//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(); }