Quine-McCluskey Algoritması Java - MyBlog - Bilgi Paylaşım Platformu


Quine-McCluskey Algoritması Java


Quine–McCluskey kullanımı (veya asal çıkarımlar yöntemi), Willard V. Quine tarafından sahiplenilmesi ve Edward J. McCluskey tarafından genişletilen Boolean okullarının minimizasyonu için kullanılabilir.
Quine-McCluskey Algoritması Java

Quine-McCluskey-Algorithm-Java

Introduction:

The Quine–McCluskey algorithm (or the method of prime implicants) is a method used for minimization of Boolean functions that was developed by Willard V. Quine and extended by Edward J. McCluskey. It is functionally identical to Karnaugh mapping, but the tabular form makes it more efficient for use in computer algorithms, and it also gives a deterministic way to check that the minimal form of a Boolean function has been reached. It is sometimes referred to as the tabulation method. The method involves two steps:

  1. Finding all prime implicants of the function.
  2. Use those prime implicants in a prime implicant chart to find the essential prime implicants of the function, as well as other prime implicants that are necessary to cover the function.

Problem Definition:

The method groups the minterms entered by the user first according to the number of ones in their binary equivalent. Then the minterms are grouped in such a way that the there is only change in a single position of the two minterms compared. The comparing is carried forward to newer tables until there are no more groups to be formed. Then all the minterms that are never paired are chosen as prime implicants and using the least number of prime implicants that cover all minterms, we generate the minimized equation for the Boolean function.

Modules:

  • void minTermsDectoBin(); - Converts decimal minterms to binary equivalents.
  • int totalSizeCalc(); - Calculates the max no. of minterms for the no of variables.
  • int calcNoOfOnes(int[]); - Counts the no of ones in the binary of the minterm
  • void display(); - Various Display Functions to display the tables
  • int compare(); - Various compare functions to compare tables and minterms
  • void firstStage(); - First Stage grouping
  • void printParityTable(); - To print the parity table
  • void parityInit(); - Initialize the parity table with -1
  • int paritycheck(); - To check the prime implicants
  • int checkForSingle(); - Prime implicants that are must to be included in eqn
  • int parityToEqt(); - To generate equation from prime implicants
  • void displayFinal(); - Display the final equation

Conclusion:

The Quine-McCluskey Method was hence implemented using arrays. Array was used because the size of the data elements to be stored where fixed and was in a tabular form of a 2d array. Also, there was no need to access elements from between and hence a linear traversal was only required along with static storage, which provides a fast access. Hence, arrays were preferred for the implementation of tabular form Quine-McCluskey Method. And thereby using arrays we implemented the project which performs the operation of minimizing the Boolean function entered by the user. The method hence provided with the minimized equations of the function.

 

Türkçe :

 

Quine-McCluskey-Algoritma-Java

GiriÅŸ:

Quine–McCluskey kullanımı (veya asal çıkarımlar yöntemi), Willard V. Quine tarafından sahiplenilmesi ve Edward J. McCluskey tarafından genişletilen Boolean okullarının minimizasyonu için kullanılan bir kullanılabilir. İşlevsel olarak işlevsellik eşlemesiyle, ancak uygulanabilecek bir sistem tasarımında kullanım için daha verimli hale getirmek ve ayrıntılı bir Boole sağlamanın minimum kontrol edilmesiyle elde edilirliğini belirlemek için bir yol sağlar. Bazen tablolama olarak adlandırılır. iki yöntem adım içerir:

  1. Fonksiyonun tüm asal imalarını bulma.
  2. Bu asal implikantları, işlevin temel özellikleri olarak kapsamlı ve genel olarak kapsamak için gerekli olan herkes için geçerli olan bir tablonda kullanım için bir standart değildir.

Problem tanımı:

