Example #1
0
        /// <summary>
        /// Equal 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 equal</returns>
        public static Bdd Equal(Fdd u1, Fdd u2)
        {
            int u1Size  = Size(u1);
            int u2Size  = Size(u2);
            int MinSize = Min(u1Size, u2Size);
            Bdd result  = new Bdd(true);

            for (int i = 0; i < MinSize; i++)
            {
                result = Kernel.And(result, Kernel.Equal(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.And(result, Kernel.Equal(new Bdd(u1.Var + i), new Bdd(false)));
                    }
                }
                else
                {
                    for (int i = MinSize; i < u2Size; i++)
                    {
                        result = Kernel.And(result, Kernel.Equal(new Bdd(false), new Bdd(u2.Var + i)));
                    }
                }
            }

            return(result);
        }
Example #2
0
        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");
        }
Example #3
0
        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);
        }
Example #4
0
 /// <summary>
 /// Equals operator on 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.Equal(l, r));
 }