/// <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); }
public Bdd execute() { Bdd b = body.execute(); Bdd result = new Bdd(false); foreach (Var v in vars) { //Bdd b2 = v.execute(); //result = BDD.And(BDD.Restrict(b.Var, b2.Var, true), BDD.Restrict(b.Var, b2.Var, false)); result = BDD.Or(result, BDD.ForAll(v.execute().Var, b)); } b.Dispose(); return(result); }
/// <summary> /// Enforces maxvalues by disallowing values normally room for with the size of bits in an fdd /// Value is normally expected to be the same as used in the constructor of the fdd. /// Note: (powers of 2) -1) does not need to be constrained: 7, 255 etc. /// </summary> /// <param name="fdd">The fdd to constrain</param> /// <param name="value">The values to enforce</param> public static Bdd EnforceMaxValue(Fdd fdd, int value) { Bdd result; //Always allow all bits where most significant bit isn't set result = Kernel.Not(new Bdd(fdd.Var)); int start = (int)Math.Pow(2, Size(fdd) - 1); //lowest number with most significant bit set for (int i = start; i <= value; i++) { result = Kernel.Or(result, Equal(fdd, 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> /// Disjunction 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.Or(l, r)); }