rev |
line source |
alpar@9
|
1 # A TRANSPORTATION PROBLEM
|
alpar@9
|
2 #
|
alpar@9
|
3 # This problem finds a least cost shipping schedule that meets
|
alpar@9
|
4 # requirements at markets and supplies at factories.
|
alpar@9
|
5 #
|
alpar@9
|
6 # References:
|
alpar@9
|
7 # Dantzig G B, "Linear Programming and Extensions."
|
alpar@9
|
8 # Princeton University Press, Princeton, New Jersey, 1963,
|
alpar@9
|
9 # Chapter 3-3.
|
alpar@9
|
10
|
alpar@9
|
11 set I;
|
alpar@9
|
12 /* canning plants */
|
alpar@9
|
13
|
alpar@9
|
14 param a{i in I};
|
alpar@9
|
15 /* capacity of plant i in cases */
|
alpar@9
|
16
|
alpar@9
|
17 table plants IN "iODBC"
|
alpar@9
|
18 'DSN=glpk;UID=glpk;PWD=gnu'
|
alpar@9
|
19 'SELECT PLANT, CAPA AS CAPACITY'
|
alpar@9
|
20 'FROM transp_capa' :
|
alpar@9
|
21 I <- [ PLANT ], a ~ CAPACITY;
|
alpar@9
|
22
|
alpar@9
|
23 set J;
|
alpar@9
|
24 /* markets */
|
alpar@9
|
25
|
alpar@9
|
26 param b{j in J};
|
alpar@9
|
27 /* demand at market j in cases */
|
alpar@9
|
28
|
alpar@9
|
29 table markets IN "iODBC"
|
alpar@9
|
30 'DSN=glpk;UID=glpk;PWD=gnu'
|
alpar@9
|
31 'transp_demand' :
|
alpar@9
|
32 J <- [ MARKET ], b ~ DEMAND;
|
alpar@9
|
33
|
alpar@9
|
34 param d{i in I, j in J};
|
alpar@9
|
35 /* distance in thousands of miles */
|
alpar@9
|
36
|
alpar@9
|
37 table dist IN "iODBC"
|
alpar@9
|
38 'DSN=glpk;UID=glpk;PWD=gnu'
|
alpar@9
|
39 'transp_dist' :
|
alpar@9
|
40 [ LOC1, LOC2 ], d ~ DIST;
|
alpar@9
|
41
|
alpar@9
|
42 param f;
|
alpar@9
|
43 /* freight in dollars per case per thousand miles */
|
alpar@9
|
44
|
alpar@9
|
45 param c{i in I, j in J} := f * d[i,j] / 1000;
|
alpar@9
|
46 /* transport cost in thousands of dollars per case */
|
alpar@9
|
47
|
alpar@9
|
48 var x{i in I, j in J} >= 0;
|
alpar@9
|
49 /* shipment quantities in cases */
|
alpar@9
|
50
|
alpar@9
|
51 minimize cost: sum{i in I, j in J} c[i,j] * x[i,j];
|
alpar@9
|
52 /* total transportation costs in thousands of dollars */
|
alpar@9
|
53
|
alpar@9
|
54 s.t. supply{i in I}: sum{j in J} x[i,j] <= a[i];
|
alpar@9
|
55 /* observe supply limit at plant i */
|
alpar@9
|
56
|
alpar@9
|
57 s.t. demand{j in J}: sum{i in I} x[i,j] >= b[j];
|
alpar@9
|
58 /* satisfy demand at market j */
|
alpar@9
|
59
|
alpar@9
|
60 solve;
|
alpar@9
|
61
|
alpar@9
|
62 table result{i in I, j in J: x[i,j]} OUT "iODBC"
|
alpar@9
|
63 'DSN=glpk;UID=glpk;PWD=gnu'
|
alpar@9
|
64 'DELETE FROM transp_result;'
|
alpar@9
|
65 'INSERT INTO transp_result VALUES (?,?,?)' :
|
alpar@9
|
66 i ~ LOC1, j ~ LOC2, x[i,j] ~ QUANTITY;
|
alpar@9
|
67
|
alpar@9
|
68 data;
|
alpar@9
|
69
|
alpar@9
|
70 param f := 90;
|
alpar@9
|
71
|
alpar@9
|
72 end;
|