lemon-project-template-glpk
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ac547f327617 |
---|---|
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. | |
10 | |
11 set I; | |
12 /* canning plants */ | |
13 | |
14 param a{i in I}; | |
15 /* capacity of plant i in cases */ | |
16 | |
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; | |
21 | |
22 set J; | |
23 /* markets */ | |
24 | |
25 param b{j in J}; | |
26 /* demand at market j in cases */ | |
27 | |
28 table markets IN "MySQL" | |
29 'Database=glpk;UID=glpk;PWD=gnu' | |
30 'transp_demand' : | |
31 J <- [ MARKET ], b ~ DEMAND; | |
32 | |
33 param d{i in I, j in J}; | |
34 /* distance in thousands of miles */ | |
35 | |
36 table dist IN "MySQL" | |
37 'Database=glpk;UID=glpk;PWD=gnu' | |
38 'transp_dist' : | |
39 [ LOC1, LOC2 ], d ~ DIST; | |
40 | |
41 param f; | |
42 /* freight in dollars per case per thousand miles */ | |
43 | |
44 param c{i in I, j in J} := f * d[i,j] / 1000; | |
45 /* transport cost in thousands of dollars per case */ | |
46 | |
47 var x{i in I, j in J} >= 0; | |
48 /* shipment quantities in cases */ | |
49 | |
50 minimize cost: sum{i in I, j in J} c[i,j] * x[i,j]; | |
51 /* total transportation costs in thousands of dollars */ | |
52 | |
53 s.t. supply{i in I}: sum{j in J} x[i,j] <= a[i]; | |
54 /* observe supply limit at plant i */ | |
55 | |
56 s.t. demand{j in J}: sum{i in I} x[i,j] >= b[j]; | |
57 /* satisfy demand at market j */ | |
58 | |
59 solve; | |
60 | |
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; | |
66 | |
67 data; | |
68 | |
69 param f := 90; | |
70 | |
71 end; |