COIN-OR::LEMON - Graph Library

source: glpk-cmake/examples/sql/transp_mysql.mod

Last change on this file was 1:c445c931472f, checked in by Alpar Juttner <alpar@…>, 13 years ago

Import glpk-4.45

  • Generated files and doc/notes are removed
File size: 1.6 KB
Line 
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
11set I;
12/* canning plants */
13
14param a{i in I};
15/* capacity of plant i in cases */
16
17table 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
22set J;
23/* markets */
24
25param b{j in J};
26/* demand at market j in cases */
27
28table markets IN "MySQL"
29  'Database=glpk;UID=glpk;PWD=gnu'
30  'transp_demand' :
31  J <- [ MARKET ], b ~ DEMAND;
32
33param d{i in I, j in J};
34/* distance in thousands of miles */
35
36table dist IN "MySQL"
37  'Database=glpk;UID=glpk;PWD=gnu'
38  'transp_dist' :
39  [ LOC1, LOC2 ], d ~ DIST;
40
41param f;
42/* freight in dollars per case per thousand miles */
43
44param c{i in I, j in J} := f * d[i,j] / 1000;
45/* transport cost in thousands of dollars per case */
46
47var x{i in I, j in J} >= 0;
48/* shipment quantities in cases */
49
50minimize cost: sum{i in I, j in J} c[i,j] * x[i,j];
51/* total transportation costs in thousands of dollars */
52
53s.t. supply{i in I}: sum{j in J} x[i,j] <= a[i];
54/* observe supply limit at plant i */
55
56s.t. demand{j in J}: sum{i in I} x[i,j] >= b[j];
57/* satisfy demand at market j */
58
59solve;
60
61table 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
67data;
68
69param f := 90;
70
71end;
Note: See TracBrowser for help on using the repository browser.