lemon-project-template-glpk
view deps/glpk/examples/sql/transp_mysql.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 "MySQL"
18 'Database=glpk;UID=glpk;PWD=gnu'
19 'SELECT PLANT, CAPA AS CAPACITY FROM transp_capa' :
20 I <- [ PLANT ], a ~ CAPACITY;
22 set J;
23 /* markets */
25 param b{j in J};
26 /* demand at market j in cases */
28 table markets IN "MySQL"
29 'Database=glpk;UID=glpk;PWD=gnu'
30 'transp_demand' :
31 J <- [ MARKET ], b ~ DEMAND;
33 param d{i in I, j in J};
34 /* distance in thousands of miles */
36 table dist IN "MySQL"
37 'Database=glpk;UID=glpk;PWD=gnu'
38 'transp_dist' :
39 [ LOC1, LOC2 ], d ~ DIST;
41 param f;
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 */
59 solve;
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;
67 data;
69 param f := 90;
71 end;