Пример #1
0
    static void MinimalCpSatPrintIntermediateSolutions()
    {
        // Creates the model.
        CpModel model = new CpModel();
        // Creates the variables.
        int num_vals = 3;

        IntVar x = model.NewIntVar(0, num_vals - 1, "x");
        IntVar y = model.NewIntVar(0, num_vals - 1, "y");
        IntVar z = model.NewIntVar(0, num_vals - 1, "z");

        // Creates the constraints.
        model.Add(x != y);
        // Create the objective.
        model.Maximize(x + 2 * y + 3 * z);

        // Creates a solver and solves the model.
        CpSolver solver = new CpSolver();
        VarArraySolutionPrinterWithObjective cb =
            new VarArraySolutionPrinterWithObjective(new IntVar[] { x, y, z });

        solver.SearchAllSolutions(model, cb);
        Console.WriteLine(String.Format("Number of solutions found: {0}",
                                        cb.SolutionCount()));
    }
Пример #2
0
    static void MinimalCpSatPrintIntermediateSolutions()
    {
        // Creates the model.
        CpModel model = new CpModel();
        // Creates the variables.
        int num_vals = 3;

        IntVar x = model.NewIntVar(0, num_vals - 1, 'x');
        IntVar y = model.NewIntVar(0, num_vals - 1, 'y');
        IntVar z = model.NewIntVar(0, num_vals - 1, 'z');

        // Adds a different constraint.
        model.Add(x != y);

        // Maximizes a linear combination of variables.
        model.Maximize(x + 2 * y + 3 * z);

        // Creates a solver and solves the model.
        CpSolver solver = new CpSolver();
        VarArraySolutionPrinterWithObjective cb =
            new VarArraySolutionPrinterWithObjective(new IntVar[] { x, y, z });

        solver.SolveWithSolutionCallback(model, cb);
        Console.WriteLine(String.Format('Number of solutions found: {0}',
                                        cb.SolutionCount()));
    }
Пример #3
0
    static void Main()
    {
        // Creates the model.
        // [START model]
        CpModel model = new CpModel();
        // [END model]

        // Creates the variables.
        // [START variables]
        int num_vals = 3;

        IntVar x = model.NewIntVar(0, num_vals - 1, "x");
        IntVar y = model.NewIntVar(0, num_vals - 1, "y");
        IntVar z = model.NewIntVar(0, num_vals - 1, "z");

        // [END variables]

        // Adds a different constraint.
        // [START constraints]
        model.Add(x != y);
        // [END constraints]

        // Maximizes a linear combination of variables.
        // [START objective]
        model.Maximize(x + 2 * y + 3 * z);
        // [END objective]

        // Creates a solver and solves the model.
        // [START solve]
        CpSolver solver = new CpSolver();
        VarArraySolutionPrinterWithObjective cb =
            new VarArraySolutionPrinterWithObjective(new IntVar[] { x, y, z });

        solver.SolveWithSolutionCallback(model, cb);
        // [END solve]

        Console.WriteLine(String.Format("Number of solutions found: {0}",
                                        cb.SolutionCount()));
    }