I would like to obtain more than one solution with SCIP. Using SAT (cp_model.CpModel()) I can collect all the possible solutions, 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:
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