Infeasible constraints: flow_1[110,310,110]
回答済みI want to implement the new constraint called solenoidality constraint in my Gurobi code and explain it in the following section:
set E within {N,N} := B union setof{(i,j) in B} (j,i);
set D within {N_L,N_L} := E_L union setof{(s,t) in E_L} (t,s);
s.t. flow_1 {(s,t) in D, i in N: i=s}:
sum{(i,j) in E} x[i,j,s,t] - sum{(j,i) in E} x[j,i,s,t] = pr[s,t];
I write the code in the Gurobi, as the following:
when I run this code, I got the following error:
Infeasible constraints: flow_1[110,310,110],
Is my code correct? how should I solve this problem, and how can I debug the following error, because in Cplex I have an answer for this constraint.
-
正式なコメント
This post is more than two 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 Arsalan,
I suspect the following is what your flow_1 constraints should be:
m.addConstrs((gp.quicksum(x[i,j,s,t] for (i,j) in E_new if i == s) - gp.quicksum(x[j,i,s,t] for (j,i) in E_new if i == s) == pr[s, t] for (s, t) in D_new), "flow_1")
- Riley
0 -
This is an ample version of the constraint which is like the following section:
s.t. flow_1 {(s,t) in D, i in N: i=s}:
sum{(i,j) in E} x[i,j,s,t] - sum{(j,i) in E} x[j,i,s,t] = pr[s,t];
s.t. flow_2 {(s,t) in D, i in N: i=t}:
sum{(i,j) in E} x[i,j,s,t] - sum{(j,i) in E} x[j,i,s,t] = -pr[s,t];
s.t. flow_3 {(s,t) in D, i in N: i<>s and i<>t}:
sum{(i,j) in E} x[i,j,s,t] - sum{(j,i) in E} x[j,i,s,t] = 0;
I implemented the following section code:
model.addConstrs((gp.quicksum(x[i,j,s,t] for (i,j) in E_0 if k == s) - gp.quicksum(x[j,i,s,t] for (j,i) in E_0 if k == s) == pr[s, t] for (s, t) in D_s_t for k in N ), "flow_1")
but it's the same error again could you define the better version?
0 -
Hi Arsalan,
From your first post:
s.t. flow_1 {(s,t) in D, i in N: i=s}:
sum{(i,j) in E} x[i,j,s,t] - sum{(j,i) in E} x[j,i,s,t] = pr[s,t];From your second post:
s.t. flow_1 {(s,t) in D, i in N: i=s}:
sum{(i,j) in E} x[i,j,s,t] - sum{(j,i) in E} x[j,i,s,t] = pr[s,t];It seems you have posted the same question.
- Riley
0 -
Dear Riley,
Thank you for your reply. I mean that in the following constraint:
s.t. flow_1 {(s,t) in D, i in N: i=s}: sum{(i,j) in E} x[i,j,s,t] - sum{(j,i) in E} x[j,i,s,t] = pr[s,t];should we consider the i in the set N, like this:
model.addConstrs((gp.quicksum(x[i,j,s,t] for (i,j) in E_new) - gp.quicksum(x[j,i,s,t] for (j,i) in E_new ) == pr[s, t] for (s, t) in D_new for i in N if i == s ), "flow_1")in your reply to the previous post, I did not find for loop for the i in the N set:
m.addConstrs((gp.quicksum(x[i,j,s,t] for (i,j) in E_new if i == s) - gp.quicksum(x[j,i,s,t] for (j,i) in E_new if i == s) == pr[s, t] for (s, t) in D_new), "flow_1")
0 -
Hi Arsalan,
You don't need a loop for i. The AMPL formulation is misleading, as the for loop i is just not necessary:
{(s,t) in D, i in N: i=s}As an simpler analogy, say N is the set of numbers 1 to 100, and consider the set
{i in N: i is even}This is the set of all numbers that are between 1 and 100, and are even. This is a perfectly reasonable way to represent this set. Now consider this set
{i in N: i = 42}This is the set of all numbers between 1 and 100, that are equal to 42. I.e. the set is {42}. This is essentially the same thing that is happening with "i in N: i=s". Hopefully this makes it clear why there is no loop over i needed. The AMPL constraint should ideally be written as
s.t. flow_1 {(s,t) in D}: sum{(i,j) in E: i = s} x[i,j,s,t] - sum{(j,i) in E: i = s} x[j,i,s,t] = pr[s,t];We write it like this using gurobipy:
m.addConstrs((gp.quicksum(x[i,j,s,t] for (i,j) in E_new if i == s) - gp.quicksum(x[j,i,s,t] for (j,i) in E_new if i == s) == pr[s, t] for (s, t) in D_new), "flow_1")
because we need to make sure that (s,j) belongs to E_new in the first quicksum and (j, s) belongs to E_new in the second quicksum. If you knew these conditions were always true then you could simplify further:
m.addConstrs((gp.quicksum(x[s,j,s,t] for j in N) - gp.quicksum(x[j,s,s,t] for j in N) == pr[s, t] for (s, t) in D_new), "flow_1")
- Riley
0
投稿コメントは受け付けていません。
コメント
6件のコメント