/// <summary> /// And function for FDD's. /// </summary> /// <param name="u1">left side of the expression</param> /// <param name="u2">right side of the expression</param> /// <returns>a new BDD where u1 and u2 are bitwise and'ed</returns> public static Bdd And(Fdd u1, Fdd u2) { int u1Size = Size(u1); int u2Size = Size(u2); int MinSize = Min(u1Size, u2Size); Bdd result = new Bdd(false); for (int i = 0; i < MinSize; i++) { result = Kernel.Or(result, Kernel.And(new Bdd(u1.Var + i), new Bdd(u2.Var + i))); } if (u1Size != u2Size) { if (u1Size > u2Size) //you reach this state when 2 Fdds does not have the same number { //of bits. What happens is then the smallest get buffered with 0's for (int i = MinSize; i < u1Size; i++) { result = Kernel.Or(result, Kernel.And(new Bdd(u1.Var + i), new Bdd(false))); } } else { for (int i = MinSize; i < u2Size; i++) { result = Kernel.Or(result, Kernel.And(new Bdd(false), new Bdd(u2.Var + i))); } } } return(result); }
static void Main(string[] args) { /* * BDDHash ht = new BDDHash(); * BddNode b = new BddNode(3, 1, 0); * BddNode b1 = new BddNode(2, 1, 1); * BddNode b2 = new BddNode(16, 0, 0); * int key = ht.GenerateKey(b); * int key1 = ht.GenerateKey(b1); * int key2 = ht.GenerateKey(b2); * Console.WriteLine(key.ToString()); * * Console.WriteLine(ht.count.ToString()); // test count for Add * * ht.Add(key, b); // test Add * ht.Add(key1, b1); // test Add * ht.Add(key2, b2); // test Add * * Console.WriteLine(ht.count.ToString()); // test count for after Add * ht.Clear(); * Console.WriteLine(ht.count.ToString()); // test for Clear() * */ Bdd result = new Bdd(true); BDD.Setup(); { Bdd a = new Bdd(1); Bdd b = new Bdd(2); Bdd c = new Bdd(3); Bdd d = new Bdd(4); Bdd e; e = BDD.Equal(a, b); Console.WriteLine(BDD.TCount().ToString()); c = BDD.Equal(c, d); Console.WriteLine(BDD.TCount().ToString()); result = BDD.And(e, c); result = BDD.Or(result, e); } Console.WriteLine(BDD.TCount().ToString()); BddSerializer.Serialize(result, "foo"); }
public Bdd execute() { // Calls specific methods from Kernel Bdd l = left.execute(); Bdd r = right.execute(); Bdd result = new Bdd(false); switch (op) { case Kind.DIS: result = BDD.Or(l, r); break; case Kind.CON: result = BDD.And(l, r); break; case Kind.BIMP: result = BDD.Equal(l, r); break; case Kind.NAND: result = BDD.Nand(l, r); break; case Kind.XOR: result = BDD.Xor(l, r); break; case Kind.NOR: result = BDD.Nor(l, r); break; case Kind.NOT: result = BDD.Not(r); break; } l.Dispose(); //forced garbage collection r.Dispose(); return(result); }
/// <summary> /// Creates a hard binding sort of like an fdd restrict. /// Difference is that the binding will persist no matter /// what changes is later added. /// </summary> /// <param name="fdd">the Fdd to create a binding on</param> /// <param name="value">the constant number that is assigned to the Fdd.</param> /// <returns></returns> public static Bdd Equal(Fdd fdd, int value) { if (Log2(value) > FddDictionary[fdd.Var]) //value larger than fdd can hold. { return(new Bdd(false)); } bool[] b = ToBitPattern(value, Size(fdd)); Bdd result = new Bdd(true); for (int i = 0; i < b.Length; i++) { if (b[i]) { result = Kernel.And(result, new Bdd(fdd.Var + i)); } else { result = Kernel.And(result, Kernel.Not(new Bdd(fdd.Var + i))); } } return(result); }
/// <summary> /// Conjunction of two Bdds /// </summary> /// <param name="l">Left Bdd</param> /// <param name="r">Right Bdd</param> /// <returns>Resulting Bdd</returns> public static Bdd operator &(Bdd l, Bdd r) { return(Kernel.And(l, r)); }