static void Main() { Solver solver = new Google.OrTools.ConstraintSolver.Solver("p"); // creating dummy variables List <IntVar> vars = new List <IntVar>(); for (int i = 0; i < 200000; i++) { vars.Add(solver.MakeIntVar(0, 1)); } IntExpr globalSum = solver.MakeSum(vars.ToArray()); DecisionBuilder db = solver.MakePhase( vars.ToArray(), Google.OrTools.ConstraintSolver.Solver.INT_VAR_SIMPLE, Google.OrTools.ConstraintSolver.Solver.INT_VALUE_SIMPLE); solver.NewSearch(db, new OptimizeVar(solver, true, globalSum.Var(), 100)); GC.Collect(); GC.WaitForPendingFinalizers(); while (solver.NextSolution()) { Console.WriteLine("solution " + globalSum.Var().Value()); } Console.WriteLine("fini"); Console.ReadLine(); }
public void NewSearchTest() { Solver solver = new Google.OrTools.ConstraintSolver.Solver("p"); // creating dummy variables List <IntVar> vars = new List <IntVar>(); for (int i = 0; i < 100000; i++) { vars.Add(solver.MakeIntVar(0, 1)); } IntExpr globalSum = solver.MakeSum(vars.ToArray()); DecisionBuilder db = solver.MakePhase(vars.ToArray(), Google.OrTools.ConstraintSolver.Solver.INT_VAR_SIMPLE, Google.OrTools.ConstraintSolver.Solver.INT_VALUE_SIMPLE); solver.NewSearch(db, new OptimizeVar(solver, true, globalSum.Var(), 100)); // force Garbage Collector GC.Collect(); GC.WaitForPendingFinalizers(); // Try to read all solutions int count = 0; while (solver.NextSolution()) { count++; // Console.WriteLine("solution " + globalSum.Var().Value()); } Console.WriteLine("Solutions: " + count); }
public void Downcast() { Solver solver = new Solver("Solver"); IntVar x = solver.MakeIntVar(2, 17, "x"); IntExpr e = x + 5; IntVar y = e.Var(); Assert.Equal("(x(2..17) + 5)", y.ToString()); }
static void DowncastTest() { Solver solver = new Solver("TestDowncast"); IntVar x = solver.MakeIntVar(0, 10, "x"); IntExpr e = x + 1; IntVar y = e.Var(); Console.WriteLine(y.ToString()); }