5 t2 v1 T* p; n+ { ) U) R" N% }6 h) w0 { # P0 `2 D" C7 O, j. ^ s第一章,基本概况 3 R& N: U, U0 z( |6 C |+ g+ N " [5 c0 x; V0 }9 r$ tGAMS是一种非常简单易学的运筹学建模语言 (www.gams.com),是由WORLD BANK 开发的。由于近几十年计算机软硬件的的高速发展,世界银行决定投资开发GAMS, 来提供:% j1 T+ D! O( T, z
1. 建立复杂模型的高级语言& ?, E% F! s( }, N' H
2. 简单易学* c/ g s% f* w0 G ^$ V
3. 强大的描述代数及逻辑关系 x3 }1 e8 m( r2 ?3 Z/ g
4. 模型可以独立于算法系统 7 z8 N/ R& O$ G: i5 uGAMS 可以让使用者专心致力于模型的建立而省略了解法方面的考虑因为GAMS包含了解决通用的LP,NLP,MILP,MINLP等各类模型所需要的solver. 另外,GAMS提供了和外界进行交互的输入输出借口。使得用户很方便的导入导出data。. t* {0 O- u C0 D0 j
下面当然是tutorial了,就想学习任何一种编程语言一样,最开始都要学习输出 hello world. 我们这里当然要复杂一点了,举一个最简单的例子,运输问题.% O# e7 `4 f8 H; r3 S' u+ ?
这是一个经典的LP问题(不用解释什么是LP吧,呵呵); A( W! S+ J/ b6 F: e; u
用点英语,呵呵, * F0 L- p0 Z g, s1 l9 w: \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? * ]& I M, Y8 v w% |" Y, h3 L就是说,我们已知有一些工厂,生产出的产品要运往一些市场来满足他们的需求,每一个工厂的生产能力(每个工厂能提供产品的数量)以及每个市场的需求(每个市场需要产品的数量)是已知的。另外,我们还知道从特定的工厂到特定的市场,运输一件产品的运费。那么我们怎么样设计从每个工厂到每个市场运送货物的数量,使得总运费最小? 7 h' c7 @- i1 R: t6 e8 J. h0 iIndices: " u4 x* r ?$ wi = plants" B; N e1 V$ R
j = markets 5 D5 e9 A! D$ q- ?Given Data: % p: F3 _) q& j0 o- P/ s9 R8 Sai = supply of commodity of plant i (in cases) + J, J x* i3 l- rbj = demand for commodity at market j (cases) 6 ]! l* E# P) L3 d. g7 h) Q# F% Tcij = cost per unit shipment between plant i and market j ($/case)$ v* ~- r4 Z9 f4 e- e$ L
Decision Variables: ! y$ @6 I3 X% Q1 x; B, cXij = amount of commodity to ship from plant i to market j 0 X5 ^. T; F% H在这里唯一的连续变量是Xi,j, ) X# a0 f* T3 v& o% F模型就不用我说了吧。。。。 3 w, x( w! \8 p1 V . ]: G( E5 D; }% |/ y! W( @% [这是一个典型的线性规划问题,他的GAMS code is; F' W1 G( V/ {7 P2 \0 W
! v2 D8 ~$ y1 a$ F- CSets 4 w% e4 z$ `/ B# Y( d6 i: vi canning plants / seattle, san-diego / % m8 F3 O3 I( [2 M* { s* {j markets / new-york, chicago, topeka / ; / t2 [9 E/ }' B' ^: EParameters ! a5 N9 v. M& ~, N. C$ d6 fa(i) capacity of plant i in cases' _$ d2 Q! T8 B! y+ r& `
/ seattle 350$ o6 \7 D, V9 X0 l3 M% c
san-diego 600 / + I3 W) G) Y2 ?3 ?" Lb(j) demand at market j in cases; I( ]/ D. L; N& ?6 r
/ new-york 3256 M; m2 _8 b4 {3 {) a
chicago 300: R' ?' l% f( Y
topeka 275 / ; , a/ A6 V* T% `4 F* m5 CTable d(i,j) distance in thousands of miles) I- D% S/ u7 q2 i6 d9 Q" ?
new-york chicago topeka 6 V2 z# S( x, t1 Zseattle 2.5 1.7 1.8 % K. T$ ?7 p5 H% M1 C% b+ _' nsan-diego 2.5 1.8 1.4 ;0 R4 l' h' R4 |; F
Scalar f freight in dollars per case per thousand miles /90/ ; ; V4 B. @4 O9 j9 x" gParameter c(i,j) transport cost in thousands of dollars per case ;+ t6 l* l1 s9 @- M# i1 _
c(i,j) = f * d(i,j) / 1000 ;2 m4 m9 A9 U5 H2 S
Variables& t Z+ z$ r% _1 l! ]
x(i,j) shipment quantities in cases- m: C h9 J N$ s1 B6 J+ m
z total transportation costs in thousands of dollars ; 8 `: _! d/ G$ f8 |! ]Positive Variable x ; 4 S( M3 j" x& ^% Z- q3 e, wEquations2 S3 Z% _1 g3 H5 O! z- {6 w
cost define objective function; P. W2 Y I4 Z. ^3 W) D9 O- x
supply(i) observe supply limit at plant i 5 q& O! G% D) Z7 b1 h* M' Z1 _demand(j) satisfy demand at market j ; ; L" |: n* x/ K8 \9 b ~3 H) T9 Y9 Mcost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;8 p6 `6 f0 Q$ _6 z
supply(i) .. sum(j, x(i,j)) =l= a(i) ;% m) }- g8 p& W$ c9 k% k
demand(j) .. sum(i, x(i,j)) =g= b(j) ; # u2 w( X9 |5 f" IModel transport /all/ ;1 G$ V9 X2 x* ]% a5 `
Solve transport using lp minimizing z ; l/ o( _2 |* M. K$ S% K
Display x.l, x.m ;; C$ r- V, V# e3 x( C* N0 p
这是一个非常典型的LP(linear programming)问题,所有的变量和约束都是线性相关的。