Closed kaibir closed 2 years ago
Thanks, @kaibir. Indeed, the code was forcing lb=0 and ub=1 for all binary variables:
if var_type == mip.BINARY:
lb = 0.0
ub = 1.0
Now ub
is set to 1.0 only when the default value mip.INF
is passed.
What about lb=1?
The default is lb=0, but the user may now set lb=1. Here's the code that replaces the previous one:
if var_type == mip.BINARY:
if ub == mip.INF:
ub = 1.0
if not (-mip.EPS <= lb <= 1.0 + mip.EPS and -mip.EPS <= ub <= 1.0 + mip.EPS):
raise ValueError("Invalid bounds for a binary variable")
Describe the bug
If adding an upper bound via 'ub=' argument to binary variable it has no effect.
To Reproduce
To reproduce use this very simple model:
The objective value is 1.0 and also ZeroVar is 1.0
Expected behavior I would have expected that ZeroVar is 0.0 and also the objective value is.
If I add the additional constraint (which is in my eyes exactly what the ub should do)
my_model.add_constr(var <= 0)
I get the expected result.
I know it may not make much sense to add an upper limit of 0 to a binary variable, but ignoring the upper limit for binary variables is not right in my eyes either.
Desktop (please complete the following information):
Additional context Add any other context about the problem here.