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

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
Please sign in to leave a comment.
Comments
3 comments