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 "iODBC"
18 'DSN=glpk;UID=glpk;PWD=gnu'
19 'SELECT PLANT, CAPA AS CAPACITY'
21 I <- [ PLANT ], a ~ CAPACITY;
27 /* demand at market j in cases */
29 table markets IN "iODBC"
30 'DSN=glpk;UID=glpk;PWD=gnu'
32 J <- [ MARKET ], b ~ DEMAND;
34 param d{i in I, j in J};
35 /* distance in thousands of miles */
38 'DSN=glpk;UID=glpk;PWD=gnu'
40 [ LOC1, LOC2 ], d ~ DIST;
43 /* freight in dollars per case per thousand miles */
45 param c{i in I, j in J} := f * d[i,j] / 1000;
46 /* transport cost in thousands of dollars per case */
48 var x{i in I, j in J} >= 0;
49 /* shipment quantities in cases */
51 minimize cost: sum{i in I, j in J} c[i,j] * x[i,j];
52 /* total transportation costs in thousands of dollars */
54 s.t. supply{i in I}: sum{j in J} x[i,j] <= a[i];
55 /* observe supply limit at plant i */
57 s.t. demand{j in J}: sum{i in I} x[i,j] >= b[j];
58 /* satisfy demand at market j */
62 table result{i in I, j in J: x[i,j]} OUT "iODBC"
63 'DSN=glpk;UID=glpk;PWD=gnu'
64 'DELETE FROM transp_result;'
65 'INSERT INTO transp_result VALUES (?,?,?)' :
66 i ~ LOC1, j ~ LOC2, x[i,j] ~ QUANTITY;