lemon-project-template-glpk
diff deps/glpk/examples/sql/transp_odbc.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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/deps/glpk/examples/sql/transp_odbc.mod Sun Nov 06 20:59:10 2011 +0100 1.3 @@ -0,0 +1,72 @@ 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 "iODBC" 1.21 + 'DSN=glpk;UID=glpk;PWD=gnu' 1.22 + 'SELECT PLANT, CAPA AS CAPACITY' 1.23 + 'FROM transp_capa' : 1.24 + I <- [ PLANT ], a ~ CAPACITY; 1.25 + 1.26 +set J; 1.27 +/* markets */ 1.28 + 1.29 +param b{j in J}; 1.30 +/* demand at market j in cases */ 1.31 + 1.32 +table markets IN "iODBC" 1.33 + 'DSN=glpk;UID=glpk;PWD=gnu' 1.34 + 'transp_demand' : 1.35 + J <- [ MARKET ], b ~ DEMAND; 1.36 + 1.37 +param d{i in I, j in J}; 1.38 +/* distance in thousands of miles */ 1.39 + 1.40 +table dist IN "iODBC" 1.41 + 'DSN=glpk;UID=glpk;PWD=gnu' 1.42 + 'transp_dist' : 1.43 + [ LOC1, LOC2 ], d ~ DIST; 1.44 + 1.45 +param f; 1.46 +/* freight in dollars per case per thousand miles */ 1.47 + 1.48 +param c{i in I, j in J} := f * d[i,j] / 1000; 1.49 +/* transport cost in thousands of dollars per case */ 1.50 + 1.51 +var x{i in I, j in J} >= 0; 1.52 +/* shipment quantities in cases */ 1.53 + 1.54 +minimize cost: sum{i in I, j in J} c[i,j] * x[i,j]; 1.55 +/* total transportation costs in thousands of dollars */ 1.56 + 1.57 +s.t. supply{i in I}: sum{j in J} x[i,j] <= a[i]; 1.58 +/* observe supply limit at plant i */ 1.59 + 1.60 +s.t. demand{j in J}: sum{i in I} x[i,j] >= b[j]; 1.61 +/* satisfy demand at market j */ 1.62 + 1.63 +solve; 1.64 + 1.65 +table result{i in I, j in J: x[i,j]} OUT "iODBC" 1.66 + 'DSN=glpk;UID=glpk;PWD=gnu' 1.67 + 'DELETE FROM transp_result;' 1.68 + 'INSERT INTO transp_result VALUES (?,?,?)' : 1.69 + i ~ LOC1, j ~ LOC2, x[i,j] ~ QUANTITY; 1.70 + 1.71 +data; 1.72 + 1.73 +param f := 90; 1.74 + 1.75 +end;