How do I model if and only if statements in Gurobi
Answeredhii, I'm having trouble modeling if and only if statements. I modeled it like the code below
for i in range(I):
for j in range(J):
m.addConstr((h[j] + eps - M * ( 1 - b) <= g[i]), "bigM_constr1" )
m.addConstr((h[j] + M * b >= g[i]), "bigM_constr2" )
'''
m.addConstr((b==1) >> (x[i,j] == 1), "indicator_constr1")
m.addConstr((b==0) >> (x[i,j] == 0), "indicator_constr2")
'''
m.addGenConstrIndicator(b,True , x[i,j], GRB.EQUAL, 1.0)
Why when I run it there is an errorKey : (0.9) ?
Please help me
-
Hi Anggita,
We discuss how to debug a key error in the Knowledge Base article Tutorial: Preparing a Minimal Reproducible Example.
Best regards,
Jaromił0 -
Hi, I want to ask more. To describe conditional statements whether there are additional indicator limits besides this
m.addConstr((b == 1 ) >> (z == w1), name= "indicator_constr1" ) m.addConstr((b == 0 ) >> (z == w2), nama= "indicator_constr2" )
0 -
To describe conditional statements whether there are additional indicator limits besides this
Could you elaborate what exactly you mean by "additional indicator limits"?
Maybe the Knowledge Base article How do I model conditional statements in Gurobi? can help.
0
Please sign in to leave a comment.
Comments
3 comments