0

I would like to obtain more than one solution with SCIP. Using SAT (cp_model.CpModel()) I can collect all the possible solutions, but when they are too many, it takes way too long. I would like to be able get the top N best solutions with SCIP, is it possible?

(I say SCIP because I've read that this can be done only using Gurobi or SCIP through OR-Tools).

Instead of cleaning out my actual problem, I'll use this OR-Tools MIP example, because it has a nice graphic that shows the possible solutions; for the sake of this example, I would like to get them all:

enter image description here

from ortools.linear_solver import pywraplp

solver = pywraplp.Solver.CreateSolver("SCIP")

infinity = solver.infinity()
x = solver.IntVar(0.0, infinity, "x")
y = solver.IntVar(0.0, infinity, "y")

solver.Add(x + 7 * y <= 17.5)
solver.Add(x <= 3.5)

solver.Maximize(x + 10 * y)

print(f"Solving with {solver.SolverVersion()}")
status = solver.Solve()

if status == pywraplp.Solver.OPTIMAL:

    for _ in range(5):

        print(f"Objective value = {solver.Objective().Value():0.3f}")
        print("x =", x.solution_value())
        print("y =", y.solution_value())

        if solver.NextSolution():
            print(f"There is another solution: ")
        else:
            print("No more solutions")
            break

else:
    print("The problem does not have an optimal solution.")

I get this:

Solving with SCIP 9.0.0 [LP solver: Glop 9.10]
Objective value = 23.000
x = 3.0
y = 2.0
There is another solution:
Objective value = 0.000
x = 0.0
y = 0.0
No more solutions

I tried configuring SCIP like this, but that didn't help:


solver = pywraplp.Solver.CreateSolver("SCIP")

solver.SetSolverSpecificParametersAsString("limits/solutions=-1")
solver.SetSolverSpecificParametersAsString("limits/bestsol=-1")
solver.SetSolverSpecificParametersAsString("constraints/countsols/sollimit=-1")
solver.SetSolverSpecificParametersAsString("constraints/countsols/collect=TRUE")
solver.SetSolverSpecificParametersAsString("constraints/countsols/discardsols=FALSE")
...

Is there something I'm doing wrong or misunderstanding? Is this possible?

Thanks

1 Answer 1

0

each time you can SetSolversSpecificParametersAsString, it overwrite the previous argument.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried not calling SetSolverSpecificParametersAsString at all and also calling it once, using one of the mentioned parameters in different runs, but still I get the same results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.