Gurobi Python: Summation Constraint not being satisfied
In my MILP model there are 2 constraints that are related to each other and must be satisfied
knowing that;
o[i,j,k,t] is a binary variable that determine the selected temperature k at time period t when transferring products from plant i to retailer j (i.e when there's and arc between i and j)
x[i,j,q,k,t] is a continuous variable that determine the amount of products to be transferred from i to j with quality q at temperature k at period t
M is a large number
the first constrain is satisfied:
coded as:
for i,j in A:
for t in range(1-w_max, H):
m.addConstr(quicksum(O[i,j,k,t] for k in K ) <=1 , name="Constr 15" )
the solution is:
O(P1,R1,10,-1) 1.000000..................# means that there exist an arc between P1 and R1 at period
-1 and the selected temperature was 10
O(P1,R1,10,0) 1.000000
O(P1,R1,10,1) 1.000000
O(P1,R2,6,-2) 1.000000
O(P1,R2,8,-1) 1.000000
O(P1,R2,8,0) 1.000000
O(P1,R3,2,-2) 1.000000
O(P1,R3,2,0) 1.000000
O(P1,R3,6,-1) 1.000000
O(P1,R4,8,-1) 1.000000
O(P1,R4,8,1) 1.000000
O(P1,R4,10,0) 1.000000
that is fine, the problem occurs as follows;
there is another constraint for x[i,j,q,k,t] that states that there will be transferred products between i and j with different quality levels at a selected temperature k in period t that matches the solution that will be obtained from the previous constraint
coded as:
for i,j in A:
for k in K:
for t in trans_per(i,j) :
m.addConstr(quicksum(x[i,j,q,k,t] for q in Q if q in range ((q_imin[j]+int(DeltaqTR[i,j,k])),151- int(DeltaqTR[i,j,k])+1) ) <= M*O[i,j,k,t] , name="Constr 13" )
the solution obtained;
x(P1,R1,56,10,0) 14.000000
x(P1,R1,56,10,1) 105.000000
x(P1,R1,64,10,-1) 162.000000
x(P1,R1,65,10,0) 200.000000
x(P1,R1,79,10,1) 68.000000
x(P1,R1,83,10,0) 95.000000
x(P1,R1,96,10,0) 57.000000
x(P1,R1,145,10,0) 6.000000
x(P1,R2,64,8,-1) 24.000000
x(P1,R2,83,10,-1) 132.000000
x(P1,R2,91,10,-2) 14.000000 ....#this is an example on one of the conflicts, the solution obtained from the variable O was O(P1,R2,6,-2) 1.000000 that states that the selected temperature form arc P1 to R2 at period -2 will be 6, but as you see the selected temperature from variable x is 10!!!
x(P1,R2,96,10,0) 143.000000
x(P1,R2,145,10,-2) 145.000000
x(P1,R3,145,10,-2) 255.000000
x(P1,R3,145,10,0) 324.000000
x(P1,R3,147,10,-1) 428.000000
x(P1,R4,79,8,1) 54.000000
x(P1,R4,83,8,-1) 54.000000
x(P1,R4,121,10,1) 200.000000
x(P1,R4,145,10,0) 270.000000
x(P1,R4,147,10,-1) 172.000000
I don't know why this conflict happened?
Thanks in advance
Ragia
-
Official comment
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?. -
Maybe, this is due to numerical trouble. Can you tell us how large M is?
0 -
M is equal to 1525 (I don't know why exactly the author assumed this value)
0 -
Can you post an .lp or .mps file of your model?
One thing seems strange: In your first constraint, you interate t over range(1-w_max, H) and in the second constraint, you iterate t over trans_per(i,j). Is this the same?
0 -
Hi Thomas,
trans_per(i,j) is a subset of (1-w_max, H)
trans_per(i,j) is a list that contains the periods where transshipment will occur between i and j,
while (1-w_max, H) is a list that contains the whole planning horizonI've tried your suggestion to unify them but nothing had changed.
0
Post is closed for comments.
Comments
5 comments