Unexpected identical solutions in solutions pool
AnsweredI have a question about the solutions pool in Gurobi. In the code snippet below, I created an IP model with (a,b) = (1, 0) is the only solution. However, the model yields two identical (1, 0) solutions.
import gurobipy as gp
from gurobipy import GRB
model = gp.Model()
model.Params.PoolSearchMode = 2
model.Params.PoolSolutions = 2
vars = model.addVars(2, vtype = GRB.BINARY)
a, b = vars[0], vars[1]
model.addConstr((a == 0) >> (b >= 1)) # indicator constraint
model.addConstr(b == 0)
model.optimize()
print(f'\nSolutions count: {model.SolCount}')
for i in range(model.SolCount):
model.Params.SolutionNumber = i
print(f'Solution {i}: (a, b) = ({a.Xn}, {b.Xn})')
# Output
# Solutions count: 2
# Solution 0: (a, b) = (1.0, 0.0)
# Solution 1: (a, b) = (1.0, 0.0)
Are solutions in the solutions pool necessarily different? Is there any parameter that I can set to make sure the difference in the solutions pool?
One more thing is that if I change the indicator constraint to
model.addConstr((a == 0) >> (b == 1)) # it is (b >= 1) above
then the model yields only one solution, which is what I expected. It confuses me since b==1 and b>=1 are the same when b is a binary variable.
I'm using python 3.8 and gurobi 9.0.3.

Hi Quan,
In this case, you can also set PoolSearchMode=1 to not get any duplicates. The behavior comes from how indicator constraints are handled during presolving. We will try to get rid of these duplicate solutions in the future.
Cheers,
Matthias0
Please sign in to leave a comment.
Comments
1 comment