public void TestSwapSimple2() { var manager = new BDDManager(3); var n2 = manager.Create(2, manager.One, manager.Zero); var n3 = manager.Create(1, manager.One, n2); var n4 = manager.Create(1, manager.Zero, manager.One); var root = manager.Create(0, n3, n4); var dict = new Dictionary <int, string> { { 0, "a" }, { 1, "b" }, { 2, "c" } }; var rdict = dict.ToDictionary((x) => x.Value, (x) => x.Key); var truth = BuildThruthTable(manager, root); Console.WriteLine(manager.ToDot(root, (x) => x.RefCount.ToString())); var res = manager.Swap(root, rdict["b"], rdict["c"]); CheckThruthTable(truth, res); Console.WriteLine(manager.ToDot(res, (x) => x.RefCount.ToString())); res = manager.Reduce(res); CheckThruthTable(truth, res); Console.WriteLine(manager.ToDot(res, (x) => x.RefCount.ToString())); }
public void TestSwapBug() { var dict = new Dictionary <int, string> { { 0, "x1" }, { 1, "x2" }, { 2, "x4" }, { 3, "x3" }, { 4, "x5" }, { 5, "x6" } }; var rdict = dict.ToDictionary((x) => x.Value, (x) => x.Key); var manager = new BDDManager(6); manager.GetVariableString = (x) => dict[x]; var n9 = manager.Create(rdict["x6"], 1, 0); var n8 = manager.Create(rdict["x5"], 0, n9); var n7 = manager.Create(rdict["x5"], n9, 0); var n6 = manager.Create(rdict["x3"], n8, n7); var n5 = manager.Create(rdict["x3"], 1, n7); var n4 = manager.Create(rdict["x4"], n5, n6); var root = n4; var truth = BuildThruthTable(manager, root); Console.WriteLine(manager.ToDot(root, (x) => x.RefCount.ToString())); var res = manager.Swap(root, rdict["x5"], rdict["x6"]); CheckThruthTable(truth, res); Console.WriteLine(manager.ToDot(res, (x) => x.RefCount.ToString())); }
public void TestSwapAsymetric() { var manager = new BDDManager(2); var n3 = manager.Create(1, manager.One, manager.Zero); var root = manager.Create(0, n3, manager.One); var dict = new Dictionary <int, string> { { 0, "a" }, { 1, "b" }, { 2, "c" } }; var truth = BuildThruthTable(manager, root); Console.WriteLine(manager.ToDot(root, (x) => x.RefCount.ToString())); var res = manager.Reduce(manager.Swap(root, 0, 1)); Console.WriteLine(manager.ToDot(res, (x) => x.RefCount.ToString())); CheckThruthTable(truth, res); }
private void LogToDotFormat(BDDNode root, BDDManager manager, Dictionary <string, BDDNode> nodeStore) { Dictionary <BDDNode, string> reverseHash = nodeStore.ToDictionary(a => a.Value, a => a.Key); Func <BDDNode, string> labelFunction = node => reverseHash.ContainsKey(node) ? reverseHash[node] + $"({node.Index})" : $"({reverseHash.FirstOrDefault(a => a.Key.Index == node.Index).Value})"; logger.Info("ROOT"); logger.Info(manager.ToDot(root, show_all: false, labelFunction: labelFunction)); }
public void TestComplex() { var dict = new Dictionary <int, string> { { 0, "x1" }, { 1, "x3" }, { 2, "x5" }, { 3, "x2" }, { 4, "x4" }, { 5, "x6" } }; var rdict = dict.ToDictionary((x) => x.Value, (x) => x.Key); var manager = new BDDManager(6); manager.GetVariableString = (x) => x < 6 ? dict[x] : "sink"; var a13 = manager.Create(rdict["x6"], manager.One, manager.Zero); var a12 = manager.Create(rdict["x4"], manager.One, a13); var a11 = manager.Create(rdict["x4"], manager.One, manager.Zero); var a10 = manager.Create(rdict["x2"], manager.One, manager.Zero); var a9 = manager.Create(rdict["x2"], manager.One, a13); var a8 = manager.Create(rdict["x2"], manager.One, a11); var a7 = manager.Create(rdict["x2"], manager.One, a12); var a6 = manager.Create(rdict["x5"], a13, manager.Zero); var a5 = manager.Create(rdict["x5"], a12, a11); var a4 = manager.Create(rdict["x5"], a9, a10); var a3 = manager.Create(rdict["x5"], a7, a8); var a2 = manager.Create(rdict["x3"], a5, a6); var a1 = manager.Create(rdict["x3"], a3, a4); var a0 = manager.Create(rdict["x1"], a1, a2); var truth = BuildThruthTable(manager, a0); Console.WriteLine(manager.ToDot(a0, (x) => "x" + x.Index + " (" + x.RefCount.ToString() + ")")); var res = manager.Sifting(a0); Console.WriteLine(manager.ToDot(res, (x) => "x" + x.Index + " (" + x.RefCount.ToString() + ")")); CheckThruthTable(truth, res); Assert.AreEqual(8, manager.GetSize(res)); }
public virtual string ToDot(BDDNode node) { return(_manager.ToDot(node, (arg) => { if (_rmapping[arg.Index] is KAOSCoreElement kce) { return kce.FriendlyName; } else { return _rmapping[arg.Index].ToString(); } }, false)); }
private void button5_Click(object sender, EventArgs e) { if (textBox1.Text != "") { string input = textBox1.Text; List <Token> rpn = Arithmetic.Calculate(input); if (rpn != null) { Dictionary <string, bool> variables = Arithmetic.GetVariables(rpn); var manager = new BDDManager(variables.Count); var root = Arithmetic.CreateTree(rpn, variables, manager); if (root != null) { List <BDDNode> list = root.Nodes.ToList(); var v1 = new Dictionary <int, string>(); int j = 0; foreach (KeyValuePair <string, bool> kv in variables) { v1.Add(j, kv.Key); j++; } manager.Reduce(root); Func <BDDNode, string> labelFunction = (x) => v1[x.Index]; Bitmap bm = new Bitmap(Graphviz.RenderImage(manager.ToDot(root, labelFunction, false), "jpg")); pictureBox1.Image = bm; label1.Text = "Готово"; } else { label1.Text = "Ошибка при вычислении логической формулы"; } } else { label1.Text = "Ошибка ввода логической формулы"; } } }
static void Main(string[] args) { var manager = new BDDManager(10); //var n3 = new BDDNode(2, manager.One, manager.One); //var n4 = new BDDNode(1, n3, manager.Zero); //var n2 = new BDDNode(1, n3, manager.Zero); //var n3 = manager.Create(2, manager.One, manager.One); //var n4 = manager.Create(1, n3, manager.Zero); //var n2 = manager.Create(1, n3, manager.Zero); //var root = manager.Create(0,n2, n4); //Console.WriteLine(n2); //Console.WriteLine(n3); //Console.WriteLine(n4); //Console.WriteLine(root); int index = 1; var p1_s = manager.Create(index++, manager.One, manager.Zero); var p1_k = manager.Create(index++, manager.One, manager.Zero); //var root = manager.Create(3, p1_s, p1_k); Console.WriteLine(p1_k); Console.WriteLine(p1_s); //var n2 = new BDDNode(1, p1_s, manager.Zero); var node = manager.Or(p1_k, p1_s); //node.Index = index++; var root = manager.Create(0, node, manager.Zero); Console.WriteLine(node); Console.WriteLine(root); //var reducedNode=manager.Reduce(root); //Console.WriteLine(reducedNode); var str = manager.ToDot(node); Console.WriteLine(str); //var root = new BDDNode(0, node, manager.Zero); //Console.WriteLine(root); //var node1 = manager.And(p1_k, p1_s); //var root1 = new BDDNode(0, node1, manager.Zero); // //var c = manager.Create(10, manager.Zero, manager.One); //string str = manager.Zero.ToString(); //string str1 = manager.One.ToString(); //Console.WriteLine(node1); //Console.WriteLine(node); //Console.WriteLine(node1); //Console.WriteLine(reucedBddNode); // -------------------------- //Program p = new Program(); //p.TestLarge01(30, 30); // Console.WriteLine(manager.ToDot(root)); //var reucedBddNode = manager.Reduce(node); //Console.WriteLine(manager.ToDot(reucedBddNode)); //Console.WriteLine(str); //Console.WriteLine(str1); //Console.WriteLine(root1); //Console.WriteLine(reucedBddNode); Console.Read(); //var root =new BDDNode(0, P1_1&000&000BI, P1_1&000&000CSL, P1_1&500&000BI, P1_1&500&000CSL, P1_10&000&000BI, P1_10&000&000CSL, P1_100&000BI, P1_100&000CSL, P1_2&000&000BI, P1_2&000&000CSL, P1_200&000BI, P1_200&000CSL, P1_25&000BI, P1_25&000CSL, P1_3&000&000BI, P1_3&000&000CSL, P1_300&000BI, P1_300&000CSL, P1_4&000&000BI, P1_4&000&000CSL, P1_5&000&000BI, P1_5&000&000CSL, P1_50&000BI, P1_50&000CSL, P1_500&000BI, P1_500&000CSL) // var P2_1&000&000BI = new BDDNode(2, false); //var P1_1 &000&000BI=new BDDNode(1,) }