Example #1
0
        public Cover(Solver solver, int columns, IntVarList list) :
            base(solver)
        {
            m_Columns = columns;

            m_List  = list;
            m_Avail = new IntVar(solver, 0, list.Count - 1);;

            m_Index = new IntVar(solver, IntDomain.Empty, "");
            m_Union = new IntVar(solver, IntDomain.Empty, "");
        }
Example #2
0
        public Golomb(int n) :
            base()
        {
            int maxLength = (int)Math.Pow(2, (n - 1)) - 1;

            m_Solver.Horizon = new IntInterval(0, maxLength);

            m_MarkList = new IntVarList(m_Solver);
            for (int idx = 0; idx < n; ++idx)
            {
                m_MarkList.Add(new IntVar(m_Solver, idx, maxLength, "m" + (idx + 1).ToString()));
            }

            int mark = 0;
            int pos  = 0;

            m_DiffList = new IntVarList(m_Solver, n * (n - 1));
            for (int i = 0; i < n - 1; ++i)
            {
                for (int j = i + 1; j < n; ++j)
                {
                    if (i == n / 2 && j == n - 1)
                    {
                        mark = pos;
                    }

                    IntVarExpr exp = m_MarkList[j] - m_MarkList[i];
                    exp.Var0.Min  = 1;
                    exp.Var0.Name = "#" + m_MarkList[j].Name + "-" + m_MarkList[i].Name;
                    m_Solver.Add(exp);

                    m_DiffList.Add(exp.Var0);

                    ++pos;
                }
            }

            IntVarListAllDifferent ad = m_DiffList.AllDifferent();

            //ad.Level	= Constraint.PropagateLevel.High;
            m_Solver.Add(ad);

            // start mark at 0
            m_MarkList[0].Value = 0;

            // lower half should be less than the half difference
            IntVarCmp cmp = m_MarkList[(n - 1) / 2] < m_DiffList[mark];

            m_Solver.Add(cmp);

            Console.WriteLine(cmp.ToString() + ", " + m_DiffList[mark].ToString());
        }
Example #3
0
        static void Test2()
        {
            Solver                 solver = new Solver(0, 100);
            IntVar                 a      = new IntVar(solver, 1, 3, "a");
            IntVar                 b      = new IntVar(solver, 1, 3, "b");
            IntVar                 c      = new IntVar(solver, 1, 3, "c");
            IntVarList             l      = new IntVarList(a, b, c);
            IntVarListAllDifferent diff   = l.AllDifferent();

            solver.Add(diff);
            solver.Propagate();

            a.Value = 1;
            b.Value = 2;
        }
Example #4
0
        public void Test()
        {
            Solver solver = new Solver(-1000, 1000);
            IntVar i0     = new IntVar(solver, 0, 10);
            IntVar i1     = new IntVar(solver, 10, 20);
            IntVar i2     = new IntVar(solver, 20, 30);
            IntVar s      = new IntVar(solver, 30, 60);

            IntVarList    list = new IntVarList(solver, new IntVar[] { i0, i1, i2 });
            IntVarListSum sum  = list.Sum();

            solver.Add(sum);
            solver.Propagate();

            Assert.AreEqual(s.Domain, sum.Var0.Domain);
        }
Example #5
0
        static void Test1()
        {
            Solver        solver = new Solver(0, 100);
            IntVar        a      = new IntVar(solver, 0, 10);
            IntVar        b      = new IntVar(solver, 0, 10);
            IntVar        c      = new IntVar(solver, 0, 10);
            IntVarList    l      = new IntVarList(a, b, c);
            IntVarListSum sum    = l.Sum();

            solver.Add(sum);
            solver.Propagate();

            sum.Var0.Value = 6;

            a.Value = 1;
            b.Value = 2;
        }
        public void Test()
        {
            Solver     solver = new Solver(-1000, 1000);
            IntVar     a      = new IntVar(solver, -10, -5, "a");
            IntVar     b      = new IntVar(solver, -1, 1, "b");
            IntVar     c      = new IntVar(solver, 5, 10, "c");
            IntVarList list   = new IntVarList(solver, new IntVar[] { a, b, c });

            IntVar          index  = new IntVar(solver);
            IntVarListIndex cons   = list.At(index);
            IntVar          result = cons.Var0;

            solver.Add(cons);
            solver.Propagate();

            result.Intersect(-8, 8);
            result.Difference(-2, 6);
            cons.Index.Difference(1);
        }
