I am new to AMPL and trying to make a simple model of MC problem, but I have so many errors and I can't understand how to solve them. I have attached bellow my model with a data in it. Maybe someone can please help to understand what is wrong?
set NODES; #diefine set of nodes
set ARCS within {NODES, NODES};
set COMMODITIES {NODES};
param quantity{COMMODITIES};
param origin{COMMODITIES};
param dest{COMMODITIES};
param cap{ARCS} >= 0;
param cost{ARCS} >= 0;
# Decision Variables
var x{(u,v,k) in ARCS cross COMMODITIES} binary; #flow assos with commodity k on the acrs
# Objective Function
minimize Total_Cost:
sum {(u,v) in ARCS, k in COMMODITIES}
cost [u,v] *x[u,v,k];
# Capacity constraints
subject to c1 {(u,v) in ARCS}:
sum{(u,v,k) in ARCS cross COMMODITIES}
x[u,v,k] <= cap[u,v];
#Flow conservation constraints
subject to c2 {u in NODES exept {orgin, dest}, k in COMMODITIES}:
sum{(v,u) in ARCS} x[v,u,k] - sum{(u,v) in ARCS} x[u,v,k] = 0;
# Source and sink constraints
subject to c5{k in COMMODITIES, v in NODES exept {orgin,dest}}:
sum{(u,v) in ARCS} x[u,v,k] - sum{(v,u) in ARCS} x[v,u,k] =
if v = orgin then +quantity[k] else if v = dest then -quantity[k] else 0;
# Non-negativity constraints
subject to c3 {(u,v,k) in ARCS cross COMMODITIES}:
x[u,v,k] >= 0;
data;
set NODES := 1 2 3 4 5 6;
param: ARCS: cap cost :=
1,2 15 3
2,3 1 6
3,4 6 3
4,1 6 8
2,4 10 4
2,5 10 4
5,6 10 4
5,3 4 12
3,6 7 8
4,6 8 10;
param COMMODITIES: orgin dest quantity :=
1 3 5 6
2 1 6 4
I have tried to define constrains separately, but it wouldn't help.
One error that is affecting most of the model is:
You declared
set COMMODITIES {NODES};which is an indexed set. In the model you seem to use it as a regular set, in which case you can just useset COMMODITIES;.Then in line 25, you have
subject to c2 {u in NODES exept {orgin, dest}, k in COMMODITIES}:. Instead you should haveu in NODES diff {orgin, dest}, but you also need to replaceorginanddestby the nodes since theyorginanddestare both declared as parameters. If you want to use theorigin[k]anddest[k](for each commodity k), then you can do that as follows:Fixing this and some typos you get the following model: