1 # A TRANSPORTATION PROBLEM
3 # This problem finds a least cost shipping schedule that meets
4 # requirements at markets and supplies at factories.
7 # Dantzig G B, "Linear Programming and Extensions."
8 # Princeton University Press, Princeton, New Jersey, 1963,
18 /* transportation lane */
24 /* capacity of plant i in cases */
27 /* demand at market j in cases */
29 param d{i in I, j in J};
30 /* distance in thousands of miles */
36 /* freight in dollars per case per thousand miles */
38 table tab_plant IN "CSV" "plants.csv" :
39 I <- [plant], a ~ capacity;
41 table tab_market IN "CSV" "markets.csv" :
42 J <- [market], b ~ demand;
44 table tab_distance IN "CSV" "distances.csv" :
45 K <- [plant, market], d ~ distance;
47 table tab_parameter IN "CSV" "parameters.csv" :
48 L <- [parameter], e ~ value ;
50 param c{i in I, j in J} := e['transport cost'] * d[i,j] / 1000;
51 /* transport cost in thousands of dollars per case */
53 var x{(i,j) in K} >= 0;
54 /* shipment quantities in cases */
56 minimize cost: sum{(i,j) in K} c[i,j] * x[i,j];
57 /* total transportation costs in thousands of dollars */
59 s.t. supply{i in I}: sum{(i,j) in K} x[i,j] <= a[i];
60 /* observe supply limit at plant i */
62 s.t. demand{j in J}: sum{(i,j) in K} x[i,j] >= b[j];
63 /* satisfy demand at market j */
67 table tab_result{(i,j) in K} OUT "CSV" "result.csv" :
68 i ~ plant, j ~ market, x[i,j] ~ shipment;