Пример #1
0
 public IntObjective( Solver solver )
     : base(solver)
 {
     m_Variable	= null;
     m_Value		= int.MaxValue;
     m_Step		= 1;
 }
Пример #2
0
        protected ConstraintVar( Solver solver, Variable[] varList, VariableList[] varListList )
            : base(solver)
        {
            m_VariableList		= varList;
            m_VariableListList	= varListList;

            OnSet();
        }
Пример #3
0
 protected Constraint( Solver solver )
     : base(solver)
 {
     m_Level				= PropagateLevel.Normal;
     m_CountFail			= 0;
     m_CountUpdate		= 0;
     m_Index				= -1;
 }
Пример #4
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, "" );
        }
Пример #5
0
        public void Enumerator()
        {
            Solver solver	= new Solver( -1000, 1000 );
            IntVar var		= new IntVar( solver, 0 );

            var.Difference( 0 );

            foreach( int x in var )
            {
                Assert.Fail();
            }
        }
Пример #6
0
        public void Test()
        {
            Solver solver	= new Solver( -100, 100 );
            FltVar a		= new FltVar( solver, 5, 10, "a" );
            FltVarNeg neg	= -a;
            FltVar b		= neg.Var0;

            solver.Add( neg );
            solver.Propagate();

            Assert.AreEqual( b.Domain, new FltDomain( -10, -5 ) );
        }
Пример #7
0
        public void Test()
        {
            Solver solver	= new Solver( -1000, 1000 );
            FltVar i0	= new FltVar( solver, 0, 10 );
            FltVar i1	= new FltVar( solver, 10, 20 );
            FltVar i2	= new FltVar( solver, 20, 30 );
            FltVar s	= new FltVar( solver, 30, 60 );

            FltVarList list		= new FltVarList( solver, new FltVar[] { i0, i1, i2 } );
            FltVarListSum sum	= list.Sum();

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

            Assert.AreEqual( s.Domain, sum.Var0.Domain );
        }
Пример #8
0
        public static int CountSolution( Solver solver )
        {
            int count	= 1;
            while( solver.Next() )
            {
                if( count % 100 == 0 )
                {
                    Console.Out.Write( "." );
                }

                ++count;
            }

            Console.Out.WriteLine( " #" + count.ToString() );

            return count;
        }
Пример #9
0
        static void GolombExecute( Solver solver, Objective objective, IntSearch search, string instance )
        {
            DateTime start	= DateTime.Now;

            solver.Solve( new GoalAnd( new IntGenerate( solver,
                                                solver.IntVarList.ToArray(),
                                                IntVarSelector.FirstNotBound,
                                                search ),
                                        new SolutionGoal( solver, solver.IntObjective, objective, instance ) ) );

            SearchAll( solver, instance );

            TimeSpan span	= DateTime.Now - start;

            Console.Out.WriteLine();
            Console.Out.WriteLine( instance + "\t" + span.ToString() );
        }
Пример #10
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 ) );
        }
Пример #11
0
        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 );
        }
Пример #12
0
        public void High()
        {
            Solver solver	= new Solver( -10000, 10000 );
            IntVar a	= new IntVar( solver, 1, 3, "a" );
            IntVar b	= new IntVar( solver, 1, 2, "b" );
            IntVar c	= new IntVar( solver, 1, 2, "c" );

            IntVarListAllDifferent cons	= new IntVarListAllDifferent(
                solver,
                new IntVar[] { a, b, c } );

            cons.Level	= PropagateLevel.High;

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

            Assert.AreEqual( a.Domain, new IntDomain( 3, 3 ) );
            Assert.AreEqual( b.Domain, new IntDomain( 1, 2 ) );
            Assert.AreEqual( c.Domain, new IntDomain( 1, 2 ) );
        }
Пример #13
0
 public GoalPrintVar( Solver solver, Variable var )
     : base(solver)
 {
     m_Var	= var;
 }
Пример #14
0
 public Problem( IntInterval horizon )
 {
     m_Solver	= new Solver( horizon );
 }
Пример #15
0
        static void Test3()
        {
            Solver solver		= new Solver( 0, 10000 );
            IntVar a			= new IntVar( solver, 1, 9, "a" );
            IntVar b			= new IntVar( solver, 1, 9, "b" );
            IntVarExpr expr		= a * a + b * b;

            solver.Add( expr );
            solver.Propagate();

            a.Value		= 4;
            b.Value		= 2;
        }
Пример #16
0
 public SolutionGoal( Solver solver, IntVar var )
     : base(solver)
 {
     m_Variable	= var;
     m_Value		= m_Variable.Domain.Max;
 }
Пример #17
0
        static void Prop1()
        {
            Solver solver	= new Solver( -10000, 10000 );
            IntVar a		= new IntVar( solver, 6, 10, "a" );
            IntVar b		= new IntVar( solver, 1, 2, "b" );
            IntVarExprVal cons	= new IntVarExprValMul( a, b, 5 );
            solver.Add( cons );
            solver.Propagate();

            Console.WriteLine();
        }
Пример #18
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;
        }
Пример #19
0
 public SolutionGoal( Solver solver, IntObjective objective, Objective value, string instance )
     : base(solver)
 {
     m_Objective			= objective;
     m_Value				= value;
     m_Instance			= instance;
 }
Пример #20
0
 public SolverBase( Solver solver )
 {
     m_Solver	= solver;
 }
Пример #21
0
 public GoalDelegate( Solver solver, ExecuteDelegate execute )
     : base(solver)
 {
     m_Execute	= execute;
 }
Пример #22
0
 protected Goal( Solver solver )
     : base(solver)
 {
 }
Пример #23
0
 public FltVarList( Solver solver )
     : this(solver, 0)
 {
 }
Пример #24
0
 public GoalAnd( Solver solver, Goal[] goalList )
     : base(solver)
 {
     m_GoalList		= goalList;
     m_Index			= new RevValue<int>( solver.StateStack, 0 );
 }
Пример #25
0
 public FltVarList( Solver solver, FltVar[] list )
     : this(solver)
 {
     foreach( FltVar var in list )
     {
         Add( var );
     }
 }
Пример #26
0
 public Problem(IntInterval horizon)
 {
     m_Solver = new Solver(horizon);
 }
Пример #27
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;
        }
Пример #28
0
 public FltVarList( Solver solver, int capacity )
     : base(solver)
 {
     Capacity	= capacity;
 }
Пример #29
0
 public GoalOr( Solver solver, Goal[] goalList )
     : base(solver)
 {
     m_GoalList		= goalList;
     m_Index			= 0;
 }
Пример #30
0
 public SolverBaseCopy( Solver solver )
     : base(solver)
 {
 }
Пример #31
0
        private static void Poly1()
        {
            Random rnd	= new Random(0);
            for( int i = 0; i < 10000000; ++i )
            {
                double a	= rnd.Next( -10, 10 );
                double b	= rnd.Next( -10, 10 ) ;
                double c	= rnd.Next( -10, 10 ) ;

                a=2;b=8;c=8;

                Solver s		= new Solver( -1000000, 1000000 );
                FltVar x		= new FltVar( s, "x" );
                FltVarExpr exp	= a*x*x+ b*x;
                s.Add( exp );
                s.Add( exp == -c );

                s.PrintConstraints();
                s.PrintVariables();

                Console.Out.WriteLine( "{0}.x^2 + {1}.x + {2} = 0", a, b, c );

                s.Solve( new FltGenerate( s, new FltVar[] { x } ) );
                Console.Out.WriteLine( x.ToString(true) );
                while( s.Next() )
                {
                    Console.Out.WriteLine( x.ToString(true) );
                }
            }
        }