List comprehension syntax in addGenConstrAnd type of constraints
回答済みHi,
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
-
正式なコメント
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 try Gurobot, our chatbot interface offering instant, expert-level support. -
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
投稿コメントは受け付けていません。
コメント
3件のコメント