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))
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.
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
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 -
Is the duplicate issue already resolved?
Thanks.
0 -
Hi Israel!
Yes, this issue has been fixed in the current release of Gurobi.
Cheers,
Matthias0
Post is closed for comments.
Comments
4 comments