Example #1
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 #2
0
        public void Test()
        {
            Solver solver = new Solver(-10000, 10000);
            IntVar a      = new IntVar(solver, 1, 2, "a");
            IntVar b      = new IntVar(solver, 2, 3, "b");
            IntVar c      = new IntVar(solver, 3, 4, "c");
            IntVar d      = new IntVar(solver, 4, 5, "d");

            IntVarListDotProduct cons = new IntVarListDotProduct(
                solver,
                new IntVar[] { a, b, c, d },
                new int[] { 1000, 100, 10, 1 });
            IntVar result = cons.Var0;

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

            Assert.AreEqual(result.Domain, new IntDomain(1234, 2345));
        }
Example #3
0
        public void Test()
        {
            Solver solver	= new Solver( -10000, 10000 );
            IntVar a	= new IntVar( solver, 1, 2, "a" );
            IntVar b	= new IntVar( solver, 2, 3, "b" );
            IntVar c	= new IntVar( solver, 3, 4, "c" );
            IntVar d	= new IntVar( solver, 4, 5, "d" );

            IntVarListDotProduct cons	= new IntVarListDotProduct(
                solver,
                new IntVar[] { a, b, c, d },
                new int[] { 1000, 100, 10, 1 } );
            IntVar result	= cons.Var0;

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

            Assert.AreEqual( result.Domain, new IntDomain( 1234, 2345 ) );
        }
Example #4
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 #5
0
        public static IntVarMatrix operator *( IntVarMatrix lhs, int[] rhs )
        {
            if( lhs.ColCount != rhs.Length )
                throw new Exception( "" );

            Solver solver	= lhs.Solver;
            IntVarList list	= new IntVarList( solver );

            for( int row = 0; row < lhs.RowCount; ++row )
            {
                IntVar[] rowList	= new IntVar[ lhs.ColCount ];

                for( int col = 0; col < lhs.ColCount; ++col )
                {
                    rowList[ col ]	= lhs.Cell( row, col );
                }

                IntVarListDotProduct dp		= new IntVarListDotProduct( solver, rowList, rhs );
                solver.Add( dp );

                list.Add( dp.Var0 );
            }

            return new IntVarMatrix( solver, lhs.ColCount, 1, list );
        }