Пример #1
0
        private Tree OnlyOneColor(int i, int j)
        {
            int  c1 = 1; // 1 цвет
            var  e1 = nameId[new ColoredEdge(i, j, 1)];
            Tree t1 = new Tree(e1);

            for (int c2 = 2; c2 <= colorNum; c2++)
            {
                e1 = nameId[new ColoredEdge(i, j, c2)];

                t1.AddAnd(t1, c1 == c2 ? new Tree(e1) : new Tree(e1, true));
            }
            Tree result = t1;


            for (c1 = 2; c1 <= colorNum; c1++)
            {
                e1 = nameId[new ColoredEdge(i, j, 1)];
                t1 = new Tree(e1, true); //1!=2
                for (int c2 = 2; c2 <= colorNum; c2++)
                {
                    e1 = nameId[new ColoredEdge(i, j, c2)];

                    t1.AddAnd(t1, c1 == c2 ? new Tree(e1) : new Tree(e1, true));
                }

                result.AddOr(result, t1);
            }
            return(result);
        }
Пример #2
0
        private bool Solve()
        {
            nameId = new Dictionary <ColoredEdge, int>(); // i, об color
            GenerateVariables();

            var cnf = new DPLL.CNF();

            //not one color in clique
            for (int c = 1; c <= colorNum; c++)
            {
                cnf.Add(GenerateCliqueNotOneColor(c));
            }

            Tree t = OnlyOneColor(1, 2);

            //only one color of edge
            for (int i = 1; i < n; i++)
            {
                for (int j = i + 1; j <= n; j++)
                {
                    if (i != 1 || j != 2)
                    {
                        t.AddAnd(t, OnlyOneColor(i, j));
                    }
                }
            }

            var ts = new DPLL.TseitinTransformer(t);

            cnf.Add(ts.Transform());

            vars = ts.GetVars;
            vars = new HashSet <int>(vars.Union(nameId.Values));

            var dpll = new DPLL.DPLL(vars);

            return(dpll.DPLLAlgo(cnf));
        }