2 g( S0 Y. Z, ^ - d( X2 d, v% Z0 x( {9 H+ l/ ?7 b8 s" G
第一章,基本概况% i! j R. O' O/ a
* q/ ^2 k" e6 v d) r, B0 w' u3 l g
GAMS是一种非常简单易学的运筹学建模语言 (www.gams.com),是由WORLD BANK 开发的。由于近几十年计算机软硬件的的高速发展,世界银行决定投资开发GAMS, 来提供: - p9 _ \0 p4 @1. 建立复杂模型的高级语言 T8 l: g. e& b4 \4 x' k1 N1 d7 W
2. 简单易学 / C4 y" A1 y; X2 l/ e& s' U# l3. 强大的描述代数及逻辑关系 $ E; E" W8 ~ \5 j/ M; F4. 模型可以独立于算法系统 0 `- t/ u6 S0 J! A' p, vGAMS 可以让使用者专心致力于模型的建立而省略了解法方面的考虑因为GAMS包含了解决通用的LP,NLP,MILP,MINLP等各类模型所需要的solver. 另外,GAMS提供了和外界进行交互的输入输出借口。使得用户很方便的导入导出data。: }# K. i1 j, A
下面当然是tutorial了,就想学习任何一种编程语言一样,最开始都要学习输出 hello world. 我们这里当然要复杂一点了,举一个最简单的例子,运输问题.4 T! W. t. d* F: E% t
这是一个经典的LP问题(不用解释什么是LP吧,呵呵)& j! V* e- u1 O/ V( c
用点英语,呵呵, & `* K0 ~+ m: r! m; uIn 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?1 I f. ~3 I6 P9 F; J& M
就是说,我们已知有一些工厂,生产出的产品要运往一些市场来满足他们的需求,每一个工厂的生产能力(每个工厂能提供产品的数量)以及每个市场的需求(每个市场需要产品的数量)是已知的。另外,我们还知道从特定的工厂到特定的市场,运输一件产品的运费。那么我们怎么样设计从每个工厂到每个市场运送货物的数量,使得总运费最小? 0 y: A. f4 j& E$ WIndices:) ^& ^% Y8 m* o0 c
i = plants* L) F# C8 P) Z( Z' |6 Q
j = markets ! W$ @& U+ d+ c1 O5 sGiven Data: % N' F# V/ \- s pai = supply of commodity of plant i (in cases) ) m6 @* q& L( B2 Y: v& t+ C. X2 w. xbj = demand for commodity at market j (cases): O# |) f1 j% V& V& r
cij = cost per unit shipment between plant i and market j ($/case) + p+ `/ a4 z; t( D' {Decision Variables: . C1 l3 A2 p% L8 f3 lXij = amount of commodity to ship from plant i to market j0 g1 b# [" L- n) v: t/ b
在这里唯一的连续变量是Xi,j, & w) ` [7 f/ E* ?模型就不用我说了吧。。。。! L# l5 V" t+ S5 I9 d w( O" B: N
# b2 g k' O D. C这是一个典型的线性规划问题,他的GAMS code is m% M& k: u5 _* D( K
( H' O' G/ g/ M$ aSets . t. n, v5 u5 c7 `( B- [, li canning plants / seattle, san-diego /: B! H* f" F+ i% q7 ]& v* Y
j markets / new-york, chicago, topeka / ; ! v0 x9 |& _" [( mParameters; u! M+ p( v, h3 N
a(i) capacity of plant i in cases* b9 q. w3 r3 v3 n4 l* ^
/ seattle 3507 {* Q+ l6 S) y. Q( n
san-diego 600 /" N6 c. y8 d; ]/ X& \
b(j) demand at market j in cases / P8 w* a) b. W6 I# \7 S/ new-york 325 + i# w+ d2 i6 k& G) C r- ychicago 300' A* u; D; k% s: }/ q& Q. l( X
topeka 275 / ;/ b4 O0 w% P& C2 x4 I; p
Table d(i,j) distance in thousands of miles: s# Q$ E1 m5 K/ A0 H. z
new-york chicago topeka9 M7 t3 G4 u: X8 X2 n& A' h
seattle 2.5 1.7 1.8 - a& H0 _% `/ ^7 Jsan-diego 2.5 1.8 1.4 ; / Y4 ]" L" n6 cScalar f freight in dollars per case per thousand miles /90/ ; 0 ~& d6 H* m/ | Y$ S; Z( oParameter c(i,j) transport cost in thousands of dollars per case ; 8 O: r+ {' Y0 K, g- ]8 X% Nc(i,j) = f * d(i,j) / 1000 ; " n. d7 T; j- }4 g. c* w* ?" C' X m; y4 pVariables ) O+ g9 j' g5 V. a: ]' H% m" L( Cx(i,j) shipment quantities in cases; Y" M2 Z2 y, W& Q% w
z total transportation costs in thousands of dollars ; " x9 u, b6 } h+ ~7 D2 `. j: EPositive Variable x ;( m- Z) w+ Q/ i$ @+ K$ p: ^4 U
Equations5 x7 [; g$ B# n: e0 k2 ^& C. A
cost define objective function* ~# Q) e9 w) _2 v' Y6 j
supply(i) observe supply limit at plant i p0 }- T* q; }- t- vdemand(j) satisfy demand at market j ; r9 L9 s7 b4 s! h) d
cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;1 w7 b$ d, C8 N& D2 ?& p
supply(i) .. sum(j, x(i,j)) =l= a(i) ;, T5 K) ^5 Z2 `4 b. F
demand(j) .. sum(i, x(i,j)) =g= b(j) ; 6 i! e" @& O/ Q/ [7 u& ?* EModel transport /all/ ;' r0 b1 U. N) k0 |! [. G
Solve transport using lp minimizing z ; 0 J* Q9 b+ |- ^Display x.l, x.m ; , A% ]7 a; k% y; z/ O这是一个非常典型的LP(linear programming)问题,所有的变量和约束都是线性相关的。