How to model this kind of indicator constraint in Gurobipy?
Answeredx = binAssign.addVar(vtype=GRB.INTEGER, name='x')
y = binAssign.addVar(vtype=GRB.INTEGER, name='y')
z = binAssign.addVar(vtype=GRB.INTEGER, name='z')
a = 3
Model.addConstr((x >= 5) >> or_(z <= 2, y <= 3))
This code shows some errors for me. How should I write the constraint if I want to add
this kind of indicator constraint?
0
-
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,
You would need into basic parts the logic, for example:
let b1 b2 b3 be binary variables
m.addConstr((b1 == 1) >> (x>= 5))
m.addConstr((b1 == 0) >> (x <= 5))
m.addConstr((b2 == 1) >> (y <= 2))
m.addConstr((b3 == 1) >> (z <= 3))
m.addConstr(b1 = or_(b2,b3))
1 -
Small typo: m.addConstr( b1 == or_(b2,b3))
1 -
Thank you. This way is available. I am wondering if there are other efficient ways so that I don't need to creat so many variables.
0
Post is closed for comments.
Comments
4 comments