Adding constraints based on input flag in Python
回答済みHi all,
I have a question regarding the possibility to add constraints to models based on a boolean flag variable, which is not a Gurobi variable. The boolean flag in my case would be a parameter with a default value.
In short, I want to do something like:
def myFunc(arg1,..., some_flag=False):
model = gurobipy.Model()
...
if some_flag:
model.addConstr(< a constraint on some variable x >)
else:
model.addConstr(< another constraint on same variable x >)
Is this possible at all? Or should I model the constraints differently?
If it is possible, would there be performance benefits to this approach?
Thanks for your help! :)
-
正式なコメント
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 Elvi,
This is perfectly fine. You will simply end up with two different models depending on the value of the flag. Please note that this is not going to be dynamic in any way. If you change the flag and want to optimize the new model, you will also have to create a new model object.
Cheers,
Matthias1 -
Thank you for your quick reply. It's clear now.
Cheers,
Elvi0
投稿コメントは受け付けていません。
コメント
3件のコメント