AMPL Formulation
The formulation of the transportation problem is AMPL is a straighforward translation of the matehmatical programme for the transportation problem.
The sets and are declared as SUPPLY_NODES and DEMAND_NODES respectively:
set SUPPLY_NODES;
set DEMAND_NODES;
The supply and demand are declared as integer parameters:
param Supply {SUPPLY_NODES} >= 0, integer;
param Demand {DEMAND_NODES} >= 0, integer;
The cost is declared over the SUPPLY_NODES and DEMAND_NODES :
param Cost {SUPPLY_NODES, DEMAND_NODES};
Now, the mathematical proramme follows directly:
var Flow {i in SUPPLY_NODES, j in DEMAND_NODES} >= 0, integer;
minimize TotalCost:
sum {i in SUPPLY_NODES, j in DEMAND_NODES} Cost[i, j] * Flow[i, j];
subject to UseSupply {i in SUPPLY_NODES}:
sum {j in DEMAND_NODES} Flow[i, j] = Supply[i];
subject to MeetDemand {j in DEMAND_NODES}:
sum {i in SUPPLY_NODES} Flow[i, j] = Demand[j];
Note that we assume the transportation is balanced. |