Example #7
0
        static void Mul2()
        {
            IntDomain v = new IntDomain();

            for (int idx = 0; idx < 100000; ++idx)
            {
                Solver     s = new Solver(-1000, 1000);
                IntVar     a = new IntVar(s, IntDomain.Random(-100, 100, 1), "a");
                IntVar     b = new IntVar(s, IntDomain.Random(-100, 100, 1), "b");
                IntVar     c = new IntVar(s, IntDomain.Random(-100, 100, 1), "c");
                IntVar     d = new IntVar(s, IntDomain.Random(-100, 100, 1), "d");
                IntVarList l = new IntVarList(s, new IntVar[] { a, b, c, d });
                //p.Add( a + b + c + d );
                s.Add(l.Sum());

                s.Propagate();
                s.PrintVariables();
                s.PrintConstraints();
            }
        }
Example #8
0
        static void Mul1()
        {
            Solver       solver = new Solver(0, 10000);
            IntVarMatrix m1     = new IntVarMatrix(solver, 2, 2, new IntInterval(0, 100));

            int[]        v  = new int[] { 1, 2 };
            IntVarMatrix m2 = m1 * v;

            solver.Propagate();
            solver.PrintVariables(Console.Out);

            Solver     s1 = new Solver(-1000000, 1000000);
            IntVar     a  = new IntVar(s1, IntDomain.Random(-100, 100, 1), "a");
            IntVar     b  = new IntVar(s1, IntDomain.Random(-100, 100, 1), "b");
            IntVar     c  = new IntVar(s1, IntDomain.Random(-100, 100, 1), "c");
            IntVarList l  = new IntVarList(s1, new IntVar[] { a, b, c });

            s1.Add(l.Mul());
            s1.Propagate();
            s1.PrintVariables(Console.Out);
        }
Example #9
0
        public MoreMoney() :
            base(0, 1000000)
        {
            IntVar d = new IntVar(m_Solver, 0, 9, "d");
            IntVar e = new IntVar(m_Solver, 0, 9, "e");
            IntVar m = new IntVar(m_Solver, 1, 9, "m");
            IntVar n = new IntVar(m_Solver, 0, 9, "n");
            IntVar o = new IntVar(m_Solver, 0, 9, "o");
            IntVar r = new IntVar(m_Solver, 0, 9, "r");
            IntVar s = new IntVar(m_Solver, 1, 9, "s");
            IntVar y = new IntVar(m_Solver, 0, 9, "y");

            IntVarList list = new IntVarList(m_Solver, new IntVar[] { d, e, m, n, o, r, s, y });

            m_Solver.Add(list.AllDifferent());

            IntVarListDotProduct send = new IntVarListDotProduct(m_Solver,
                                                                 new IntVar[] { s, e, n, d },
                                                                 new int[] { 1000, 100, 10, 1 });
            IntVarListDotProduct more = new IntVarListDotProduct(m_Solver,
                                                                 new IntVar[] { m, o, r, e },
                                                                 new int[] { 1000, 100, 10, 1 });
            IntVarListDotProduct money = new IntVarListDotProduct(m_Solver,
                                                                  new IntVar[] { m, o, n, e, y },
                                                                  new int[] { 10000, 1000, 100, 10, 1 });

            m_Solver.Add(send);
            m_Solver.Add(more);
            m_Solver.Add(money);

            IntVarExpr sendMore = send.Var0 + more.Var0;

            m_Solver.Add(sendMore);

            IntVarCmp cmp = sendMore.Var0 == money.Var0;

            m_Solver.Add(cmp);
        }
Example #10
0
 public ExactCover(int columns) :
     base(0, 1024)
 {
     m_List = new IntVarList(m_Solver);
 }