lemon-project-template-glpk

view deps/glpk/examples/sql/transp_odbc.mod @ 9:33de93886c88

Import GLPK 4.47
author Alpar Juttner <alpar@cs.elte.hu>
date Sun, 06 Nov 2011 20:59:10 +0100
parents
children
line source
1 # A TRANSPORTATION PROBLEM
2 #
3 # This problem finds a least cost shipping schedule that meets
4 # requirements at markets and supplies at factories.
5 #
6 # References:
7 # Dantzig G B, "Linear Programming and Extensions."
8 # Princeton University Press, Princeton, New Jersey, 1963,
9 # Chapter 3-3.
11 set I;
12 /* canning plants */
14 param a{i in I};
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'
20 'FROM transp_capa' :
21 I <- [ PLANT ], a ~ CAPACITY;
23 set J;
24 /* markets */
26 param b{j in J};
27 /* demand at market j in cases */
29 table markets IN "iODBC"
30 'DSN=glpk;UID=glpk;PWD=gnu'
31 'transp_demand' :
32 J <- [ MARKET ], b ~ DEMAND;
34 param d{i in I, j in J};
35 /* distance in thousands of miles */
37 table dist IN "iODBC"
38 'DSN=glpk;UID=glpk;PWD=gnu'
39 'transp_dist' :
40 [ LOC1, LOC2 ], d ~ DIST;
42 param f;
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 */
60 solve;
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;
68 data;
70 param f := 90;
72 end;