Beispiel #1
0
        public void ConstructorTest()
        {
            int MaxValue = 3;

            Fdd target = new Fdd(MaxValue);

            Assert.IsNotNull(target, "Fdd was not created");
            Assert.IsNotNull(target.Root, "Root of Fdd was not initialized to a valid Bdd");
        }
Beispiel #2
0
        public void RootTest()
        {
            int MaxValue = 3;

            Fdd target = new Fdd(MaxValue);

            Assert.AreEqual(true, target.Root.High.IsTerminal(), "Root of Fdd not an ithvar (high not a terminal)");
            Assert.AreEqual(true, target.Root.Low.IsTerminal(), "Root of Fdd not an ithvar (low not a terminal)");
        }
Beispiel #3
0
        public static void EnforceTest()
        {
            Kernel.Setup();
            Bdd result;
            Fdd fdd = new Fdd(6);

            result = FddKernel.EnforceMaxValue(fdd, 6);

            BddSerializer.Serialize(result, "TTest");
        }
Beispiel #4
0
        public void VarTest()
        {
            int MaxValue = 40;

            Fdd target = new Fdd(MaxValue);

            int val = 1;

            Assert.AreEqual(val, target.Var, "BddSharp.Kernel.Fdd.Var was not set correctly.");
        }
Beispiel #5
0
        public void ToStringTest()
        {
            int MaxValue = 3;

            Fdd target = new Fdd(MaxValue);

            String expected = "1";
            String actual   = target.ToString();

            Assert.AreEqual(expected, actual, "Root did not get startvar 1");
        }
Beispiel #6
0
        public void GetHashCodeTest()
        {
            int MaxValue = 3;

            Fdd target = new Fdd(MaxValue);

            int expected = 1;
            int actual   = target.GetHashCode();

            Assert.AreEqual(expected, actual, "Root did not get startvar 1");
        }
Beispiel #7
0
        public void XorTest()
        {
            Fdd u1 = new Fdd(3);
            Fdd u2 = new Fdd(5);


            Bdd actual;

            actual = BddSharp.Kernel.FddKernel.Xor(u1, u2);
            int[] i = FddKernel.AnySat(actual, 3);

            Assert.AreNotEqual(i[0], i[1], "After an xor each factor must differ, but does not");
        }
Beispiel #8
0
        public void AnySatTest()
        {
            Fdd u1 = new Fdd(3);
            Fdd u2 = new Fdd(5);


            Bdd actual;

            actual = BddSharp.Kernel.FddKernel.Xor(u1, u2);
            int[] i = FddKernel.AnySat(actual, 3);

            Assert.AreEqual(2, i.Length, "Both u1,u2 returned a valid answers in AnySat.");
        }
Beispiel #9
0
        public FDDStatemachine()
        {
            FddKernel.Setup();
            transList = new Dictionary <Bdd, string>();

            F  = new Fdd(N);
            Fp = new Fdd(N);

            BuildInitialState();
            BuildEndState();
            BuildTransitions();
            pairs.Add(F.Var, Fp.Var);        //only pair to add.
            R = ReachableStates();
        }
Beispiel #10
0
        public void EqualsTest()
        {
            int MaxValue = 2;

            Fdd target = new Fdd(MaxValue);

            Fdd fdd = new Fdd(MaxValue);

            bool expected = false;
            bool actual;

            actual = target.Equals(fdd);

            Assert.AreEqual(expected, actual, "BddSharp.Kernel.Fdd.Equals did not return the expected value.");
        }
Beispiel #11
0
        private void solve_Click(object sender, EventArgs e)
        {
            Kernel.Setup();
            Fdd[] nodeArray = new Fdd[81];
            for (int i = 0; i < 81; i++)
            {
                nodeArray[i] = new Fdd(9);
            }

            //vertical xors
            Bdd b = new Bdd(true);

            //horisontal xors
            Bdd a = new Bdd(true);

            for (int i = 0; i < 9; i++)
            {
                for (int j = 1; j <= 8; j++)
                {
                    for (int k = j; k < 9; k++)
                    {
                        a = Kernel.And(a, FddKernel.Xor(nodeArray[i * 9 + j], nodeArray[i * 9 + k]));
                        b = Kernel.And(b, FddKernel.Xor(nodeArray[i + j * 9], nodeArray[i + k * 9]));
                    }
                }
            }

            //own grid restriction all nodes just check 2 nodes on line below.
            Bdd c = new Bdd(true);

            for (int i = 0; i < 81; i++)
            {
                c = Kernel.And(c, FddKernel.Xor(nodeArray[i], nodeArray[getLeft(i)]));
                c = Kernel.And(c, FddKernel.Xor(nodeArray[i], nodeArray[getRight(i)]));
            }

            Bdd result = Kernel.And(Kernel.And(a, b), c);

            int[] foo = FddKernel.AnySat(result, 9);

            //BddSerializer.Serialize(result, "Sudoku");
        }
