COIN-OR::LEMON - Graph Library

source: lemon-project-template-glpk/deps/glpk/examples/sql/transp_odbc.mod @ 9:33de93886c88

subpack-glpk
Last change on this file since 9:33de93886c88 was 9:33de93886c88, checked in by Alpar Juttner <alpar@…>, 13 years ago

Import GLPK 4.47

File size: 1.6 KB
RevLine 
[9]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 "iODBC"
18  'DSN=glpk;UID=glpk;PWD=gnu'
19  'SELECT PLANT, CAPA AS CAPACITY'
20  'FROM transp_capa' :
21   I <- [ PLANT ], a ~ CAPACITY;
22
23set J;
24/* markets */
25
26param b{j in J};
27/* demand at market j in cases */
28
29table markets IN "iODBC"
30  'DSN=glpk;UID=glpk;PWD=gnu'
31  'transp_demand' :
32  J <- [ MARKET ], b ~ DEMAND;
33
34param d{i in I, j in J};
35/* distance in thousands of miles */
36
37table dist IN "iODBC"
38  'DSN=glpk;UID=glpk;PWD=gnu'
39  'transp_dist' :
40  [ LOC1, LOC2 ], d ~ DIST;
41
42param f;
43/* freight in dollars per case per thousand miles */
44
45param c{i in I, j in J} := f * d[i,j] / 1000;
46/* transport cost in thousands of dollars per case */
47
48var x{i in I, j in J} >= 0;
49/* shipment quantities in cases */
50
51minimize cost: sum{i in I, j in J} c[i,j] * x[i,j];
52/* total transportation costs in thousands of dollars */
53
54s.t. supply{i in I}: sum{j in J} x[i,j] <= a[i];
55/* observe supply limit at plant i */
56
57s.t. demand{j in J}: sum{i in I} x[i,j] >= b[j];
58/* satisfy demand at market j */
59
60solve;
61
62table 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;
67
68data;
69
70param f := 90;
71
72end;
Note: See TracBrowser for help on using the repository browser.