メインコンテンツへスキップ

Infeasible constraints: flow_1[110,310,110]

回答済み

コメント

5件のコメント

  • Riley Clement
    • Gurobi Staff

    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
  • Arsalan Modirkhazeni
    • Gurobi-versary
    • First Comment
    • First Question

    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
  • Riley Clement
    • Gurobi Staff

    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
  • Arsalan Modirkhazeni
    • Gurobi-versary
    • First Comment
    • First Question

    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
  • Riley Clement
    • Gurobi Staff

    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

サインインしてコメントを残してください。