Doubt regarding adding a constraint with difference of summations using quicksum
回答済みHey folks, firstly, thanks for taking the time to read the question, I am looking for some clarification on the ways to approach adding a constraint that involves the difference between summations.
so, this is the constraint I am trying to add to my model, the idea is to go through all i one at a time and make sure the difference between the summations of xij an xji over j is equal to zero, I added the constraint using the following line of code,
mdl.addConstrs(((quicksum(x[i,j] for j in I if j!=i)) - (quicksum(x[j,i] for j in I if j!=i)))==0for i in I);
I am just not sure if it's the right way to do it since I have a feeling that I might be iterating over j twice instead of being able to do that by iterating over j just once, can someone please help me figure out if I am doing this the right way? Thank you
1
-
正式なコメント
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,
You could write your constraint as
\[ \sum_j (x_{ij} - x_{ji}) =0 \quad \forall \, i \]
mdl.addConstrs( (quicksum(x[i,j] - x[j,i] for j in I if j!=i)) == 0 for i in I )
Best regards,
Jaromił1
投稿コメントは受け付けていません。
コメント
2件のコメント