Binary variable ignored at multiplication
AnsweredHi
I´m trying to multiply an binary variable with the Big-M factor which is set as 5e7 in a similar form as following:
a = n * Big_M * (1 - x[i , j])
However, when n is not zero, the term (1-x[i , j]) is before the model update already treated as 1 and the value of "a" become n*Big_M, as if the binary variable doesn´t play any roll.
I´ve changed the value of the Big_M to an enough small value like 10 and the Binary variable is still ignored.
How can i fix this issue? Thank you in advance!
Zheren
-
Hi Zheren,
It's not quite clear to me what you mean by the value of "a".
Consider the following minimum reproducible example
import guropbipy
m = gp.Model()
n=1
M=5
x = m.addVar(vtype=gp.GRB.BINARY)
a = n*M*(1-x)
In this case the variable "a" is assigned a linear expression>> type(a)
gurobipy.LinExprand
>> a.getValue()
AttributeError: Index out of range for attribute 'X'fails because we have not optimized and found a solution.
So when you say that "a", or any variable or expression in the model, has a value (prior to model update, and more importantly model optimization) it is not clear what you are referring to.
Are you able to elaborate more, and use the code above to explain what you mean?
Thanks
- Riley
0 -
Hi Riley
Thank you for the reply and sorry for my unclear discription. In this case the variable "a" is an gurobipy linear expression which is a sum that every summand of it is expected to contain a gurobi variable.
I´ve inspected my code once more and I realize that the gurobi variable x of this linear expression is not ignored, just the constant term (n*M) is pushed to the beginning of the expression and the term -n*m*x is at the last position. There must be other wrong implementations that make my code not work as expected.
Sorry for taking your time because of my carelessness.
Best regards
Zheren
0 -
Hi Zheren,
No need to apologize, it's all part of learning, and happens to the best of us :)
- Riley
0
Please sign in to leave a comment.
Comments
3 comments