I am new to AMPL and doing MC problem. I have included my code. I asked earlier to help with other errors, at this moment program is working, but optimal solution is 0 and giving a strange error. What can be a problem? Maybe my constraints are wrong?
Error:
Error executing "solve" command:
error processing constraint c2[1,1]:
invalid subscript flow[1,4,1]
Code:
set NODES; #define set of nodes
set ARCS within {NODES, NODES};
set COMMODITIES;
param demand {COMMODITIES};
param origin {COMMODITIES};
param dest {COMMODITIES};
param cap{ARCS} >= 0;
param cost{ARCS} >= 0;
# Decision Variables
var flow{(u,v,k) in ARCS cross COMMODITIES}; #flow assos with commodity k
var x{(u,v,k) in ARCS cross COMMODITIES} binary; #fraction of flow assos with commodity k
# Objective Function
minimize Total_Cost:
sum {(u,v) in ARCS, k in COMMODITIES}
cost [u,v] *(flow[u,v,k]*x[u,v,k]);
# Capacity constraints
subject to c1 {(u,v) in ARCS}:
sum{(u,v,k) in ARCS cross COMMODITIES}
(flow[u,v,k]*x[u,v,k]) <= cap[u,v];
#Flow conservation constraints
subject to c2 {k in COMMODITIES, u in NODES diff {origin[k], dest[k]}}:
sum{(v,u) in ARCS} (flow[u,v,k]*x[v,u,k]) - sum{(u,v) in ARCS} (flow[u,v,k]*x[u,v,k]) = 0;
# Source and sink constraints
subject to c3{k in COMMODITIES, u in NODES diff {origin[k],dest[k]}}:
sum{(u,v) in ARCS} flow[u,v,k] - sum{(v,u) in ARCS} flow[v,u,k] =
if u = origin[k] then demand[k] else if u = dest[k] then -demand[k] else 0;
# Commodity flow constraints
subject to c4 {(u,v,k) in ARCS cross COMMODITIES}:
flow[u,v,k] <= x[u,v,k] * cap[u,v];
# Non-negativity constraints
subject to c5 {(u,v,k) in ARCS cross COMMODITIES}:
x[u,v,k] >= 0;
data;
set NODES := 1 2 3 4 5 6;
param: ARCS: cost cap :=
1,2 3 15
2,3 6 1
4,1 8 6
2,5 4 10
2,4 4 10
3,4 3 6
3,6 8 7
5,3 12 4
4,6 10 8 ;
param: COMMODITIES: origin dest demand :=
1 3 5 6
2 1 6 4;
Program doesn't have an errors, but optimal solution is 0. I don't understand where is the problem, which constrains are wrong.