Gurobi/python: infeasible model
回答済みI have a model m . I want to code the two constraints shown in the figure correctly.

- The different set of data are as follows:
```
R = [1,2,3,4]
K = [1,2]
P = [1,2,3,4]
D = [5,6,7,8]
PD = P + D
C = [10,11,12,13,14,15,16,17,18,19,20,21]
PDC = PD + C
Cr = {1: C[0:3], 2 : C[3:6],3: C[6:9], 4: C[9:12] }
O = [0,9]
N = O + P + D + C # all nodes
OC = O + C
# The parameter f:
fr={}
for r in R:
for i in N:
fr[r,i] = 1 if i in P else -1 if i in D else 0
# the variables
yr = m.addVars(R,N,N, vtype=GRB.BINARY)
z = m.addVars(((r,i,j) for r in R for i in Cr[r] for j in Cr[r]), vtype=GRB.BINARY, name='z')
print(z)
I want to know whether the next two constraints are programmed correctly
```
m.addConstrs((quicksum(yr[r,i,j] for j in N) +
quicksum(z [r,i,j] for j in Cr[r])-
quicksum(yr[r,j,i] for j in N )-
quicksum(z [r,j,i] for j in Cr[r]) == fr[r,i] for r in R for i in Cr[r] ),'6')
m.addConstrs((quicksum(yr[r,i,j] for j in N if j!=i)-
quicksum(yr[r,j,i] for j in N if j!=i)== fr[r,i] for r in R for i in N if i not in Cr[r] ),'7'')
```
when I run the code I get a message says infeasible model. When I used the
m.computeIIS()
m.write("irreducible.ilp")
I get about 25 constraints/bound problem, but I think the problem resides in the above two constraints because when I tried to formulate them with a different method I get the infeasibility message but with 2 constraints/bounds.
the other way I used as follows:
```
m.addConstrs((quicksum(yr[r,i,j] for j in N) +
quicksum(z [i,j] for j in Cr[r])-
quicksum(yr[r,j,i] for j in N )-
quicksum(z [j,i] for j in Cr[r]) == 0 for r in R for i in Cr[r] ),'6')
m.addConstrs((quicksum(yr[r,i,j] for j in N if j!=i)-
quicksum(yr[r,j,i] for j in N if j!=i)== 1 for r in R for i in P ),'7-')
m.addConstrs((quicksum(yr[r,i,j] for j in N if j!=i)-
quicksum(yr[r,j,i] for j in N if j!=i)== -1 for r in R for i in D),'7')
m.addConstrs((quicksum(yr[r,i,j] for j in N if j!=i)-
quicksum(yr[r,j,i] for j in N if j!=i)== 0 for r in R for i in OC if i not in Cr[r] ),'7+')
```
-
正式なコメント
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 Sabrin,
I would take a look at fr and print out if this dictionary looks like expected.
Best,
Sonja
0 -
Sonja, thanks a lot for your prompt reply. I have printed out the fr, constraint 6 and constraint 7. The output seems acceptable and the constraints correctly captured the required nodes. However, the code I wrote returns back an infeasible model message.
I really need urgent help!!!!!!!!!!!!!!!! please. I do not know why the model is infeasible and what is wrong. I can share the whole code along with the model itself which is published in a reliable journal.
I feel it is a trivial issue that can be captured quickly if I shared the whole code, but it should not be publicly.
0 -
Hi Sabrin,
From this post it seems you got it working now. Can you share what you did for solving it?
Thanks,
Sonja
0 -
Hi Sonja, the infeasibility was due unreasonable quantity of a particular parameter (input data). This is how I thought to catch the error: after employing m.computeIIS() and m.write("irreducible.ilp"), it has become clear for me the constraints contributing to the infeasibility. I revised and studied them carefully and with little logic and thinking I realized that the infeasibility was due unlogic quantity of a specific parameter.
Now the model is working but takes a too long time. To solve it faster, I am going to implement three different techniques ( arc elimination, subtour elimination, and variable substitution). These will be challenges that I should face, it is my first model to solve!!
Regards,
Sabreen
0
投稿コメントは受け付けていません。
コメント
5件のコメント