示例#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
文件: Constraint.cs 项目: nofear/Mara
 protected Constraint( Solver solver )
     : base(solver)
 {
     m_Level				= PropagateLevel.Normal;
     m_CountFail			= 0;
     m_CountUpdate		= 0;
     m_Index				= -1;
 }
示例#4
0
文件: Cover.cs 项目: nofear/Mara
        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
文件: IntVarTest.cs 项目: nofear/Mara
        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
文件: TestBase.cs 项目: nofear/Mara
        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
文件: AppGolomb.cs 项目: nofear/Mara
        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
文件: Problem.cs 项目: nofear/Mara
 public Problem( IntInterval horizon )
 {
     m_Solver	= new Solver( horizon );
 }
示例#15
0
文件: Program.cs 项目: nofear/Mara
        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
文件: TestGolomb.cs 项目: nofear/Mara
 public SolutionGoal( Solver solver, IntVar var )
     : base(solver)
 {
     m_Variable	= var;
     m_Value		= m_Variable.Domain.Max;
 }
示例#17
0
文件: Program.cs 项目: nofear/Mara
        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
文件: Program.cs 项目: nofear/Mara
        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
文件: AppGolomb.cs 项目: nofear/Mara
 public SolutionGoal( Solver solver, IntObjective objective, Objective value, string instance )
     : base(solver)
 {
     m_Objective			= objective;
     m_Value				= value;
     m_Instance			= instance;
 }
示例#20
0
文件: SolverBase.cs 项目: nofear/Mara
 public SolverBase( Solver solver )
 {
     m_Solver	= solver;
 }
示例#21
0
 public GoalDelegate( Solver solver, ExecuteDelegate execute )
     : base(solver)
 {
     m_Execute	= execute;
 }
示例#22
0
文件: Goal.cs 项目: nofear/Mara
 protected Goal( Solver solver )
     : base(solver)
 {
 }
示例#23
0
文件: FltVarList.cs 项目: nofear/Mara
 public FltVarList( Solver solver )
     : this(solver, 0)
 {
 }
示例#24
0
文件: GoalAnd.cs 项目: nofear/Mara
 public GoalAnd( Solver solver, Goal[] goalList )
     : base(solver)
 {
     m_GoalList		= goalList;
     m_Index			= new RevValue<int>( solver.StateStack, 0 );
 }
示例#25
0
文件: FltVarList.cs 项目: nofear/Mara
 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
文件: Program.cs 项目: nofear/Mara
        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
文件: FltVarList.cs 项目: nofear/Mara
 public FltVarList( Solver solver, int capacity )
     : base(solver)
 {
     Capacity	= capacity;
 }
示例#29
0
文件: GoalOr.cs 项目: nofear/Mara
 public GoalOr( Solver solver, Goal[] goalList )
     : base(solver)
 {
     m_GoalList		= goalList;
     m_Index			= 0;
 }
示例#30
0
 public SolverBaseCopy( Solver solver )
     : base(solver)
 {
 }
示例#31
0
文件: Program.cs 项目: nofear/Mara
        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) );
                }
            }
        }