How to express if statement in constraints (Gurobi)
回答済みHi,
I have a question about expressing if statement in constraints.
The constraints that I want to add are Z[i,j]+Z[j,i] = 1 if i is not equal to j, where i and j are indices within a certain range.
How could I express this set of constraints in Gurobi?
Thank you so much for 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,
There are different ways of doing this. It depends a bit on how you are creating the constraints and which programming language you use. For example, if you are using Python and you are adding them one by one and if I and J are lists of your indices, you can do something like this:
for i in I:
for j in J:
if i != j:
add constraintIn Python, there are definitely other more elegant ways, one example could be using tuplelists and only add those indices to the tuplelist that you really need in your constraints. We show an example of this in our netflow.py example.
Best,
Sonja
1
投稿コメントは受け付けていません。
コメント
2件のコメント