Beispiel #12
0
        static void test()
        {
            FddKernel.Setup();
            Fdd[] X = new Fdd[3];
            for (int i = 0; i < 3; i++)
            {
                X[i] = new Fdd(8);
            }

            Bdd result = new Bdd(true);

            DateTime startSetup = DateTime.Now;

            //for(int i=0;i<8;i++)
            //    for(int j=i+1;j<9;j++)
            //        result = Kernel.And(result, FddKernel.Xor(X[i], X[j]));

            result = Kernel.And(result, FddKernel.Xor(X[0], X[1]));
            result = Kernel.And(result, FddKernel.Xor(X[0], X[2]));
            //result = Kernel.And(result, FddKernel.Xor(X[0], X[3]));
            //result = Kernel.And(result, FddKernel.Xor(X[0], X[4]));
            //result = Kernel.And(result, FddKernel.Xor(X[0], X[5]));
            //result = Kernel.And(result, FddKernel.Xor(X[0], X[6]));
            //result = Kernel.And(result, FddKernel.Xor(X[0], X[7]));
            //result = Kernel.And(result, FddKernel.Xor(X[0], X[8]));

            result = Kernel.And(result, FddKernel.Xor(X[1], X[2]));
            //result = Kernel.And(result, FddKernel.Xor(X[1], X[3]));
            //result = Kernel.And(result, FddKernel.Xor(X[1], X[4]));
            //result = Kernel.And(result, FddKernel.Xor(X[1], X[5]));
            //result = Kernel.And(result, FddKernel.Xor(X[1], X[6]));
            //result = Kernel.And(result, FddKernel.Xor(X[1], X[7]));
            //result = Kernel.And(result, FddKernel.Xor(X[1], X[8]));

            //result = Kernel.And(result, FddKernel.Xor(X[2], X[3]));
            //result = Kernel.And(result, FddKernel.Xor(X[2], X[4]));
            //result = Kernel.And(result, FddKernel.Xor(X[2], X[5]));
            //result = Kernel.And(result, FddKernel.Xor(X[2], X[6]));
            //result = Kernel.And(result, FddKernel.Xor(X[2], X[7]));
            //result = Kernel.And(result, FddKernel.Xor(X[2], X[8]));

            //result = Kernel.And(result, FddKernel.Xor(X[3], X[4]));
            //result = Kernel.And(result, FddKernel.Xor(X[3], X[5]));
            //result = Kernel.And(result, FddKernel.Xor(X[3], X[6]));
            //result = Kernel.And(result, FddKernel.Xor(X[3], X[7]));
            //result = Kernel.And(result, FddKernel.Xor(X[3], X[8]));

            //result = Kernel.And(result, FddKernel.Xor(X[4], X[5]));
            //result = Kernel.And(result, FddKernel.Xor(X[4], X[6]));
            //result = Kernel.And(result, FddKernel.Xor(X[4], X[7]));
            //result = Kernel.And(result, FddKernel.Xor(X[4], X[8]));

            //result = Kernel.And(result, FddKernel.Xor(X[5], X[6]));
            //result = Kernel.And(result, FddKernel.Xor(X[5], X[7]));
            //result = Kernel.And(result, FddKernel.Xor(X[5], X[8]));

            //result = Kernel.And(result, FddKernel.Xor(X[6], X[7]));
            //result = Kernel.And(result, FddKernel.Xor(X[6], X[8]));

            //result = Kernel.And(result, FddKernel.Xor(X[7], X[8]));

            DateTime finishSetup = DateTime.Now;
            TimeSpan timeSetup   = finishSetup - startSetup;

            //result = FddKernel.Restrict(result, X[1], 0);
            result = Kernel.And(result, FddKernel.Equal(X[1], 6));

            int[] foo = FddKernel.AnySat(result, 8);        //returns 0,1,2,3

            //BddSerializer.Serialize(result, "foo");
        }
