Advertisement
anas_harby

Untitled

May 2nd, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.68 KB | None | 0 0
  1. import java.lang.StringBuilder;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.Collections;
  5. import java.util.Scanner;
  6. public class TESTer {
  7.     /** The minterms (Decimal integers). */
  8.     static ArrayList<Integer> minterms = new ArrayList<Integer>();
  9.    
  10.     /** The dontcares (Decimal integers). */
  11.     static ArrayList<Integer> dontcares = new ArrayList<Integer>();
  12.    
  13.     /** The comparisons (3D arrayList, 1st Dimension holds comparison, 2nd holds groups
  14.      * ,3rd holds binary representation alongside the minterms it fulfills, e.x: 0--1 1 3 5 7).
  15.      * . */
  16.     static ArrayList<ArrayList<ArrayList<String>>> comparisons = new ArrayList<ArrayList<ArrayList<String>>>();
  17.    
  18.     /** The essential prime implicants. (same representation as the above) */
  19.     static ArrayList<String> essentialPrimeImplicantsContainingOne = new ArrayList<String>();
  20.    
  21.     /** The minterms apperancescount */
  22.     static int[][] mintermsApperancescount;
  23.    
  24.     /** The prime implicants (taken before coverage table). */
  25.     static ArrayList<String> primeImplicants = new ArrayList<String>();
  26.  
  27.     /** The combination (combination of terms generated in coverage table). */
  28.     static String[] combination = new String[26];
  29.  
  30.     /** number of variables/bits needed to represent each minterm. */
  31.     static int numberOfBits;
  32.    
  33.     /** checks if generateCombinations() method has found a suitable combination. */
  34.     static boolean foundCombination = false;
  35.  
  36.     /** The scanner. */
  37.     static Scanner in = new Scanner(System.in);
  38.  
  39.     /**
  40.      * Pre-fills array lists with empty data to enable accessing it with random indexes.
  41.      */
  42.     private static void fillArrayList() {
  43.         for (int i = 0; i < 26; i++) {
  44.             comparisons.add(new ArrayList()); // comparisons
  45.             for (int j = 0; j <= numberOfBits; j++)
  46.                 comparisons.get(i).add(new ArrayList()); // groups
  47.         }
  48.     }
  49.  
  50.     /**
  51.      * Differ binary.
  52.      *
  53.      * @param firstMinterm the first minterm in a binary string representation.
  54.      * @param secondMinterm the second minterm in a binary string representations.
  55.      * @return a string in a binary representation with difference represented as dashes. returns the number of ones in the end of the string.
  56.      */
  57.     private static String differBinary(String firstMinterm, String secondMinterm) {
  58.         String result = "";
  59.         int ones = 0;
  60.         for (int i = 0; i < firstMinterm.length(); i++) {
  61.             if (firstMinterm.charAt(i) != secondMinterm.charAt(i))
  62.                 result += "-";
  63.             else
  64.                 result += firstMinterm.charAt(i);
  65.             if (firstMinterm.charAt(i) == '1')
  66.                 ones++;
  67.         }
  68.         return result + " " + String.valueOf(ones);
  69.     }
  70.  
  71.     /**
  72.      * Converter from decimal to binary (needed to count ones, adds result immediately in the first comparison --> comparisons[0]).
  73.      */
  74.     private static void decimalToBinary() {
  75.  
  76.         for (int i = 0; i < minterms.size(); i++) {
  77.             int div = minterms.get(i), ones = 0;
  78.             String res = "";
  79.             while (div != 0) {
  80.                 if (div % 2 == 1) {
  81.                     ones++;
  82.                     res = "1" + res;
  83.                 } else
  84.                     res = "0" + res;
  85.                 div /= 2;
  86.             }
  87.             for (int j = 0, len = res.length(); j < numberOfBits - len; j++)
  88.                 res = "0" + res;
  89.             comparisons.get(0).get(ones).add(res + " " + Integer.parseInt(res, 2));
  90.         }
  91.         for (int i = 0; i < dontcares.size(); i++) {
  92.             int div = dontcares.get(i), ones = 0;
  93.             String res = "";
  94.             while (div != 0) {
  95.                 if (div % 2 == 1) {
  96.                     ones++;
  97.                     res = "1" + res;
  98.                 } else
  99.                     res = "0" + res;
  100.                 div /= 2;
  101.             }
  102.             for (int j = 0, len = res.length(); j < numberOfBits - len; j++)
  103.                 res = "0" + res;
  104.             comparisons.get(0).get(ones).add(res + " " + Integer.parseInt(res, 2));
  105.         }
  106.         for (int i = 0; i < comparisons.get(0).size(); i++)
  107.             Collections.sort(comparisons.get(0).get(i));
  108.     }
  109.  
  110.     /**
  111.      * Do comparisons.
  112.      */
  113.     private static void doComparisons() {
  114.         int k;
  115.         for (k = 0; k < comparisons.size() - 1; k++) { // Loop through comparisons
  116.             boolean[][] takenToNextComparison = new boolean[1000][1000];
  117.             for (int l = 0; l < comparisons.get(k).size(); l++) { // Loop through groups
  118.                 if (comparisons.get(k).get(l).isEmpty()) //continue if group is empty.
  119.                     continue;
  120.                 int m = l + 1;
  121.  
  122.                 while (m < comparisons.get(k).size() && comparisons.get(k).get(m).isEmpty()) //find a next group that isn't empty.
  123.                     m++;
  124.                 if (m == comparisons.get(k).size()) { //if this is the last group, add terms that were not taken before into the prime implicants.
  125.                     for (int i = 0; i < comparisons.get(k).get(l).size(); i++) {
  126.                         if (!takenToNextComparison[l][i]) {
  127.                             ArrayList<String> iData = new ArrayList<String>();
  128.                             for (String retval : comparisons.get(k).get(l).get(i).split(" "))
  129.                                 iData.add(retval);
  130.                             String info = iData.get(0);
  131.                             for (int x = 1; x < iData.size(); x++)
  132.                                 info += " " + iData.get(x);
  133.                             primeImplicants.add(info);
  134.                         }
  135.                     }
  136.                     break;
  137.                 }
  138.                 for (int i = 0; i < comparisons.get(k).get(l).size(); i++) {
  139.                     boolean fPrime = true;
  140.                     ArrayList<String> iData = new ArrayList<String>();
  141.                     for (String retval : comparisons.get(k).get(l).get(i).split(" ")) //get data inside comparisons arraylist for the 1st term.
  142.                         iData.add(retval);
  143.                     for (int j = 0; j < comparisons.get(k).get(m).size(); j++) {
  144.                         ArrayList<String> jData = new ArrayList<String>();
  145.                         for (String retval : comparisons.get(k).get(m).get(j).split(" "))
  146.                             jData.add(retval);
  147.                         float exponent = 0;
  148.                         int difference = 0;
  149.                         boolean fAccept = true;
  150.                         for (int x = 1; x < iData.size(); x++) {
  151.                             int iDifference = Integer.parseInt(iData.get(x));
  152.                             int jDifference = Integer.parseInt(jData.get(x));
  153.                             int tempDifference = jDifference - iDifference;
  154.                             float tempExponent = (float) (Math.log(tempDifference) / Math.log(2)); //difference between the two is 2^n.
  155.                             if (x == 1) {
  156.                                 difference = tempDifference;
  157.                                 exponent = tempExponent;
  158.                                 if (difference < 0 || exponent - (int) exponent != 0) {
  159.                                     fAccept = false;
  160.                                     break;
  161.                                 }
  162.                             } else {
  163.                                 if (tempDifference != difference || tempExponent != exponent) {
  164.                                     fAccept = false;
  165.                                     break;
  166.                                 }
  167.                             }
  168.                         }
  169.                         if (fAccept) {
  170.                             fPrime = false;
  171.                             String iBinary = iData.get(0);
  172.                             String jBinary = jData.get(0);
  173.                             takenToNextComparison[l][i] = true; //the implicant is taken.
  174.                             takenToNextComparison[m][j] = true;
  175.                             ArrayList<String> dashesAndOnes = new ArrayList<String>();
  176.                             for (String retval : differBinary(iBinary, jBinary).split(" "))
  177.                                 dashesAndOnes.add(retval);
  178.                             String differenceBinary = dashesAndOnes.get(0);
  179.                             int ones = Integer.parseInt(dashesAndOnes.get(1));
  180.                             boolean fDuplicate = false;
  181.                             for (int x = 0; x < comparisons.get(k + 1).size(); x++) { //checks for duplicates.
  182.                                 for (int y = 0; y < comparisons.get(k + 1).get(x).size(); y++) {
  183.                                     String duplicate = comparisons.get(k + 1).get(x).get(y).split(" ")[0];
  184.                                     if (duplicate.equals(differenceBinary)) {
  185.                                         fDuplicate = true;
  186.                                         break;
  187.                                     }
  188.                                 }
  189.                             }
  190.                             if (!fDuplicate) {
  191.                                 String info = differenceBinary; //assign data for the next comparison.
  192.                                 for (int x = 1; x < iData.size(); x++) {
  193.                                     info += " " + iData.get(x);
  194.                                 }
  195.                                 for (int x = 1; x < jData.size(); x++) {
  196.                                     info += " " + jData.get(x);
  197.                                 }
  198.                                 comparisons.get(k + 1).get(ones).add(info);
  199.                             } else
  200.                                 continue;
  201.  
  202.                         }
  203.                     }
  204.                     if (fPrime && !takenToNextComparison[l][i]) { //add to prime implicants.
  205.                         String info = iData.get(0);
  206.                         for (int x = 1; x < iData.size(); x++)
  207.                             info += " " + iData.get(x);
  208.                         primeImplicants.add(info);
  209.                     }
  210.  
  211.                 }
  212.             }
  213.         }
  214.         for (int i = 0; i < comparisons.get(k).size(); i++) // add all the implicants in the last comparison to prime implicants.
  215.             for (int j = 0; j < comparisons.get(k).get(i).size(); j++) {
  216.                 ArrayList<String> data = new ArrayList<String>();
  217.                 for (String retval : comparisons.get(k).get(i).get(j).split(" "))
  218.                     data.add(retval);
  219.                 String info = data.get(0);
  220.                 for (int x = 1; x < data.size(); x++)
  221.                     info += " " + data.get(x);
  222.                 primeImplicants.add(info);
  223.             }
  224.     }
  225.  
  226.     /**
  227.      * Returns an alphabetical representation of a binary number with dashes.
  228.      *
  229.      * @param arrayList required
  230.      * @return string expression
  231.      */
  232.     private static String findExpression(ArrayList required) {
  233.         String expression = new String();
  234.         ;
  235.         StringBuilder dashesExpression = null;
  236.         StringBuilder expressionBuilder = new StringBuilder();
  237.  
  238.         for (int i = 0; i < required.size(); i++) {
  239.             for (String retval : ((String) required.get(i)).split(" ")) {
  240.                 dashesExpression = new StringBuilder();
  241.                 dashesExpression.append(retval);
  242.                 break;
  243.             }
  244.  
  245.             for (int j = 0; j < dashesExpression.length(); j++) {
  246.                 if (dashesExpression.charAt(j) == '1') {
  247.                     char character = (char) ((int) ('A') + j);
  248.                     expressionBuilder.append(character);
  249.                 } else if (dashesExpression.charAt(j) == '0') {
  250.                     char character = (char) ((int) ('A') + j);
  251.                     String str = new String();
  252.                     str += character + "'";
  253.                     expressionBuilder.append(str);
  254.  
  255.                 }
  256.  
  257.             }
  258.             if (i != (required.size() - 1))
  259.                 expressionBuilder.append(" + ");
  260.         }
  261.  
  262.         expression = expressionBuilder.toString();
  263.         return expression;
  264.     }
  265.    
  266.     /**
  267.      * Checks whether shifting to getting reduced prime implicants entering the combinations generating process is needed or not.
  268.      *
  269.      * @return true, if successful
  270.      */
  271.     private static boolean containsOne() {
  272.         for (int i = 0; i < mintermsApperancescount.length; i++) {
  273.             if ((mintermsApperancescount[i][1]) == 1)
  274.                 return true;
  275.         }
  276.         return false;
  277.     }
  278.  
  279.     /**
  280.      * Counts the appearances of each minterm in each combined group.
  281.      * NOTE:  Combined groups arise from the method doComparisons()
  282.      */
  283.     private static void countAppearances() {
  284.         StringBuilder str2;
  285.         int foundFlag = 0;
  286.         mintermsApperancescount = new int[minterms.size()][2];
  287.         for (int i = 0; i < minterms.size(); i++) {
  288.             mintermsApperancescount[i][0] = minterms.get(i);
  289.  
  290.         }
  291.         for (int i = 0; i < primeImplicants.size(); i++) {
  292.             String str = primeImplicants.get(i).split(" ", 2)[1];
  293.             str2 = new StringBuilder();
  294.             for (int j = 0; j <= str.length(); j++) {
  295.                 foundFlag = 0;
  296.                 if ((j != str.length()) && (str.charAt(j) != ' ')) {
  297.                     str2.append(str.charAt(j));
  298.  
  299.                 } else {
  300.                     int vaL = Integer.parseInt(str2.toString());
  301.                     for (int k = 0; k < mintermsApperancescount.length; k++) {
  302.                         if (vaL == mintermsApperancescount[k][0]) {
  303.                             foundFlag = 1;
  304.                             mintermsApperancescount[k][1]++;
  305.                             str2 = new StringBuilder();
  306.                             break;
  307.  
  308.                         }
  309.                     }
  310.                     if (foundFlag == 0)
  311.                         str2 = new StringBuilder();
  312.  
  313.                 }
  314.             }
  315.         }
  316.  
  317.     }
  318.  
  319.  
  320.  
  321.     /**
  322.      * Finds minterms that appeared only once in a certain column and gets a corresponding expreesion using an array.
  323.      * Removes each minterm taken from consideration as they're not needed in the next step in the combination generating.
  324.      */
  325.     private static void getReducedEssentialImplicants() {
  326.         int uniqueMinterm, foundFlag = 0;
  327.         StringBuilder str2;
  328.  
  329.         for (int i = 0; i < mintermsApperancescount.length; i++) {
  330.             if (mintermsApperancescount[i][1] == 1) {
  331.                 uniqueMinterm = mintermsApperancescount[i][0];
  332.                 for (int j = 0; j < primeImplicants.size(); j++) {
  333.                     String str = primeImplicants.get(j).split(" ", 2)[1];
  334.                     str2 = new StringBuilder();
  335.                     for (int k = 0; k <= str.length(); k++) {
  336.                         if ((k != str.length()) && (str.charAt(k) != ' ')) {
  337.                             str2.append(str.charAt(k));
  338.  
  339.                         } else if (((k != str.length()) && (str.charAt(k) == ' ')) || (k == (str.length()))) {
  340.                             int value = Integer.parseInt(str2.toString());
  341.                             if (value == uniqueMinterm) {
  342.                                 essentialPrimeImplicantsContainingOne.add(primeImplicants.get(j));
  343.                                 /*
  344.                                  * the implicant that matches certain conditions should be
  345.                                  * promoted to be essential and removed from the prime implicants arraylist.
  346.                                  */
  347.                                 primeImplicants.remove(j);
  348.                                 str2 = new StringBuilder();
  349.                                 for (int u = 0; u <= str.length(); u++) {
  350.                                     foundFlag = 0;
  351.                                     if ((u != str.length()) && (str.charAt(u) != ' ')) {
  352.                                         str2.append(str.charAt(u));
  353.  
  354.                                     } else {
  355.                                         int vaL = Integer.parseInt(str2.toString());
  356.                                         for (int m = 0; m < mintermsApperancescount.length; m++) {
  357.                                             if (vaL == mintermsApperancescount[m][0]) {
  358.                                                 foundFlag = 1;
  359.                                                 mintermsApperancescount[m][1] = 0;
  360.                                                 /*
  361.                                                  * Cancels out all the minterms in the row and the columns
  362.                                                  * that matches the taken row "expression".
  363.                                                  */
  364.                                                 str2 = new StringBuilder();
  365.                                                 ;
  366.                                                 break;
  367.  
  368.                                             }
  369.                                         }
  370.                                         if (foundFlag == 0)
  371.                                             str2 = new StringBuilder();
  372.  
  373.                                     }
  374.  
  375.                                 }
  376.                             } else {
  377.                                 str2 = new StringBuilder();
  378.                             }
  379.                         }
  380.                     }
  381.                 }
  382.             }
  383.         }
  384.  
  385.     }
  386.    
  387.     /**
  388.      * Checks whether the essential prime implicants already covered all the minterms before trying to generate combinations.
  389.      *
  390.      * @return true, if successful
  391.      */
  392.     private static boolean needsCombinations() {
  393.         int countZeros = 0;
  394.  
  395.         for (int i = 0; i < mintermsApperancescount.length; i++) {
  396.             if (mintermsApperancescount[i][1] == 0) {
  397.                 for (int j = 0; j < minterms.size(); j++) {
  398.                     if (mintermsApperancescount[i][0] == minterms.get(j)) {
  399.                         minterms.remove(j);
  400.                         break;
  401.                     }
  402.  
  403.                 }
  404.                 countZeros++;
  405.             }
  406.         }
  407.         if (countZeros == mintermsApperancescount.length) {  
  408.             /*
  409.             if all the terms have the zero value in appearance cell therefore
  410.             it's not needed to proceed to another level of computations using the combinations generator
  411.             as it's already done.
  412.            */
  413.             return true;
  414.         } else
  415.             return false;
  416.     }
  417.  
  418.     /**
  419.      * Check combination.
  420.      *
  421.      * @param len length of the combination.
  422.      * @return true, if combination covered all the remaining minterms.
  423.      */
  424.     private static boolean checkCombination(int len) {
  425.         ArrayList<Integer> checkedMinterms = new ArrayList<Integer>();
  426.  
  427.         for (int i = 0; i < len; i++) {
  428.             ArrayList<String> data = new ArrayList<String>();
  429.             for (String retval : combination[i].split(" "))
  430.                 data.add(retval);
  431.             for (int j = 1; j < data.size(); j++)
  432.                 checkedMinterms.add(Integer.parseInt(data.get(j)));
  433.         }
  434.         if (checkedMinterms.containsAll(minterms))
  435.             return true;
  436.         else
  437.             return false;
  438.     }
  439.    
  440.     /**
  441.      * Generate combinations.
  442.      *
  443.      * @param element the element
  444.      * @param m the m
  445.      * @param len the len
  446.      */
  447.     private static void generateCombinations(int element, int m, int len) { // (1,0,size)
  448.         if (m == len) {
  449.             if (checkCombination(len)) {
  450.                 foundCombination = true;
  451.                 fillEssentialPrime(len);
  452.                 Arrays.fill(combination, "");
  453.             }
  454.             return;
  455.         }
  456.         if (element == primeImplicants.size() + 1)
  457.             return;
  458.         combination[m] = primeImplicants.get(element - 1);
  459.         generateCombinations(element + 1, m + 1, len);
  460.         generateCombinations(element + 1, m, len);
  461.     }
  462.  
  463.     /**
  464.      * Takes the combination and adds it to a local list (since a global one won't be needed taken into consideration the probability of
  465.      * getting more than one minimal expression). prints the implicants immediately.
  466.      * Prints the essential prime implicants immediately.
  467.      * Generates an alphabetical expression and prints it.
  468.      * NOTE: (if needed to separate the printing process, a new 2D array list can be added globally and with a proper string representation
  469.      *        minimal expressions can be added, ex: ( 1 >> [BC' + AB' + ABC', 1 2, 4 5, 3 5 6, ...etc] ) and dealt with later with split()  
  470.      * @param combinationLength the number of essential prime implicants inside combination.
  471.      */
  472.     private static void fillEssentialPrime(int combinationLength) {
  473.         ArrayList<String> combinationEssential = new ArrayList<String>();
  474.         for (int i = 0; i < combinationLength; i++) {
  475.             String binaryRepresentation = combination[i].split(" ",2)[0];
  476.             String numericRepresentation = combination[i].split(" ",2)[1];
  477.             System.out.println(binaryRepresentation + "\t" + "(" + numericRepresentation + ")");
  478.             combinationEssential.add(combination[i]);
  479.         }
  480.         for(int i=0; i<essentialPrimeImplicantsContainingOne.size(); i++) {
  481.             String binaryRepresentation = essentialPrimeImplicantsContainingOne.get(i).split(" ",2)[0];
  482.             String numericRepresentation = essentialPrimeImplicantsContainingOne.get(i).split(" ",2)[0];
  483.             System.out.println(binaryRepresentation + "\t" + "(" + numericRepresentation + ")");
  484.         }
  485.         System.out.println("\n" + "Expression:");
  486.         String expression = findExpression(essentialPrimeImplicantsContainingOne);
  487.         if(!expression.equals(""))
  488.             expression+= " + ";
  489.         expression += findExpression(combinationEssential);
  490.         System.out.println(expression);
  491.         System.out.println("---------------");
  492.     }
  493.    
  494.     public static void printCoverageTable() {
  495.         for(int i=0; i<numberOfBits; i++)
  496.             System.out.print(" ");
  497.         System.out.print("\t");
  498.         for(int i=0; i<minterms.size(); i++)
  499.             System.out.print(minterms.get(i) + "\t");
  500.         System.out.print("\n" + "\n");
  501.         for(int i=0; i<primeImplicants.size(); i++) {
  502.             ArrayList<String> data = new ArrayList<String>();
  503.             for (String retval : primeImplicants.get(i).split(" "))
  504.                 data.add(retval);
  505.             System.out.print(data.get(0) + "\t");
  506.             for(int j=0; j<minterms.size(); j++) {
  507.                 if(data.contains(Integer.toString(minterms.get(j))))
  508.                     System.out.print("X" + "\t");
  509.                 else
  510.                     System.out.print(" " + "\t");
  511.             }
  512.             System.out.println();
  513.         }
  514.     }
  515.  
  516.     /**
  517.      * The main method.
  518.      *
  519.      * @param args the arguments
  520.      */
  521.     public static void main(String[] args) {
  522.         System.out.println("Enter number of variables:");
  523.         numberOfBits = in.nextInt();
  524.        
  525.         System.out.println("Enter minterms in decimal <-1 to finish>:");
  526.         int c=0;
  527.         while (true) {
  528.             int input;
  529.             input = c;
  530.             if (c == 210*3)
  531.                 break;
  532.             minterms.add(input);
  533.             c+=3;
  534.         }
  535.         System.out.println("Enter don'tcares in decimal <-1 to finish>:");
  536.         while (true) {
  537.             int input;
  538.             input = c;
  539.             if (input == 210*3)
  540.                 break;
  541.             dontcares.add(input);
  542.             c++;
  543.         }
  544.  
  545.         fillArrayList();
  546.         decimalToBinary();
  547.         doComparisons();
  548.        
  549.         System.out.println("________________________________________________________________" + "\n");
  550.         System.out.println("Grouping:");
  551.         System.out.println();
  552.         for (int k = 0; k < comparisons.size(); k++) {
  553.             boolean comparisonHasElements = false;
  554.  
  555.             for (int i = 0; i < comparisons.get(k).size(); i++) {
  556.                 if (comparisons.get(k).get(i).isEmpty())
  557.                     continue;
  558.                 for (int j = 0; j < comparisons.get(k).get(i).size(); j++) {
  559.                     String binaryRepresentation = comparisons.get(k).get(i).get(j).split(" ", 2)[0];
  560.                     String numericRepresentation = comparisons.get(k).get(i).get(j).split(" ", 2)[1];
  561.                     System.out.println(binaryRepresentation + "\t" + "(" + numericRepresentation + ")");
  562.                 }
  563.                 comparisonHasElements = true;
  564.                 System.out.println("-----------------");
  565.             }
  566.             if (comparisonHasElements) {
  567.                 System.out.println("_________________" + "\n");
  568.             }
  569.         }
  570.         if (minterms.isEmpty()==true)
  571.         {
  572.             System.out.println("Expression = 0");
  573.             System.exit(0);
  574.         }
  575.        
  576.         System.out.println("Prime Implicants:" + "\n");
  577.         for (int i = 0; i < primeImplicants.size(); i++) {
  578.             String binaryRepresentation = primeImplicants.get(i).split(" ", 2)[0];
  579.             String numericRepresentation =  primeImplicants.get(i).split(" ", 2)[1];
  580.             System.out.println(binaryRepresentation + "\t" + "(" + numericRepresentation + ")");
  581.         }
  582.         System.out.println("\n" + "Expression:");
  583.         System.out.println(findExpression(primeImplicants));
  584.         System.out.println("_________________" + "\n");
  585.         System.out.println("Coverage Table:");
  586.         System.out.println();
  587.         printCoverageTable();
  588.         System.out.println("_________________" + "\n" + "\n" + "Essential Prime Implicants:" + "\n");
  589.         countAppearances();
  590.         if (containsOne()) {
  591.             getReducedEssentialImplicants();
  592.             if (!needsCombinations()) {
  593.                 for (int i = 1; i <= primeImplicants.size() && !foundCombination; i++)
  594.                     generateCombinations(1, 0, i);
  595.             }
  596.             else {
  597.                 for(int i=0; i<essentialPrimeImplicantsContainingOne.size(); i++) {
  598.                     String binaryRepresentation = essentialPrimeImplicantsContainingOne.get(i).split(" ",2)[0];
  599.                     String numericRepresentation = essentialPrimeImplicantsContainingOne.get(i).split(" ",2)[0];
  600.                     System.out.println(binaryRepresentation + "\t" + "(" + numericRepresentation + ")");
  601.                 }
  602.                 System.out.println("\n" + "Expression:");
  603.                 System.out.println(findExpression(essentialPrimeImplicantsContainingOne));
  604.                
  605.             }
  606.         }
  607.         else {
  608.             for (int i = 1; i <= primeImplicants.size() && !foundCombination; i++)
  609.                 generateCombinations(1, 0, i);
  610.         }
  611.  
  612.     }
  613. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement