为什么我的 AMPL 代码不断出现此错误?
我一直在尝试解决 AMPL 中的广义网络流问题,但我不断遇到此错误:
presolve: constraint flow_balance['c5'] cannot hold:
body >= 0 cannot be <= -2500; difference = 2500
presolve: constraint flow_balance['p1'] cannot hold:
body <= 0 cannot be >= 4500; difference = -4500
presolve: constraint flow_balance['c5'] cannot hold:
body >= 0 cannot be <= -5300; difference = 5300
presolve: constraint flow_balance['p1'] cannot hold:
body <= 0 cannot be >= 4800; difference = -4800```
reset;
option solver cplex;
set NODES; # nodes in the network
set ARCS within {NODES, NODES}; # arcs in the network
param b {NODES} default 0; # supply/demand for node i
param c {ARCS} default 0; # cost of one of flow on arc(i,j)
param l {ARCS} default 0; # lower bound on flow on arc(i,j)
param u {ARCS} default Infinity; # upper bound on flow on arc(i,j)
param mu {ARCS} default 1; # multiplier on arc(i,j) -- if one unit leaves i, mu[i,j] units arrive
var x {ARCS}; # flow on arc (i,j)
data Prob3.dat
maximize profit: sum{(i,j) in ARCS} c[i,j] * x[i,j]; #objective: maximize arc flow profit
# Flow Out(i) - Flow In(i) = b(i)
subject to flow_balance {i in NODES}: sum{j in NODES: (i,j) in ARCS} x[i,j] - sum{j in NODES: (j,i) in ARCS} mu[j,i] * x[j,i] = b[i];
subject to capacity {(i,j) in ARCS}: l[i,j] <= x[i,j] <= u[i,j];
#subject to demand {i in NODES}: sum{j in NODES: (j,i) in ARCS} mu[j,i] * x[j,i] - sum{j in NODES: (i,j) in ARCS} x[i,j] = b[i];
solve;
display profit;
display NODES;
display ARCS;
display x;
#note: default arc costs and lower bounds are 0
# default arc upper bounds are infinity
# default node requirements are 0
# default multiplier is 1
set NODES := p1 p2 p3 p4 #product time period nodes
r1 r2 r3 r4 #raw material time period nodes
c1 c2 c3 c4 c5 c5p; #cash flow time period nodes
set ARCS := (p1,p2) (p2,p3) (p3,p4) #inventory arcs
(r1,r2) (r2,r3) (r3,r4) #raw inventory arcs
(c1,c2) (c2,c3) (c3,c4) (c4,c5) #cash flow arcs
(c5,c5p) #virtual arc
(p1,c2) (p2,c3) (p3,c4) (p4,c5) #buy arcs final
(r1,c2) (r2,c3) (r3,c4) (r4,c5) #buy arcs raw
(c1,p2) (c2,p3) (c3,p4) #sell arcs final
(c1,r2) (c2,r3) (c3,r4); #sell arcs raw
param b:= p1 2000 #ending final product on-hand
p4 2000; #initial final product on-hand
#specify costs, upper bound, and multipliers for each arc
param: c u mu l:=
[p1, p2] 1.30 3000 0.94 . #holding cost, capacity, 1-spoilage rate
[p2, p3] 1.30 3000 0.94 .
[p3, p4] 1.30 3000 0.94 .
[c1, c2] . . . . #final product period carry over cost
[c2, c3] . . . .
[c3, c4] . . . .
[c4, c5] . . . .
[r1, r2] 11 7500 0.45 . #raw material conversion
[r2, r3] 11 9000 0.45 .
[r3, r4] 11 8500 0.45 .
[p1, c2] . 3000 38 2000 #final price
[p2, c3] . 3000 40 2500
[p3, c4] . 5000 42 2800
[p4, c5] . 5000 42 2500
[c1, p2] . . -0.02631579 . #1/final price
[c2, p3] . . -0.025 .
[c3, p4] . . -0.02380952 .
[r1, c2] . 7500 0.4 . #raw price
[r2, c3] . 9000 0.4 .
[r3, c4] . 8500 0.333 .
[r4, c5] . 9200 0.286 .
[c1, r2] . . -2.5 . #1/raw price
[c2, r3] . . -2.5 .
[c3, r4] . . -3.0 .
[c5, c5p] -1 . 0 .; #virtual arc has negative cost to incentavize flow
我已发布我的 dat 和 mod 文件以供参考。我知道这个错误是由于平衡限制造成的,但我不确定为什么。我尝试添加最小需求约束,但这似乎使一切变得更糟,我厌倦了多次重新设计网络流程图,但没有成功。如果有人能提供一些关于为什么我无法解决这个错误的见解,我将非常感激。
I have been trying to get my generalized network flow problem in AMPL but I keep running into this error:
presolve: constraint flow_balance['c5'] cannot hold:
body >= 0 cannot be <= -2500; difference = 2500
presolve: constraint flow_balance['p1'] cannot hold:
body <= 0 cannot be >= 4500; difference = -4500
presolve: constraint flow_balance['c5'] cannot hold:
body >= 0 cannot be <= -5300; difference = 5300
presolve: constraint flow_balance['p1'] cannot hold:
body <= 0 cannot be >= 4800; difference = -4800```
reset;
option solver cplex;
set NODES; # nodes in the network
set ARCS within {NODES, NODES}; # arcs in the network
param b {NODES} default 0; # supply/demand for node i
param c {ARCS} default 0; # cost of one of flow on arc(i,j)
param l {ARCS} default 0; # lower bound on flow on arc(i,j)
param u {ARCS} default Infinity; # upper bound on flow on arc(i,j)
param mu {ARCS} default 1; # multiplier on arc(i,j) -- if one unit leaves i, mu[i,j] units arrive
var x {ARCS}; # flow on arc (i,j)
data Prob3.dat
maximize profit: sum{(i,j) in ARCS} c[i,j] * x[i,j]; #objective: maximize arc flow profit
# Flow Out(i) - Flow In(i) = b(i)
subject to flow_balance {i in NODES}: sum{j in NODES: (i,j) in ARCS} x[i,j] - sum{j in NODES: (j,i) in ARCS} mu[j,i] * x[j,i] = b[i];
subject to capacity {(i,j) in ARCS}: l[i,j] <= x[i,j] <= u[i,j];
#subject to demand {i in NODES}: sum{j in NODES: (j,i) in ARCS} mu[j,i] * x[j,i] - sum{j in NODES: (i,j) in ARCS} x[i,j] = b[i];
solve;
display profit;
display NODES;
display ARCS;
display x;
#note: default arc costs and lower bounds are 0
# default arc upper bounds are infinity
# default node requirements are 0
# default multiplier is 1
set NODES := p1 p2 p3 p4 #product time period nodes
r1 r2 r3 r4 #raw material time period nodes
c1 c2 c3 c4 c5 c5p; #cash flow time period nodes
set ARCS := (p1,p2) (p2,p3) (p3,p4) #inventory arcs
(r1,r2) (r2,r3) (r3,r4) #raw inventory arcs
(c1,c2) (c2,c3) (c3,c4) (c4,c5) #cash flow arcs
(c5,c5p) #virtual arc
(p1,c2) (p2,c3) (p3,c4) (p4,c5) #buy arcs final
(r1,c2) (r2,c3) (r3,c4) (r4,c5) #buy arcs raw
(c1,p2) (c2,p3) (c3,p4) #sell arcs final
(c1,r2) (c2,r3) (c3,r4); #sell arcs raw
param b:= p1 2000 #ending final product on-hand
p4 2000; #initial final product on-hand
#specify costs, upper bound, and multipliers for each arc
param: c u mu l:=
[p1, p2] 1.30 3000 0.94 . #holding cost, capacity, 1-spoilage rate
[p2, p3] 1.30 3000 0.94 .
[p3, p4] 1.30 3000 0.94 .
[c1, c2] . . . . #final product period carry over cost
[c2, c3] . . . .
[c3, c4] . . . .
[c4, c5] . . . .
[r1, r2] 11 7500 0.45 . #raw material conversion
[r2, r3] 11 9000 0.45 .
[r3, r4] 11 8500 0.45 .
[p1, c2] . 3000 38 2000 #final price
[p2, c3] . 3000 40 2500
[p3, c4] . 5000 42 2800
[p4, c5] . 5000 42 2500
[c1, p2] . . -0.02631579 . #1/final price
[c2, p3] . . -0.025 .
[c3, p4] . . -0.02380952 .
[r1, c2] . 7500 0.4 . #raw price
[r2, c3] . 9000 0.4 .
[r3, c4] . 8500 0.333 .
[r4, c5] . 9200 0.286 .
[c1, r2] . . -2.5 . #1/raw price
[c2, r3] . . -2.5 .
[c3, r4] . . -3.0 .
[c5, c5p] -1 . 0 .; #virtual arc has negative cost to incentavize flow
I have posted my dat and mod files for reference. I know that the error is due somehow to the balance constraint but I am unsure why. I have tried to add min demand constraints but that seemed to make everything worse, I have tired redesigning the network flow chart multiple times and I've had no success. If anyone could provide some insight into why I can't figure this error out I would be extremely grateful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过这些消息,AMPL 的预求解阶段告诉您,您的问题没有可行的解决方案:无法将值分配给变量范围内且满足所有约束的变量。如需详细分析,请参阅 AMPL 用户论坛中对您的问题的回复。
With these messages, AMPL's presolve phase is telling you that your problem has no feasible solution: there is no way to assign values to the variables that are within the variables' bounds and that also satisfy all of the constraints. For a detailed analysis, see the reply to your question in the AMPL user forum.