Beispiel #13
0
        //0  |18 |             row1
        // 8 |   |             row2
        //  2|   |             row3
        //--- --- ---
        public static void EnforceTest2()
        {
            FddKernel.Setup();
            Fdd[] X = new Fdd[27];
            for (int i = 0; i < 27; i++)
            {
                X[i] = new Fdd(8);
            }

            Bdd result = new Bdd(true);

            //row1 restricts
            result = Kernel.And(result, FddKernel.Equal(X[0], 0));
            result = Kernel.And(result, FddKernel.Equal(X[3], 1));
            result = Kernel.And(result, FddKernel.Equal(X[4], 8));

            //grid 1 restricts (except row1)
            result = Kernel.And(result, FddKernel.Equal(X[10], 8));
            result = Kernel.And(result, FddKernel.Equal(X[20], 2));

            //row1 maxvalues restricts
            result = Kernel.Or(result, FddKernel.EnforceMaxValue(X[1], 8));
            result = Kernel.Or(result, FddKernel.EnforceMaxValue(X[2], 8));


            //row1
            for (int i = 0; i < 8; i++)
            {
                for (int j = i + 1; j < 9; j++)
                {
                    result = Kernel.And(result, FddKernel.Xor(X[i], X[j]));
                }
            }


            //small grid 1
            result = Kernel.And(result, FddKernel.Xor(X[0], X[9]));
            result = Kernel.And(result, FddKernel.Xor(X[0], X[10]));
            result = Kernel.And(result, FddKernel.Xor(X[0], X[11]));
            result = Kernel.And(result, FddKernel.Xor(X[0], X[18]));
            result = Kernel.And(result, FddKernel.Xor(X[0], X[19]));
            result = Kernel.And(result, FddKernel.Xor(X[0], X[20]));
            result = Kernel.And(result, FddKernel.Xor(X[1], X[9]));
            result = Kernel.And(result, FddKernel.Xor(X[1], X[10]));
            result = Kernel.And(result, FddKernel.Xor(X[1], X[11]));
            result = Kernel.And(result, FddKernel.Xor(X[1], X[18]));
            result = Kernel.And(result, FddKernel.Xor(X[1], X[19]));
            result = Kernel.And(result, FddKernel.Xor(X[1], X[20]));
            result = Kernel.And(result, FddKernel.Xor(X[2], X[9]));
            result = Kernel.And(result, FddKernel.Xor(X[2], X[10]));
            result = Kernel.And(result, FddKernel.Xor(X[2], X[11]));
            result = Kernel.And(result, FddKernel.Xor(X[2], X[18]));
            result = Kernel.And(result, FddKernel.Xor(X[2], X[19]));
            result = Kernel.And(result, FddKernel.Xor(X[2], X[20]));

            //row2
            //for (int i = 9; i < 17; i++)
            //    for (int j = i; j < 18; j++)
            //        result = Kernel.And(result, FddKernel.Xor(X[i], X[j]));

            ////row3
            //for (int i = 18; i < 26; i++)
            //    for (int j = i; j < 27; j++)
            //        result = Kernel.And(result, FddKernel.Xor(X[i], X[j]));
        }
Beispiel #14
0
        public string Run(bool b1, bool b2, bool b3)
        {
            Fdd[] nodeArray = new Fdd[16];
            for (int i = 0; i < 16; i++)
            {
                nodeArray[i] = new Fdd(4);
            }
            Bdd result = new Bdd(true);

            result = Kernel.And(result, FddKernel.Xor(nodeArray[0], nodeArray[1]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[0], nodeArray[2]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[0], nodeArray[3]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[0], nodeArray[4]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[0], nodeArray[5]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[0], nodeArray[8]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[0], nodeArray[12]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[1], nodeArray[2]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[1], nodeArray[3]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[1], nodeArray[4]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[1], nodeArray[5]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[1], nodeArray[9]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[1], nodeArray[13]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[2], nodeArray[3]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[2], nodeArray[6]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[2], nodeArray[7]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[2], nodeArray[10]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[2], nodeArray[14]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[3], nodeArray[6]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[3], nodeArray[7]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[3], nodeArray[11]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[3], nodeArray[15]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[4], nodeArray[5]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[4], nodeArray[6]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[4], nodeArray[7]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[4], nodeArray[8]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[4], nodeArray[12]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[5], nodeArray[9]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[5], nodeArray[13]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[6], nodeArray[7]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[6], nodeArray[10]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[6], nodeArray[14]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[7], nodeArray[11]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[7], nodeArray[15]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[8], nodeArray[9]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[8], nodeArray[10]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[8], nodeArray[11]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[8], nodeArray[12]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[8], nodeArray[13]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[9], nodeArray[10]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[9], nodeArray[11]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[9], nodeArray[13]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[10], nodeArray[11]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[10], nodeArray[14]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[10], nodeArray[15]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[11], nodeArray[14]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[11], nodeArray[15]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[12], nodeArray[13]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[12], nodeArray[14]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[12], nodeArray[15]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[13], nodeArray[14]));
            result = Kernel.And(result, FddKernel.Xor(nodeArray[13], nodeArray[15]));

            result = Kernel.And(result, FddKernel.Xor(nodeArray[14], nodeArray[15]));

            long l = Kernel.SatCount(result);

            string s = PrintNice(FddKernel.AnySat(result, 3));

            return(String.Format("Number of results: {0}{1}{2}", l, Environment.NewLine, s));
        }