: o- a: [& R* |5 p' W4 e( H0 T第一章,基本概况 * u( n, \" p9 W3 _! l- `2 ]! Q; i" ^2 o: W" g- x6 k
GAMS是一种非常简单易学的运筹学建模语言 (www.gams.com),是由WORLD BANK 开发的。由于近几十年计算机软硬件的的高速发展,世界银行决定投资开发GAMS, 来提供:% P1 r, `, m0 n- z0 s& J
1. 建立复杂模型的高级语言 + ?, b4 i. V8 B. k2. 简单易学% [$ k; ?8 z* j# s
3. 强大的描述代数及逻辑关系 9 u4 y* i) A3 s0 c' D4. 模型可以独立于算法系统+ A8 f7 `( t0 a/ y% I( c' B
GAMS 可以让使用者专心致力于模型的建立而省略了解法方面的考虑因为GAMS包含了解决通用的LP,NLP,MILP,MINLP等各类模型所需要的solver. 另外,GAMS提供了和外界进行交互的输入输出借口。使得用户很方便的导入导出data。 # i: \6 j5 k, g下面当然是tutorial了,就想学习任何一种编程语言一样,最开始都要学习输出 hello world. 我们这里当然要复杂一点了,举一个最简单的例子,运输问题.1 E& V. r7 s7 X4 d! d+ Q o
这是一个经典的LP问题(不用解释什么是LP吧,呵呵)8 c- U( H; U% w5 z( j: R
用点英语,呵呵,6 m G9 s* k- }$ r1 J/ L
In the familiar transportation problem, we are given the supplies at several plants and the demands at several markets for a single commodity, and we are given the unit costs of shipping the commodity from plants to markets. The economic question is: how much shipment should there be between each plant and each market so as to minimize total transport cost?' x# U3 m, R6 b1 O( z+ `1 o
就是说,我们已知有一些工厂,生产出的产品要运往一些市场来满足他们的需求,每一个工厂的生产能力(每个工厂能提供产品的数量)以及每个市场的需求(每个市场需要产品的数量)是已知的。另外,我们还知道从特定的工厂到特定的市场,运输一件产品的运费。那么我们怎么样设计从每个工厂到每个市场运送货物的数量,使得总运费最小?6 |: W% A' L" s8 u) Z
Indices: 8 f8 c" z1 h1 Wi = plants4 Y H; d' z1 t0 i5 Y
j = markets ! r. X4 K4 c4 U$ e; n# r4 {9 k' _Given Data:- W+ e7 v0 U0 b$ I
ai = supply of commodity of plant i (in cases); f2 T( `1 C, e
bj = demand for commodity at market j (cases)9 }; G, t# y- f
cij = cost per unit shipment between plant i and market j ($/case) K3 S" E4 R7 r4 t9 h7 B
Decision Variables: 5 ? k- q* C: nXij = amount of commodity to ship from plant i to market j * r2 ~( f9 `2 W3 ^9 U# t ]在这里唯一的连续变量是Xi,j,9 l" O/ S$ a$ s& h& `
模型就不用我说了吧。。。。. E; p. k% `* ^. t* R7 ]8 `. \
2 S! Y0 W5 g1 a J$ U2 M3 M: A这是一个典型的线性规划问题,他的GAMS code is 6 N. g( I% R4 q; Q c y4 k . O/ h) G' j. Z$ H/ ?9 rSets6 A3 v; h; O9 T2 w! t/ V9 d/ Q
i canning plants / seattle, san-diego /( r* F5 B# \7 X0 f$ D
j markets / new-york, chicago, topeka / ;( h I$ W1 W+ \1 c$ n
Parameters 1 y: e; G6 O4 B0 |a(i) capacity of plant i in cases , W( e- C; P, B3 t/ seattle 350( P& Z: x! C0 w
san-diego 600 / * S4 L% w) y$ F8 L! M0 [! F" D& `b(j) demand at market j in cases 9 T& C l: a% G( F( y/ new-york 325( p2 Y) B2 I9 ~5 v9 }* L
chicago 300 ! }/ E3 r4 ~9 z* b* ?% r1 y7 z }; {topeka 275 / ;$ x- a3 p+ j4 C& D# W
Table d(i,j) distance in thousands of miles% ]) g1 `7 Z G2 {
new-york chicago topeka ) D) O- l/ _1 wseattle 2.5 1.7 1.8 ' F* w& S) K. A. Q) H9 u) U1 osan-diego 2.5 1.8 1.4 ; % u C9 X' a4 E& j) DScalar f freight in dollars per case per thousand miles /90/ ;5 J+ z9 @4 c1 `( z
Parameter c(i,j) transport cost in thousands of dollars per case ; ) j4 T8 V1 ]$ v! M" Uc(i,j) = f * d(i,j) / 1000 ;5 n+ J$ _" U, {2 y. \
Variables - O* C. r( N! e- nx(i,j) shipment quantities in cases ( F7 `3 ~$ I8 c+ v, I3 Q' Ez total transportation costs in thousands of dollars ;7 V9 g. p) E" _& p8 S
Positive Variable x ; / ?4 T0 j" u( m* ~ h {Equations. S( v6 w: @" ^) X9 S1 o
cost define objective function9 L3 v" D3 m" v6 v9 {
supply(i) observe supply limit at plant i ' p5 R1 a& T$ t0 t, t6 g+ m6 tdemand(j) satisfy demand at market j ;/ S/ W6 O i+ a |- O! ^
cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; . [4 w7 l8 I. g5 X* |" Qsupply(i) .. sum(j, x(i,j)) =l= a(i) ; & Y4 k0 Z, H! c: Sdemand(j) .. sum(i, x(i,j)) =g= b(j) ; 4 b- y! G: Q" x0 DModel transport /all/ ;2 }$ T) i+ F+ m; ?( e& F
Solve transport using lp minimizing z ;/ {6 g- d6 m! Q# _' T3 l9 y) m
Display x.l, x.m ;) f% L$ w7 H9 z! E: g+ Q( o
这是一个非常典型的LP(linear programming)问题,所有的变量和约束都是线性相关的。