예제 #1
0
        // this demonstrate the structure interface
        static void test_structure_solver(string[] args)
        {
            SATSolver solver = new SATSolver();
            int       a      = solver.CreatePI();
            int       b      = solver.CreatePI();
            int       c      = solver.CreatePI();
            //int d = solver.CreatePI();
            int       xor_a_b     = solver.Xor(a, b);
            int       not_a       = solver.Not(a);
            int       not_b       = solver.Not(b);
            int       and_a_not_b = solver.And(a, not_b);
            int       and_b_not_a = solver.And(b, not_a);
            int       xor_a_b_p   = solver.Or(and_a_not_b, and_b_not_a);
            int       miter       = solver.Xor(xor_a_b, xor_a_b_p);
            SATStatus r           = solver.TestSAT(miter);

            WriteLine(String.Format("Test Right {0}", r.ToString()));

            int and_a_b       = solver.And(a, b);
            int xor_a_b_wrong = solver.Or(and_a_not_b, and_a_b);
            int miter1        = solver.Xor(xor_a_b, xor_a_b_wrong);

            r = solver.TestSAT(miter1);
            WriteLine(String.Format("Test Wrong {0}", r.ToString()));

            int and_a_b_c = solver.And(solver.And(a, b), c);

            int flag = solver.AllocFlag();

            solver.MarkTransitiveFanins(and_a_b_c, flag);
            for (int i = 0, sz = solver.NumPI(); i < sz; ++i)
            {
                int  node_id = solver.NthPI(i);
                bool flagset = solver.IsNodeFlagSet(node_id, flag);
                if (flagset)
                {
                    WriteLine(String.Format("PI {0} is in the transitive fanin", i));
                }
                else
                {
                    WriteLine(String.Format("PI {0} is NOT in the transitive fanin", i));
                }
            }
            solver.ClearFlag(flag);


            MyHashtable nameMap = new MyHashtable();

            nameMap.Add(0, "PrimaryIn 0");
            WriteLine(solver.TreeToString(miter1, nameMap));
            WriteLine(solver.TreeToString(xor_a_b, nameMap));

            WriteLine("Press Return...");
            System.Console.ReadLine();
        }
예제 #2
0
        public static bool test_small_model()
        {
            SATSolver solver = new SATSolver();

            int a = solver.NthPI(0);
            int b = solver.NthPI(1);
            int c = solver.NthPI(2);
            int d = solver.NthPI(3);

            int ab         = solver.And(a, b);
            int cd         = solver.And(c, d);
            int abcd       = solver.And(ab, cd);
            int constraint = solver.Constraint(abcd);

            solver.Solve();
            int [] model = solver.FindSmallModel();
            print_model(model);
            solver.ReleaseConstraint(constraint);

            int not_abcd = solver.Not(abcd);

            constraint = solver.Constraint(not_abcd);
            solver.Solve();
            model = solver.FindSmallModel();
            print_model(model);
            solver.ReleaseConstraint(constraint);

            int e            = solver.CreatePI();
            int f            = solver.CreatePI();
            int exf          = solver.Xor(e, f);
            int and_exf_abcd = solver.And(exf, abcd);

            constraint = solver.Constraint(and_exf_abcd);
            solver.Solve();
            model = solver.FindSmallModel();
            print_model(model);
            solver.ReleaseConstraint(constraint);

            int not_and_exf_abcd = solver.Not(and_exf_abcd);

            constraint = solver.Constraint(not_and_exf_abcd);
            solver.Solve();
            model = solver.FindSmallModel();
            print_model(model);
            solver.ReleaseConstraint(constraint);
            return(true);
        }