1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/sql/transp_mysql.mod Mon Dec 06 13:09:21 2010 +0100
1.3 @@ -0,0 +1,71 @@
1.4 +# A TRANSPORTATION PROBLEM
1.5 +#
1.6 +# This problem finds a least cost shipping schedule that meets
1.7 +# requirements at markets and supplies at factories.
1.8 +#
1.9 +# References:
1.10 +# Dantzig G B, "Linear Programming and Extensions."
1.11 +# Princeton University Press, Princeton, New Jersey, 1963,
1.12 +# Chapter 3-3.
1.13 +
1.14 +set I;
1.15 +/* canning plants */
1.16 +
1.17 +param a{i in I};
1.18 +/* capacity of plant i in cases */
1.19 +
1.20 +table plants IN "MySQL"
1.21 + 'Database=glpk;UID=glpk;PWD=gnu'
1.22 + 'SELECT PLANT, CAPA AS CAPACITY FROM transp_capa' :
1.23 + I <- [ PLANT ], a ~ CAPACITY;
1.24 +
1.25 +set J;
1.26 +/* markets */
1.27 +
1.28 +param b{j in J};
1.29 +/* demand at market j in cases */
1.30 +
1.31 +table markets IN "MySQL"
1.32 + 'Database=glpk;UID=glpk;PWD=gnu'
1.33 + 'transp_demand' :
1.34 + J <- [ MARKET ], b ~ DEMAND;
1.35 +
1.36 +param d{i in I, j in J};
1.37 +/* distance in thousands of miles */
1.38 +
1.39 +table dist IN "MySQL"
1.40 + 'Database=glpk;UID=glpk;PWD=gnu'
1.41 + 'transp_dist' :
1.42 + [ LOC1, LOC2 ], d ~ DIST;
1.43 +
1.44 +param f;
1.45 +/* freight in dollars per case per thousand miles */
1.46 +
1.47 +param c{i in I, j in J} := f * d[i,j] / 1000;
1.48 +/* transport cost in thousands of dollars per case */
1.49 +
1.50 +var x{i in I, j in J} >= 0;
1.51 +/* shipment quantities in cases */
1.52 +
1.53 +minimize cost: sum{i in I, j in J} c[i,j] * x[i,j];
1.54 +/* total transportation costs in thousands of dollars */
1.55 +
1.56 +s.t. supply{i in I}: sum{j in J} x[i,j] <= a[i];
1.57 +/* observe supply limit at plant i */
1.58 +
1.59 +s.t. demand{j in J}: sum{i in I} x[i,j] >= b[j];
1.60 +/* satisfy demand at market j */
1.61 +
1.62 +solve;
1.63 +
1.64 +table result{i in I, j in J: x[i,j]} OUT "MySQL"
1.65 + 'Database=glpk;UID=glpk;PWD=gnu'
1.66 + 'DELETE FROM transp_result;'
1.67 + 'INSERT INTO transp_result VALUES (?,?,?)' :
1.68 + i ~ LOC1, j ~ LOC2, x[i,j] ~ QUANTITY;
1.69 +
1.70 +data;
1.71 +
1.72 +param f := 90;
1.73 +
1.74 +end;