Example #1
0
        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);
        }
Example #2
0
    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();
    }
Example #3
0
  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 static IntExpr Sum(this IntExpr[] exprs)
        {
            Solver solver = GetSolver(exprs);

            IntVar[] vars = new IntVar[exprs.Length];
            for (int i = 0; i < exprs.Length; ++i)
            {
                vars[i] = exprs[i].Var();
            }
            return(solver.MakeSum(vars));
        }
        // sum of all constraints.
        public static IntExpr Sum(this IConstraintWithStatus[] cts)
        {
            Solver solver = GetSolver(cts);

            IntVar[] vars = new IntVar[cts.Length];
            for (int i = 0; i < cts.Length; ++i)
            {
                vars[i] = cts[i].Var();
            }
            return(solver.MakeSum(vars));
        }
        // sum of all vars.
        public static IntExpr Sum(this IntVar[] vars)
        {
            Solver solver = GetSolver(vars);

            return(solver.MakeSum(vars));
        }