Problems around general indicator constraints using MVar (& matrix multiplication operator)
AnsweredHi,
Do MVar objects compatible with general indicator constraints? I have problem with it. Where can I find an example..
Assume 'x', 'y' and 'z' are binaries.
Yij + Zjk + (Xpq - 1)M == 1
like the line below:
for ...:
m.addGenConstrIndicator(X[q, p], True, Y[i, j] + Z[j, k], GRB.EQUAL, 1)
For performance reason, I switched from successful but slow "term-based" constraint definition to matrix multiplication approach. I tried this version.
B y + C z + (A x - 1)M = 1
Then for such constraint I wrote below line:
m.addConstr(b @ y + c @ z + (a @ x - 1)*100000 == 1)
This is ok individually but in general I have infeasibility issues and I am sure about indices and matrices built for such calculation. So I preferred to switch to more logical version that might be helpful. [In this stage I am not sure about what is wrong with infeasibility of my model described with '@' method. All I doubt are linked to constraint definition that have Big-M notations, like the example provided]
m.addGenConstrIndicator(a @ x, True, b @ y + c @ z, GRB.EQUAL, 1)
But, then I get this error "Invalid lhs argument for general constraint of indicator type"
Or when I try this one
m.addConstr((a @ x == 1) >> (b @ y + c @ z == 1))
Then I get another error " 'MLinExpr' object has no attribute 'size' "
How to implement such constraint/What should I do generally?
Best regards
-
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 Amir,
Currently, MVar objects are not compatible with general constraints. You can use the tolist function and add the general constraints in a sequential fashion, e.g.,
x = m.addMVar(3, vtype=GRB.BINARY)
y = m.addMVar(3, vtype=GRB.BINARY)
z = m.addMVar(3, vtype=GRB.BINARY)
x_list = x.tolist()
y_list = y.tolist()
z_list = z.tolist()
for i in range(3):
m.addConstr((x_list[i] == 1) >> (y_list[i] + z_list[i] == 1))This behavior will very likely be improved in an upcoming release.
Best regards,
Jaromił0 -
Thank you so much for the guide.
Sincerely,
Amir
0
Post is closed for comments.
Comments
3 comments