% p3 Y6 G4 N5 R6 J- E4 `+ V 1 ^# S m V+ m2 X! r' C$ [: P. a \) f& A& M
; w$ i* `7 `$ S& }' c( U9 i- i5 [5 S3 h2 @9 J5 J
第一章,基本概况 ) ]2 A; V9 [3 C, z5 t1 Q% s$ P; q' k, W5 J) P k
GAMS是一种非常简单易学的运筹学建模语言 (www.gams.com),是由WORLD BANK 开发的。由于近几十年计算机软硬件的的高速发展,世界银行决定投资开发GAMS, 来提供: & o/ B/ x- I# S. I/ h1 w( J1. 建立复杂模型的高级语言 : F. F6 [ b% r+ c% I" p* i* g2. 简单易学 + g2 u5 [+ {$ G$ Z! Y( ~. O3. 强大的描述代数及逻辑关系 ; d7 [, ~% A; a4. 模型可以独立于算法系统 : `" L8 f9 K# h# s: q0 s7 ~9 SGAMS 可以让使用者专心致力于模型的建立而省略了解法方面的考虑因为GAMS包含了解决通用的LP,NLP,MILP,MINLP等各类模型所需要的solver. 另外,GAMS提供了和外界进行交互的输入输出借口。使得用户很方便的导入导出data。 , E' Q0 `/ q9 k$ s6 p& ?下面当然是tutorial了,就想学习任何一种编程语言一样,最开始都要学习输出 hello world. 我们这里当然要复杂一点了,举一个最简单的例子,运输问题.0 D) m: L+ @5 \) g5 E+ ^
这是一个经典的LP问题(不用解释什么是LP吧,呵呵) 6 _( C# `* n# Y5 y( i用点英语,呵呵,6 J9 V! s- P+ u5 l, S
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? 7 x2 l+ \; k! f) A就是说,我们已知有一些工厂,生产出的产品要运往一些市场来满足他们的需求,每一个工厂的生产能力(每个工厂能提供产品的数量)以及每个市场的需求(每个市场需要产品的数量)是已知的。另外,我们还知道从特定的工厂到特定的市场,运输一件产品的运费。那么我们怎么样设计从每个工厂到每个市场运送货物的数量,使得总运费最小? % I# g7 F" S& j3 t5 M& ~/ O8 T1 ^Indices: * X+ Y5 C0 Z; J8 ~i = plants 1 S4 D' ~6 y3 `7 c5 Nj = markets+ x/ ^$ X5 g' k$ b0 d& v6 M: a
Given Data: , m7 }# ?" i/ g' O Z( n) U9 cai = supply of commodity of plant i (in cases)1 a3 l4 a T5 O$ w( U
bj = demand for commodity at market j (cases)1 r2 j1 l6 `; O8 y
cij = cost per unit shipment between plant i and market j ($/case) : P! q) R/ h; h+ t4 ]Decision Variables: 9 ~0 e, [! q& H' C* B" |- L+ M* t% `, RXij = amount of commodity to ship from plant i to market j 6 v0 q s5 L( ]! @在这里唯一的连续变量是Xi,j,% ~2 O; `8 m3 o. G
模型就不用我说了吧。。。。 3 h `: G% M! G' S 6 q" `: s4 _% d) t7 ~0 I8 A4 t这是一个典型的线性规划问题,他的GAMS code is/ V% q+ d! ^) ~7 L, C* M
, h$ F# D4 A$ s: M4 ?Sets4 I+ N4 z5 C9 ?% y& d- @
i canning plants / seattle, san-diego /. G- h' p' I) T/ a2 d
j markets / new-york, chicago, topeka / ;5 n) W0 F, y) q
Parameters. e6 E; K6 @) D6 v; r' E- a/ T
a(i) capacity of plant i in cases P$ b# ]: B5 A/ [0 s9 T! e$ u5 X. ^1 d
/ seattle 3507 `, F0 `, ~) o: z& f4 |) @( Y
san-diego 600 / , I* m7 [1 m8 V. B4 Vb(j) demand at market j in cases ' K& ^: V. Y5 b0 L$ c( m/ new-york 325: |2 ]; T$ H) W( |/ q
chicago 300 + c7 t5 W7 t/ Jtopeka 275 / ;9 C- y0 B( ]7 e9 [' G
Table d(i,j) distance in thousands of miles- o' ?2 y/ G% s6 y
new-york chicago topeka $ Y2 O3 L3 ^1 K0 M. w0 [seattle 2.5 1.7 1.8, [1 i3 a$ I6 a9 Y* p2 W' u; u
san-diego 2.5 1.8 1.4 ;' i4 g5 d2 ]1 z3 M5 I
Scalar f freight in dollars per case per thousand miles /90/ ;5 |3 A; b! }' K7 `5 z* g4 G
Parameter c(i,j) transport cost in thousands of dollars per case ; ^* k$ D. x: Oc(i,j) = f * d(i,j) / 1000 ; & k$ y$ ^, M/ A0 i. h6 ?1 Q- _' E3 DVariables # `: v1 ~* S+ L! }$ L+ Sx(i,j) shipment quantities in cases4 ]' t+ ] M! @* m
z total transportation costs in thousands of dollars ; % q" L: X F; N& y& }; dPositive Variable x ; 1 ]; K, F7 W Z" JEquations . |- @: I6 V3 g& J- F% icost define objective function+ v7 C' }; Z! e. M+ I
supply(i) observe supply limit at plant i 9 i) x" @( [4 C' ademand(j) satisfy demand at market j ; ) k" y( Q; E, ]: M* Xcost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;1 r4 T) X1 Z8 f2 F
supply(i) .. sum(j, x(i,j)) =l= a(i) ; % d9 f1 _6 T2 ~. Ydemand(j) .. sum(i, x(i,j)) =g= b(j) ; ' @% ^! a2 {! |2 iModel transport /all/ ;, `6 u; j9 z! I8 t V9 A
Solve transport using lp minimizing z ;. n2 R% ?+ m9 D# O, ~ T) @4 r4 d M
Display x.l, x.m ; % f9 r4 v* W- y+ j这是一个非常典型的LP(linear programming)问题,所有的变量和约束都是线性相关的。