Example #1
0
        public static void CheckRestrict()
        {
            Kernel.Setup();
            Bdd a = new Bdd(1);
            Bdd b = new Bdd(2);
            Bdd c = new Bdd(3);

            Bdd result = new Bdd(false);

            result = Kernel.Or(Kernel.Equal(a, b), c);

            string s1 = Kernel.AnySat(result);

            result = Kernel.Restrict(result, b.Var, true);

            string s2 = Kernel.AnySat(result);

            BddSerializer.Serialize(result, "foo");
        }
        // we are NOT using these rules

        /*
         * Regler:
         *
         * One location at a time:
         * -----------------------
         * if m1r then !m1b & !m1l
         * if m2r then !m2b & !m2l
         * if m3r then !m3b & !m3l
         *
         * Shore rule
         * ----------
         * if (m1r & m2r & !m3r) then
         * ((c1r & c2r & !c3r) | (!c1r & c2r & c3r) | (c1r & !c2r & c3r) |
         * (!c1r &!c2r & c3r) | (c1r & !c2r & !c3r) | (!c1r & c2r & !c3r) |
         * (!c1r & !c2r & !c3r))
         * if (m1r & m2r & m3r) then ((c1r & c2r & c3r) & (above rule))
         *
         * Boat rule (left)
         * ---------
         * if (m1bl & !m2bl & !m3bl) then
         * ((c1bl & !c2bl & !c3bl) | (!c1bl & !c2bl & c3bl) |!c1bl & c2bl & !c3bl) |
         * (!c1bl & !c2bl))
         * if (!m1bl & !m2bl & m3b1) then
         * (c1bl & c2bl & !c3bl) | (!c1bl & c2bl & c3bl) | (c1bl & !c2bl & c3bl) | (above rule)
         * if (m1bl & m2bl & !m3b1) then
         * (!c1bl & !c2bl & !c3bl)
         *
         * */


        public string Run()
        {
            Kernel.Setup();
            Bdd I, E, T, R;

            Bdd[] ml  = new Bdd[N]; // missionaries on left side
            Bdd[] mr  = new Bdd[N]; // missionaries on right side
            Bdd[] mbr = new Bdd[N]; // missionaries on boat on right side
            Bdd[] mbl = new Bdd[N]; // missionaries on boat on left side

            Bdd[] mlp  = new Bdd[N];
            Bdd[] mrp  = new Bdd[N];
            Bdd[] mbrp = new Bdd[N];
            Bdd[] mblp = new Bdd[N];

            Bdd[] cl  = new Bdd[N]; // cannibles on left side
            Bdd[] cr  = new Bdd[N]; // cannibles on right side
            Bdd[] cbr = new Bdd[N]; // cannibles on boat on right side
            Bdd[] cbl = new Bdd[N]; // cannibles on boat on left side

            Bdd[] clp  = new Bdd[N];
            Bdd[] crp  = new Bdd[N];
            Bdd[] cbrp = new Bdd[N];
            Bdd[] cblp = new Bdd[N];

            Bdd br, brp, bl, blp; // the boat on right, the boat on right', the boat one the left, etc.


            //List<int> PreState = new List<int>();
            //List<int> PostState = new List<int>();

            BddPairList pairList = new BddPairList();

            // *2 because we have both missionaries and cannibals
            // *4 because they all have four variables
            for (int i = 0; i < N * 2 * 4; i++)
            {
                pairList.Add(i * 2, i * 2 + 1);
            }

            //for (int i = 0; i < N*2*4; i++)
            //{
            //    PreState.Add(i * 2);
            //    PostState.Add(i * 2 + 1);
            //}

            for (int i = 0; i < N; i++)
            {
                ml[i]   = new Bdd(i * 16);
                mlp[i]  = new Bdd(i * 16 + 1);
                mbl[i]  = new Bdd(i * 16 + 2);
                mblp[i] = new Bdd(i * 16 + 3);
                mr[i]   = new Bdd(i * 16 + 4);
                mrp[i]  = new Bdd(i * 16 + 5);
                mbr[i]  = new Bdd(i * 16 + 6);
                mbrp[i] = new Bdd(i * 16 + 7);
                cl[i]   = new Bdd(i * 16 + 8);
                clp[i]  = new Bdd(i * 16 + 9);
                cbl[i]  = new Bdd(i * 16 + 10);
                cblp[i] = new Bdd(i * 16 + 11);
                cr[i]   = new Bdd(i * 16 + 12);
                crp[i]  = new Bdd(i * 16 + 13);
                cbr[i]  = new Bdd(i * 16 + 14);
                cbrp[i] = new Bdd(i * 16 + 15);
            }
            bl  = new Bdd(N * 16);
            blp = new Bdd(N * 16 + 1);
            pairList.Add(N * 16, N * 16 + 1);
            br  = new Bdd(N * 16 + 2);
            brp = new Bdd(N * 16 + 3);
            pairList.Add(N * 16 + 2, N * 16 + 3);



            I = InitialState(mr, cr, ml, cl, mbr, cbr, mbl, cbl, bl, br);
            E = EndState(mr, cr, ml, cl, mbr, cbr, mbl, cbl, bl, br);
            T = Transitions(mr, cr, ml, cl, mbr, cbr, mbl, cbl, mrp, crp, mlp, clp, mbrp, cbrp, mblp, cblp, bl, blp, br, brp);
            //R = ReachableStates(I, T, PreState, PostState);
            R = ReachableStates(I, T, pairList);
            Bdd result = E & R;

            //BddSerializer.Serialize(R, "output2");
            return("R&E-satcount: " + Kernel.SatCount(result).ToString() +
                   Environment.NewLine +
                   "R&E-anysat: " + Kernel.AnySat(result) +
                   Environment.NewLine +
                   "R-satcount: " + Kernel.SatCount(R).ToString() +
                   Environment.NewLine +
                   "LevelCount: " + count.ToString());
        }