Yöntem, kullanıcı tarafından girilen mintermleri, ikili eşdeğerlerindeki sayı sayısına göre gruplandırır. Daha sonra mintermler, karşılaştırılan iki mintermin yalnızca tek bir konumunda değişiklik olacak şekilde gruplandırılır. Karşılaştırma, oluşturulacak başka grup kalmayıncaya kadar daha yeni tablolara taşınır. Daha sonra hiçbir zaman eşleşmeyen tüm mintermler asal çıkarımlar olarak seçilir ve tüm mintermleri kapsayan en az sayıda asal implikant kullanılarak Boole fonksiyonu için minimize edilmiş denklemi üretiriz.

Modüller:

  • geçersiz minTermsDectoBin(); - Ondalık mintermleri ikili eÅŸdeÄŸerlere dönüştürür.
  • int toplamSizeCalc(); - Maksimum sayıyı hesaplar. deÄŸiÅŸken sayısı için mintermler.
  • int calcNoOfOnes(int[]); - Minterm ikili dosyasındakilerin sayısını sayar
  • geçersiz ekran(); - Tabloları görüntülemek için çeÅŸitli Görüntüleme Ä°ÅŸlevleri
  • int karşılaÅŸtır(); - Tabloları ve mintermleri karşılaÅŸtırmak için çeÅŸitli karşılaÅŸtırma iÅŸlevleri
  • void firstStage(); - Birinci AÅŸama gruplaması
  • geçersiz printParityTable(); - Parite tablosunu yazdırmak için
  • geçersiz eÅŸlikInit(); - Parite tablosunu -1 ile baÅŸlatın
  • int paritycheck(); - Asal imaları kontrol etmek için
  • int checkForSingle(); - Denklemde yer alması gereken asal imalar
  • int parityToEqt(); - Asal imalardan denklem oluÅŸturmak için
  • geçersiz displayFinal(); - Son denklemi göster

Çözüm:

