List comprehension syntax in addGenConstrAnd type of constraints
AnsweredHi,
I need to model a constraint which is like --> y is true if x is true and z[i] are true for i in lst_i.
What is the best way to model this constraint using gurobipy?
I am using 'addGenConstrAnd' construct within a for loop for every i in lst_i, but I am sure there exists an elegant way to model the list comprehension within addGenConstrAnd/ addGenConstrOr type of constraints. Any help is appreciated!
0
-
Hi Madhushini,You can first build the list of variables over which the AND concatenation will be taken and then use the Model.addGenConstrAnd() method.
vars = [x]
vars.extend([z_i for i in lst_i])
model.addGenConstrAnd(y, vars, name="and")Best regards,Maliheh0 -
Thank you, that works!
0
Please sign in to leave a comment.
Comments
2 comments