Why does my AMPL code keep giving this error?

223 Views Asked by At

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.

1

There are 1 best solutions below

0
4er On

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.