Quine-McCluskey Yöntemi bu artan diziler uygulandı. Dizi, saklanacak verinin öğelerinin görünümünde olduğu ve bir 2 dizinin bulunduğu tablo içind uygulanacaktır. Ayrıca, araçlara erişim için gerekli ve bu şekilde, erişimle geçiş ile birlikte bir geçiş geçiş gerekliydi. Bu artan, şeklindeki Quine-McCluskey yönteminin için diziler tercih edilirken. Bu sayede aracılığıyla kullanıcı tarafından girilen Boolean'ı en aza indirgeyerek gerçekleştiren projeyi diziler kullanarak hayata geçirebiliriz. Bu gelişmiş sistem fonksiyonun en aza indirilmiş olan denklemleri ile teslim edilir.

 

  1. import java.util.Scanner;
  2. import java.util.Vector;
  3. import ts.display;
  4. class declarations {
  5.     // Variable Declarations
  6.     public static int i = 0, j = 0, l = 0, k = 0, c = 0, noOfVariables = 0, maxBit = 0, noOfMinTerms = 0;
  7.     public static int[] minTermsDec = new int[16];
  8.     public static int[][] minTermsBin = new int[16][16];
  9.     public static int[] noOfOnes = new int[16];
  10.     public static int[][] g0 = new int[14][5];
  11.     public static int[][] g1 = new int[16][5];
  12.     public static int[][] g2 = new int[16][5];
  13.     public static int[][] g3 = new int[16][5];
  14.     public static int[][] g4 = new int[16][5];
  15.     public static int[][] h0 = new int[16][7];
  16.     public static int[][] h1 = new int[16][7];
  17.     public static int[][] h2 = new int[16][7];
  18.     public static int[][] h3 = new int[16][7];
  19.     public static int[][] i0 = new int[16][9];
  20.     public static int[][] i1 = new int[16][9];
  21.     public static int[][] i2 = new int[16][9];
  22.     public static int[][] k0 = new int[16][13];
  23.     public static int[][] k1 = new int[16][13];
  24.     public static int[][] parityTable = new int[20][24];
  25.     public static int gzero = 0, gone = 0, gtwo = 0, gthree = 0, gfour = 0;
  26.     public static int hzero = 0, hone = 0, htwo = 0, hthree = 0;
  27.     public static int izero = 0, ione = 0, itwo = 0;
  28.     public static int kzero = 0, kone = 0;
  29.     public static int[][] Final = new int[100][5];
  30.     public static int finalc = 0;
  31.     public static int parityCnt = 0;
  32.     static Scanner s = new Scanner(System.in);
  33.     //Constructor to initialize parity 
  34.     declarations() {
  35.     for (i = 0; i < 20; i++)
  36.             for (j = 0; j < 24; j++)
  37.                 parityTable[i][j] = -1;
  38.     }
  39.     // Function Definitions
  40.     public static int parityToEqt() // Function to generate the parity bits
  41.     {
  42.         for (j = 0; j < 16; j++) {
  43.             if (checkForSingle(j) != 100) {
  44.                 Final[finalc][0] = parityTable[checkForSingle(j)][20];
  45.                 Final[finalc][1] = parityTable[checkForSingle(j)][21];
  46.                 Final[finalc][2] = parityTable[checkForSingle(j)][22];
  47.                 Final[finalc][3] = parityTable[checkForSingle(j)][23];
  48.                 finalc++;
  49.             }
  50.         }
  51.         return 0;
  52.     }
  53. // Function to compare the parity table and final parities for equation
  54.     public static int compareSamefinal(int a[][], int size) 
  55.     {
  56.         for (i = 0; i < size; i++) {
  57.             for (j = i + 1; j < size;) {
  58.                 if ((a[j][0] == a[i][0]) && (a[j][1] == a[i][1]) && (a[j][2] == a[i][2]) && (a[j][3] == a[i][3])) {
  59.                     for (k = j; k < size; k++) {
  60.                         a[k][0] = a[k + 1][0];
  61.                         a[k][1] = a[k + 1][1];
  62.                         a[k][2] = a[k + 1][2];
  63.                         a[k][3] = a[k + 1][3];
  64.                     }
  65.                     size--;
  66.                 } else {
  67.                     j++;
  68.                 }
  69.             }
  70.         }
  71.         return size;
  72.     }
  73. // Function to check for parity that are necessary for equation as they are lone contributers for a minterm
  74.     public static int checkForSingle(int column) 
  75.     {
  76.         int patc = 0, temp121 = 0;
  77.         for (i = 0; i < parityCnt; i++) {
  78.             if (parityTable[i][column] == 999) {
  79.                 temp121 = i;
  80.                 patc++;
  81.             }
  82.         }
  83.         if (patc == 1)
  84.             return temp121;
  85.         else
  86.             return 100;
  87.     }
  88.     public static int paritycheck3(int a[][], int b[][], int h[][], int first, int second,
  89.             int third) 
  90.     {
  91.         int t = 0;
  92.         while (t != first) {
  93.             int c = 0;
  94.             for (i = 0; i < second; i++) {
  95.                 int flag = 0;
  96.                 for (j = 0; j < 4; j++) {
  97.                     if (a[t][j] != b[i][j]) {
  98.                         flag++;
  99.                     }
  100.                 }
  101.                 if (flag == 1) {
  102.                     c++;
  103.                 }
  104.             }
  105.             for (i = 0; i < third; i++) {
  106.                 int flag = 0;
  107.                 for (j = 0; j < 4; j++) {
  108.                     if (a[t][j] != h[i][j]) {
  109.                         flag++;
  110.                     }
  111.                 }
  112.                 if (flag == 1) {
  113.                     c++;
  114.                 }
  115.             }
  116.             if (c == 0) {
  117.                 parityTable[parityCnt][16] = a[t][4];
  118.                 parityTable[parityCnt][17] = a[t][5];
  119.                 parityTable[parityCnt][18] = a[t][6];
  120.                 parityTable[parityCnt][19] = a[t][7];
  121.                 parityTable[parityCnt][23] = a[t][3];
  122.                 parityTable[parityCnt][22] = a[t][2];
  123.                 parityTable[parityCnt][21] = a[t][1];
  124.                 parityTable[parityCnt][20] = a[t][0];
  125.                 parityTable[parityCnt][a[t][7]] = 999;
  126.                 parityTable[parityCnt][a[t][6]] = 999;
  127.                 parityTable[parityCnt][a[t][5]] = 999;
  128.                 parityTable[parityCnt][a[t][4]] = 999;
  129.                 parityCnt++;
  130.             }
  131.             t++;
  132.         }
  133.         return 0;
  134.     }
  135.     public static int paritycheck2(int a[][], int b[][], int h[][], int first, int second,
  136.             int third) // Function to check parity
  137.     {
  138.         int t = 0;
  139.         while (t != first) {
  140.             int c = 0;
  141.             for (i = 0; i < second; i++) {
  142.                 int flag = 0;
  143.                 for (j = 0; j < 4; j++) {
  144.                     if (a[t][j] != b[i][j]) {
  145.                         flag++;
  146.                     }
  147.                 }
  148.                 if (flag == 1) {
  149.                     c++;
  150.                 }
  151.             }
  152.             for (i = 0; i < third; i++) {
  153.                 int flag = 0;
  154.                 for (j = 0; j < 4; j++) {
  155.                     if (a[t][j] != h[i][j]) {
  156.                         flag++;
  157.                     }
  158.                 }
  159.                 if (flag == 1) {
  160.                     c++;
  161.                 }
  162.             }
  163.             if (c == 0) {
  164.                 parityTable[parityCnt][16] = a[t][4];
  165.                 parityTable[parityCnt][17] = a[t][5];
  166.                 parityTable[parityCnt][23] = a[t][3];
  167.                 parityTable[parityCnt][22] = a[t][2];
  168.                 parityTable[parityCnt][21] = a[t][1];
  169.                 parityTable[parityCnt][20] = a[t][0];
  170.                 parityTable[parityCnt][a[t][5]] = 999;
  171.                 parityTable[parityCnt][a[t][4]] = 999;
  172.                 parityCnt++;
  173.             }
  174.             t++;
  175.         }
  176.         return 0;
  177.     }
  178.     public static int paritycheck1(int a[][], int b[][], int h[][], int first, int second,
  179.             int third) // Function to check parity
  180.     {
  181.         int t = 0;
  182.         while (t != first) {
  183.             int c = 0;
  184.             for (i = 0; i < second; i++) {
  185.                 int flag = 0;
  186.                 for (j = 0; j < 4; j++) {
  187.                     if (a[t][j] != b[i][j]) {
  188.                         flag++;
  189.                     }
  190.                 }
  191.                 if (flag == 1) {
  192.                     c++;
  193.                 }
  194.             }
  195.             for (i = 0; i < third; i++) {
  196.                 int flag = 0;
  197.                 for (j = 0; j < 4; j++) {
  198.                     if (a[t][j] != h[i][j]) {
  199.                         flag++;
  200.                     }
  201.                 }
  202.                 if (flag == 1) {
  203.                     c++;
  204.                 }
  205.             }
  206.             if (c == 0) {
  207.                 parityTable[parityCnt][16] = a[t][4];
  208.                 parityTable[parityCnt][23] = a[t][3];
  209.                 parityTable[parityCnt][22] = a[t][2];
  210.                 parityTable[parityCnt][21] = a[t][1];
  211.                 parityTable[parityCnt][20] = a[t][0];
  212.                 parityTable[parityCnt][a[t][4]] = 999;
  213.                 parityCnt++;
  214.             }
  215.             t++;
  216.         }
  217.         return 0;
  218.     }
  219.     public static int totalSizeCalc() // Function to check the maximum no of minterms possible for the no of variables
  220.     {
  221.         for (i = 0; i < noOfVariables; i++) {
  222.             maxBit = maxBit + (int) Math.pow(2, i);
  223.         }
  224.         return maxBit + 1;
  225.     }
  226.     public static void inputMinTerms() // Function to input the minterms
  227.     {
  228.         int inp = 0;
  229.         Vector vec = new Vector(16);
  230.         System.out.print("Enter the minterms to be minimized: \n");
  231.         for (i = 0; i < maxBit; i++) {
  232.             inp = s.nextInt();
  233.             if (inp >= (maxBit)) {
  234.                 for (i = 0; i < noOfMinTerms; i++)
  235.                     minTermsDec[i] = vec.get(i);
  236.                 return;
  237.             }
  238.             else if (inp == (-1)) {
  239.                 for (i = 0; i < noOfMinTerms; i++)
  240.                     minTermsDec[i] = vec.get(i);
  241.                 return;
  242.             } else {
  243.                 vec.add(inp);
  244.                 noOfMinTerms++;
  245.             }
  246.         }
  247.     }
  248.     public static int calcNoOfOnes(int num[]) // Function to calculate the no of ones in the minterms binary value
  249.     {
  250.         int flag = 0;
  251.         for (i = 0; i < maxBit; i++) {
  252.             if (num[i] == 1)
  253.                 flag++;
  254.         }
  255.         return flag;
  256.     }
  257.     public static void minTermsDectoBin() // Function to convert the minterms in decimal to their binary equivalents
  258.     {
  259.         int temp;
  260.         for (i = 0; i <= noOfMinTerms; i++) {
  261.             for (j = 0; j < noOfMinTerms; j++) {
  262.                 temp = minTermsDec[j];
  263.                 minTermsBin[j][4] = temp;
  264.                 for (l = 3; l >= 0; l--) {
  265.                     minTermsBin[j][l] = temp % 2;
  266.                     temp = temp / 2;
  267.                 }
  268.                 if (minTermsDec[j] == 1)
  269.                     noOfOnes[j] = 1;
  270.                 else
  271.                     noOfOnes[j] = calcNoOfOnes(minTermsBin[j]);
  272.             }
  273.         }
  274.     }
  275.     public static void firstStage() // Function for first stage comparisons
  276.     {
  277.         for (i = 0; i < noOfMinTerms; i++) {
  278.             if (noOfOnes[i] == 0) {
  279.                 for (j = 0; j < 5; j++) {
  280.                     g0[gzero][j] = minTermsBin[i][j];
  281.                 }
  282.                 gzero++;
  283.             }
  284.             if (noOfOnes[i] == 1) {
  285.                 for (j = 0; j < 5; j++) {
  286.                     g1[gone][j] = minTermsBin[i][j];
  287.                 }
  288.                 gone++;
  289.             }
  290.             if (noOfOnes[i] == 2) {
  291.                 for (j = 0; j < 5; j++) {
  292.                     g2[gtwo][j] = minTermsBin[i][j];
  293.                 }
  294.                 gtwo++;
  295.             }
  296.             if (noOfOnes[i] == 3) {
  297.                 for (j = 0; j < 5; j++) {
  298.                     g3[gthree][j] = minTermsBin[i][j];
  299.                 }
  300.                 gthree++;
  301.             }
  302.             if (noOfOnes[i] == 4) {
  303.                 for (j = 0; j < 5; j++) {
  304.                     g4[gfour][j] = minTermsBin[i][j];
  305.                 }
  306.                 gfour++;
  307.             }
  308.         }
  309.     }
  310.     public static void display() // Display function to display the no of ones
  311.     {
  312.         for (j = 0; j < noOfMinTerms; j++) {
  313.             System.out.print(noOfOnes[j] + "\t");
  314.         }
  315.     }
  316.     public void displayFinal() // Function to display the final table
  317.     {
  318.         for (i = 0; i < finalc; i++) {
  319.             for (j = 0; j < 4; j++) {
  320.                 System.out.print(Final[i][j] + "\t");
  321.             }
  322.             System.out.print("\n");
  323.         }
  324.     }
  325.     public static void displayArray(int a[][], int n) // Dsiplay Function
  326.     {
  327.         for (i = 0; i < n; i++) {
  328.             for (j = 0; j < 4; j++) {
  329.                 System.out.print(a[i][j] + "\t");
  330.             }
  331.             System.out.print("\n");
  332.         }
  333.     }
  334.     static int compare(int a[][], int b[][], int h[][], int first, int second) // Compare Function
  335.     {
  336.         int y = 0, t = 0;
  337.         while (t < first) {
  338.             for (i = 0; i < second; i++) {
  339.                 int flag = 0;
  340.                 for (j = 0; j < 4; j++) {
  341.                     if (a[t][j] == b[i][j]) {
  342.                         h[y][j] = b[i][j];
  343.                     } else {
  344.                         h[y][j] = 9;
  345.                         flag++;
  346.                     }
  347.                 }
  348.                 if (flag == 1) {
  349.                     h[y][4] = a[t][4];
  350.                     h[y][5] = b[i][4];
  351.                     if (h[y][6] == 0)
  352.                         h[y][6] = 1;
  353.                     y++;
  354.                 }
  355.             }
  356.             t++;
  357.         }
  358.         return y;
  359.     }
  360.     public static int compare1(int a[][], int b[][], int h[][], int first, int second) // Compare Function
  361.     {
  362.         int y = 0, t = 0;
  363.         while (t != first) {
  364.             for (i = 0; i < second; i++) {
  365.                 int flag = 0;
  366.                 for (j = 0; j < 4; j++) {
  367.                     if (a[t][j] == b[i][j]) {
  368.                         h[y][j] = b[i][j];
  369.                     } else {
  370.                         flag++;
  371.                         h[y][j] = 9;
  372.                     }
  373.                 }
  374.                 if (flag == 1) {
  375.                     h[y][4] = a[t][4];
  376.                     h[y][5] = a[t][5];
  377.                     h[y][6] = b[i][4];
  378.                     h[y][7] = b[i][5];
  379.                     y++;
  380.                 }
  381.             }
  382.             t++;
  383.         }
  384.         return y;
  385.     }
  386.     public static int compare2(int a[][], int b[][], int h[][], int first, int second) // Compare function
  387.     {
  388.         int y = 0, t = 0;
  389.         while (t != first) {
  390.             for (i = 0; i < second; i++) {
  391.                 int flag = 0;
  392.                 for (j = 0; j < 4; j++) {
  393.                     if (a[t][j] == b[i][j]) {
  394.                         h[y][j] = b[i][j];
  395.                     } else {
  396.                         flag++;
  397.                         h[y][j] = 9;
  398.                     }
  399.                 }
  400.                 if (flag == 1) {
  401.                     h[y][4] = a[t][4];
  402.                     h[y][5] = a[t][5];
  403.                     h[y][6] = a[t][6];
  404.                     h[y][7] = a[t][7];
  405.                     h[y][8] = b[i][4];
  406.                     h[y][9] = b[i][5];
  407.                     h[y][10] = b[i][6];
  408.                     h[y][11] = b[i][7];
  409.                     if (h[y][12] == 0)
  410.                         h[y][12] = 1;
  411.                     y++;
  412.                 }
  413.             }
  414.             t++;
  415.         }
  416.         return y;
  417.     }
  418.     public static int compareSame(int a[][], int size) // Compare Function
  419.     {
  420.         for (i = 0; i < size; i++) {
  421.             for (j = i + 1; j < size;) {
  422.                 if ((a[j][0] == a[i][0]) && (a[j][1] == a[i][1]) && (a[j][2] == a[i][2]) && (a[j][3] == a[i][3])) {
  423.                     for (k = j; k < size; k++) {
  424.                         a[k][0] = a[k + 1][0];
  425.                         a[k][1] = a[k + 1][1];
  426.                         a[k][2] = a[k + 1][2];
  427.                         a[k][3] = a[k + 1][3];
  428.                         a[k][4] = a[k + 1][4];
  429.                         a[k][5] = a[k + 1][5];
  430.                         a[k][6] = a[k + 1][6];
  431.                         a[k][7] = a[k + 1][7];
  432.                         a[k][8] = a[k + 1][8];
  433.                     }
  434.                     size--;
  435.                 } else {
  436.                     j++;
  437.                 }
  438.             }
  439.         }
  440.         return size;
  441.     }
  442.     public static int compareSame2(int a[][], int size) // Compare Function
  443.     {
  444.         for (i = 0; i < size; i++) {
  445.             for (j = i + 1; j < size;) {
  446.                 if ((a[j][0] == a[i][0]) && (a[j][1] == a[i][1]) && (a[j][2] == a[i][2]) && (a[j][3] == a[i][3])) {
  447.                     for (k = j; k < size; k++) {
  448.                         a[k][0] = a[k + 1][0];
  449.                         a[k][1] = a[k + 1][1];
  450.                         a[k][2] = a[k + 1][2];
  451.                         a[k][3] = a[k + 1][3];
  452.                         a[k][4] = a[k + 1][4];
  453.                         a[k][5] = a[k + 1][5];
  454.                         a[k][6] = a[k + 1][6];
  455.                         a[k][7] = a[k + 1][7];
  456.                         a[k][8] = a[k + 1][8];
  457.                         a[k][9] = a[k + 1][9];
  458.                         a[k][10] = a[k + 1][10];
  459.                         a[k][11] = a[k + 1][11];
  460.                         a[k][12] = a[k + 1][12];
  461.                     }
  462.                     size--;
  463.                 } else {
  464.                     j++;
  465.                 }
  466.             }
  467.         }
  468.         return size;
  469.     }
  470.     static void parityInit() // Function to initialize the parity table
  471.     {
  472.         for (i = 0; i < 20; i++)
  473.             for (j = 0; j < 24; j++)
  474.                 parityTable[i][j] = -1;
  475.     }
  476.     static void printParityTable() // Function to print the parity table
  477.     {
  478.         for (i = 0; i < parityCnt; i++) {
  479.             System.out.print("\n P" + i + 1 + " : ");
  480.             for (j = 16; j < 20; j++) {
  481.                 if (parityTable[i][j] == -1)
  482.                     continue;
  483.                 else {
  484.                     System.out.print(" " + parityTable[i][j] + " ");
  485.                     if (j != 19 && parityTable[i][j + 1] != -1)
  486.                         System.out.print(",");
  487.                 }
  488.             }
  489.             System.out.print("\n");
  490.         }
  491.     }
  492.     static void eqnGenerator() // Function to generate the equation from the parity
  493.     {
  494.         System.out.print("\n The Equation is : \t");
  495.         for (i = 0; i < finalc; i++) {
  496.             if (i != 0)
  497.                 System.out.print(" + ");
  498.             for (j = 0; j < 4; j++) {
  499.                 if (j == 0 && j < noOfVariables) {
  500.                     if (Final[i][j] == 0)
  501.                         System.out.print("A'");
  502.                     else if (Final[i][j] == 1)
  503.                         System.out.print("A");
  504.                 } else if (j == 1 && j < noOfVariables) {
  505.                     if (Final[i][j] == 0)
  506.                         System.out.print("B'");
  507.                     else if (Final[i][j] == 1)
  508.                         System.out.print("B");
  509.                 } else if (j == 2 && j < noOfVariables) {
  510.                     if (Final[i][j] == 0)
  511.                         System.out.print("C'");
  512.                     else if (Final[i][j] == 1)
  513.                         System.out.print("C");
  514.                 } else if (j == 3) {
  515.                     if (Final[i][j] == 0 && j < noOfVariables)
  516.                         System.out.print("D'");
  517.                     else if (Final[i][j] == 1)
  518.                         System.out.print("D");
  519.                 }
  520.             }
  521.         }
  522.     }
  523. }
  524. class l extends declarations {
  525.     public static void main(String args[]) {
  526.         try {
  527.             Scanner sc = new Scanner(System.in);
  528.             System.out.println("Please enter your name");
  529.             String s = sc.next();
  530.             System.out.print("Enter the number of variables to be Minimized: ");
  531.             noOfVariables = sc.nextInt();
  532.             maxBit = totalSizeCalc();
  533.             parityInit();
  534.             inputMinTerms();
  535.             System.out.println();
  536.             minTermsDectoBin();
  537.             System.out.print("\n\n  **STAGE 1**\n\n");
  538.             firstStage();
  539.             if (gzero != 0) {
  540.                 System.out.print("\ngroup of 0s\n");
  541.                 displayArray(g0, gzero);
  542.             }
  543.             if (gone != 0) {
  544.                 System.out.print("\ngroup of 1s\n");
  545.                 displayArray(g1, gone);
  546.             }
  547.             if (gtwo != 0) {
  548.                 System.out.print("\ngroup of 2s\n");
  549.                 displayArray(g2, gtwo);
  550.             }
  551.             if (gthree != 0) {
  552.                 System.out.print("\ngroup of 3s\n");
  553.                 displayArray(g3, gthree);
  554.             }
  555.             if (gfour != 0) {
  556.                 System.out.print("\ngroup of 4s\n");
  557.                 displayArray(g4, gfour);
  558.             }
  559.             System.out.print("\n\n  **STAGE 2**\n\n");
  560.             hzero = compare(g0, g1, h0, gzero, gone);
  561.             if (hzero != 0) {
  562.                 System.out.print("\n\nComparing Group 0 with 1:\n");
  563.                 displayArray(h0, hzero);
  564.             }
  565.             hone = compare(g1, g2, h1, gone, gtwo);
  566.             if (hone != 0) {
  567.                 System.out.print("\n\nComparing Group 1 with 2:\n");
  568.                 displayArray(h1, hone);
  569.             }
  570.             htwo = compare(g2, g3, h2, gtwo, gthree);
  571.             if (htwo != 0) {
  572.                 System.out.print("\n\nComparing Group 2 with 3:\n");
  573.                 displayArray(h2, htwo);
  574.             }
  575.             hthree = compare(g3, g4, h3, gthree, gfour);
  576.             if (hthree != 0) {
  577.                 System.out.print("\n\nComparing Group 3 with 4:\n");
  578.                 displayArray(h3, hthree);
  579.             }
  580.             System.out.print("\n\n    **STAGE 3**\n\n");
  581.             izero = compare1(h0, h1, i0, hzero, hone);
  582.             izero = compareSame(i0, izero);
  583.             if (izero != 0) {
  584.                 System.out.print("\n\nComparing Group 0 with 1:\n");
  585.                 displayArray(i0, izero);
  586.             }
  587.             ione = compare1(h1, h2, i1, hone, htwo);
  588.             ione = compareSame(i1, ione);
  589.             if (ione != 0) {
  590.                 System.out.print("\n\nComparing Group 1 with 2:\n");
  591.                 displayArray(i1, ione);
  592.             }
  593.             itwo = compare1(h2, h3, i2, htwo, hthree);
  594.             itwo = compareSame(i2, itwo);
  595.             if (itwo != 0) {
  596.                 System.out.print("\n\nComparing Group 2 with 3:\n");
  597.                 displayArray(i2, itwo);
  598.             }
  599.             System.out.print("\n\n Parity Check \n\n");
  600.             paritycheck1(g0, g1, g1, gzero, gone, gone);
  601.             paritycheck1(g1, g2, g0, gone, gtwo, gzero);
  602.             paritycheck1(g2, g3, g1, gtwo, gthree, gone);
  603.             paritycheck1(g3, g4, g2, gthree, gfour, gtwo);
  604.             paritycheck1(g4, g3, g3, gfour, gthree, gthree);
  605.             paritycheck2(h0, h1, h1, hzero, hone, hone);
  606.             paritycheck2(h1, h0, h2, hone, hzero, htwo);
  607.             paritycheck2(h2, h1, h3, htwo, hone, hthree);
  608.             paritycheck2(h3, h2, h2, hthree, htwo, htwo);
  609.             paritycheck3(i0, i1, i1, izero, ione, ione);
  610.             paritycheck3(i1, i0, i2, ione, izero, itwo);
  611.             paritycheck3(i2, i1, i1, itwo, ione, ione);
  612.             parityToEqt();
  613.             printParityTable();
  614.             finalc = compareSamefinal(Final, finalc);
  615.             System.out.print("\n");
  616.             eqnGenerator();
  617.             display d = new display();
  618.             d.disp(s);
  619.         } catch (Exception e) {
  620.             System.out.println("Exception Encountered\n" + e + "\nPlease try again");
  621.         }
  622.     }
  623. }

Tepkileriniz Nedir?

like
1
dislike
0
love
0
funny
0
angry
0
sad
1
wow
0

Bir Yorum Yaz