Exemplo n.º 1
0
        public void ParseDiagramUserControl(LogicPad2.Diagram.UserControl1 userControl, 
            out string generatedExpr, out TruthTableWindow.TruthTable generatedTruthTable)
        { 
            userControl.Parse(out generatedExpr);

            generatedTruthTable = new TruthTableWindow.TruthTable();

            int numberOfTerm;
            String[] terms_names;
            int[] fvalues;
            String outputName;
            LogicPadParser.LogicPadParser.Instance.ParseInterTreeToTruthTable(
                LogicPadParser.LogicPadParser.diagram,
                out numberOfTerm,
                out terms_names,
                out fvalues,
                out outputName
             );

            LogicPadParser.TruthTable interTruthTable = new LogicPadParser.TruthTable(numberOfTerm);
            interTruthTable.Terms_names = terms_names;
            interTruthTable.Fvalues = fvalues;
            interTruthTable.OutputName = outputName;

            //Diagram To TruthTable Minimization
            LogicPadParser.TruthTableSolver solver = new LogicPadParser.TruthTableSolver();
            solver.CurrentTruthTable = interTruthTable;
            solver.Solve();

            LogicPadParser.LogicPadParser.Instance.ParseInterTreeToTruthTable(
                LogicPadParser.LogicPadParser.truthTable,
                out numberOfTerm,
                out terms_names,
                out fvalues,
                out outputName
             );

            generatedTruthTable.Number_of_terms = numberOfTerm;
            generatedTruthTable.Terms_names = terms_names;
            generatedTruthTable.Fvalues = fvalues;
            generatedTruthTable.Rows = (int)Math.Pow(2, generatedTruthTable.Number_of_terms) + 1;
            generatedTruthTable.Columns = generatedTruthTable.Number_of_terms + 2;
            generatedTruthTable.OutputName = outputName;


            generatedExpr = InterTree.ParseExpressionToString(LogicPadParser.LogicPadParser.truthTable);
        }
Exemplo n.º 2
0
        //TruthTable
        public void ParseInterTreeToTruthTable(InterTree tree, 
            out int number_of_term, out string[] term_names, 
            out int[] fvalue, out string outputName)
        {
            List<String> termList = new List<String>();

            if (tree == null)
            {
                number_of_term = -1;
                term_names = null;
                fvalue = null;
                outputName = null;
                return;
            } 

            outputName = tree.LeftNode.Head;
            InterTree.ParseInterTreeTokens(tree.RightNode, ref termList);
            term_names = termList.ToArray();
            Array.Sort(term_names);
            number_of_term = termList.Count;

            //Add Parent pointer to each node
            InterTree.AddParentToInterTree(ref tree._rightNode);
            //Change Not Gate
            InterTree.FilterNotGate(ref tree._rightNode);
            //Change XOR and change Product to Summation
            InterTree.ReformulateInterTree(ref tree._rightNode);
            //Check Complement Law
            //InterTree.CheckComplement(ref tree._rightNode);
            //Check Domination Law
            //InterTree.CheckDominationLaw(ref tree._rightNode);
            /*
            if (tree._rightNode == null)
            {
                number_of_term = 0;
                term_names = null;
                fvalue = null;
                outputName = null;
                return;
            }
            */
            TruthTable truthTable = new TruthTable(number_of_term);
            truthTable.Terms_names = term_names;
            truthTable.OutputName = outputName;

            Dictionary<int, string[]> truthTableRows = truthTable.ConstructTruthTableRowList();
            //Initialization
            int row = (int)Math.Pow(2, number_of_term);
            Dictionary<int, int> truthTableResults = new Dictionary<int, int>(row);
            for (int index = 0; index < row; index++)
            {
                truthTableResults.Add(index, 0);
            }
            //Segement InterTree to InterTreeList
            List<InterTree> interTreeList = new List<InterTree>();

            InterTree.ParseInterTreeToInterTreeList(ref tree._rightNode, ref interTreeList);

            List<List<string>> stringArray = new List<List<string>>();
            InterTree.ParseInterTreeListToStringArray(interTreeList, ref stringArray, term_names);

            if (stringArray.Count == 0)
            {
                number_of_term = 0;
                term_names = null;
                fvalue = null;
                outputName = null;
                return;
            }

            InterTree.MatchInterTreeToTruthTable(stringArray, truthTableRows, ref truthTableResults, row);

            fvalue = truthTableResults.Values.ToArray();
        }
Exemplo n.º 3
0
        public int ParseExpressionUserControl(LogicPad2.Expression.UserControl1 userControl,
            out TruthTableWindow.TruthTable generatedTruthTable, out XElement generatedXElement)
        {
            int output = 2;
            generatedXElement = userControl.Parse(ref output);
            if(output != 2)
            {
                generatedTruthTable = null;
                return output;
            }
            LogicPadParser.LogicPadParser.Instance.ParseExpressionXElement(generatedXElement);
           
            generatedTruthTable = new TruthTableWindow.TruthTable();

            int numberOfTerm;
            String[] terms_names;
            int[] fvalues;
            string outputName;

            LogicPadParser.LogicPadParser.Instance.ParseInterTreeToTruthTable(
                LogicPadParser.LogicPadParser.expression,
                out numberOfTerm,
                out terms_names,
                out fvalues,
                out outputName
             );

            if (numberOfTerm == 0)
            {
                generatedTruthTable = null;
                return 0;
            }
            else if (numberOfTerm == -1)
            {
                generatedTruthTable = null;
                return 1;
            }

            LogicPadParser.TruthTable interTruthTable = new LogicPadParser.TruthTable(numberOfTerm);
            interTruthTable.Terms_names = terms_names;
            interTruthTable.Fvalues = fvalues;
            interTruthTable.OutputName = outputName;
            
            //Expression Minimization
            LogicPadParser.TruthTableSolver solver = new LogicPadParser.TruthTableSolver();
            solver.CurrentTruthTable = interTruthTable;
            solver.Solve();

            LogicPadParser.LogicPadParser.Instance.ParseInterTreeToTruthTable(
                LogicPadParser.LogicPadParser.truthTable,
                out numberOfTerm,
                out terms_names,
                out fvalues,
                out outputName
             );

            if (numberOfTerm == 0)
            {
                generatedTruthTable = null;
                return 0;
            }
            else if (numberOfTerm == -1)
            {
                generatedTruthTable = null;
                return 1;
            }

            generatedTruthTable.Number_of_terms = numberOfTerm;
            generatedTruthTable.Terms_names = terms_names;
            generatedTruthTable.Fvalues = fvalues;
            generatedTruthTable.Rows = (int)Math.Pow(2, generatedTruthTable.Number_of_terms) + 1;
            generatedTruthTable.Columns = generatedTruthTable.Number_of_terms + 2;

            return 2;
        }