Example #1
0
        /**
         * Simplifies a list and removes any dublicates
         */
        public static Tuple <QuineColumn, List <Implicant> > ColumnSimplify(QuineColumn column)
        {
            List <List <Implicant> > newColumn       = new List <List <Implicant> >();
            List <Implicant>         unusedImplcants = buildUnusedList(column.implicants);

            for (int i = 0; i <= column.implicantLength; i++)
            {
                newColumn.Add(new List <Implicant>());
            }
            for (int i = 0; i < column.implicants.Count - 1; i++)            // Loops through the super list which sorts sublists based on the number of ones
            {
                for (int j = 0; j < column.implicants[i].Count; j++)         // one column looping through
                {
                    for (int m = 0; m < column.implicants[i + 1].Count; m++) // Lopp through next column looking for a match
                    {
                        if (Implicant.CanCombine(column.implicants[i][j], column.implicants[i + 1][m]))
                        {
                            //Console.WriteLine($"Trying to combine: {column[i][j].ToString()} {column[i + 1][m].ToString()}");
                            //Console.WriteLine($"These can combine: {Implicant.CanCombine(column[i][j], column[i+1][m])}");
                            Implicant newImp = Implicant.Combine(column.implicants[i][j], column.implicants[i + 1][m]);
                            //Console.WriteLine($"Num Ones: {newImp.numOnes}");
                            //Console.WriteLine($"{newImp.ToString()}");
                            newColumn[newImp.numOnes].Add(newImp);
                            if (unusedImplcants.Contains(column.implicants[i][j])) // Checks if either implucant is in the unused column, if unused removes and updates unused list
                            {
                                unusedImplcants.Remove(column.implicants[i][j]);
                            }
                            if (unusedImplcants.Contains(column.implicants[i + 1][m]))
                            {
                                unusedImplcants.Remove(column.implicants[i + 1][m]);
                            }
                        }
                    }
                }
            }

            newColumn = QuineColumn.removeDublicates(newColumn);

            QuineColumn nextColumn = new QuineColumn(column.implicantLength, newColumn);

            return(Tuple.Create(nextColumn, unusedImplcants));
        }
Example #2
0
        public static void implicantTest()
        {
            Implicant imp1 = new Implicant(0, 5);
            Implicant imp2 = new Implicant(1, 5);
            Implicant imp3 = new Implicant(8, 5);
            Implicant imp4 = new Implicant(9, 5);

            System.Console.WriteLine($"{Implicant.CanCombine(imp1, imp2)}"); // true
            System.Console.WriteLine($"{Implicant.CanCombine(imp1, imp3)}"); // false
            Implicant imp1_2 = Implicant.Combine(imp1, imp2);

            Console.WriteLine($"{imp1_2.numOnes}");
            Implicant imp3_4 = Implicant.Combine(imp3, imp4);

            Console.WriteLine(imp1_2.ToString());
            Console.WriteLine(imp3_4.ToString());
            Console.WriteLine($"{Implicant.CanCombine(imp1_2, imp3_4)}");
            Implicant imp5 = Implicant.Combine(imp1_2, imp3_4);

            Console.WriteLine(imp5.ToString());
        }