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,
15 /* capacity of plant i in cases */
17 table plants IN "MySQL"
18 'Database=glpk;UID=glpk;PWD=gnu'
19 'SELECT PLANT, CAPA AS CAPACITY FROM transp_capa' :
20 I <- [ PLANT ], a ~ CAPACITY;
26 /* demand at market j in cases */
28 table markets IN "MySQL"
29 'Database=glpk;UID=glpk;PWD=gnu'
31 J <- [ MARKET ], b ~ DEMAND;
33 param d{i in I, j in J};
34 /* distance in thousands of miles */
37 'Database=glpk;UID=glpk;PWD=gnu'
39 [ LOC1, LOC2 ], d ~ DIST;
42 /* freight in dollars per case per thousand miles */
44 param c{i in I, j in J} := f * d[i,j] / 1000;
45 /* transport cost in thousands of dollars per case */
47 var x{i in I, j in J} >= 0;
48 /* shipment quantities in cases */
50 minimize cost: sum{i in I, j in J} c[i,j] * x[i,j];
51 /* total transportation costs in thousands of dollars */
53 s.t. supply{i in I}: sum{j in J} x[i,j] <= a[i];
54 /* observe supply limit at plant i */
56 s.t. demand{j in J}: sum{i in I} x[i,j] >= b[j];
57 /* satisfy demand at market j */
61 table result{i in I, j in J: x[i,j]} OUT "MySQL"
62 'Database=glpk;UID=glpk;PWD=gnu'
63 'DELETE FROM transp_result;'
64 'INSERT INTO transp_result VALUES (?,?,?)' :
65 i ~ LOC1, j ~ LOC2, x[i,j] ~ QUANTITY;