9 b4 Y& g$ n0 \ - h) Z K2 a3 `! p5 E0 [ ) S5 `2 Y/ _+ D: E第一章,基本概况5 T8 |3 i- {: y1 `8 J9 e' U: }2 R
/ u# T! W5 g- I' @
GAMS是一种非常简单易学的运筹学建模语言 (www.gams.com),是由WORLD BANK 开发的。由于近几十年计算机软硬件的的高速发展,世界银行决定投资开发GAMS, 来提供:6 c1 y$ T0 f& {& p* `3 I ]
1. 建立复杂模型的高级语言& V7 ^/ I& ?) c$ P z+ ?% R
2. 简单易学 & B9 @# n2 w; O1 F/ e0 ]3. 强大的描述代数及逻辑关系 ! @: }0 f- {; x( f: R4 v% M4. 模型可以独立于算法系统5 a7 ]) ^8 ]: C4 u) y! J
GAMS 可以让使用者专心致力于模型的建立而省略了解法方面的考虑因为GAMS包含了解决通用的LP,NLP,MILP,MINLP等各类模型所需要的solver. 另外,GAMS提供了和外界进行交互的输入输出借口。使得用户很方便的导入导出data。 ( c$ \4 Q: w& ^3 i下面当然是tutorial了,就想学习任何一种编程语言一样,最开始都要学习输出 hello world. 我们这里当然要复杂一点了,举一个最简单的例子,运输问题. 3 Z! \: P: U$ ~& J0 |) k这是一个经典的LP问题(不用解释什么是LP吧,呵呵) ; M$ d3 M, _: `" ?8 G用点英语,呵呵, , t" G$ r% J2 V7 u4 NIn 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? 4 q0 d6 n N8 V( g9 g/ P1 N就是说,我们已知有一些工厂,生产出的产品要运往一些市场来满足他们的需求,每一个工厂的生产能力(每个工厂能提供产品的数量)以及每个市场的需求(每个市场需要产品的数量)是已知的。另外,我们还知道从特定的工厂到特定的市场,运输一件产品的运费。那么我们怎么样设计从每个工厂到每个市场运送货物的数量,使得总运费最小?& T+ W+ q7 S& [* J# `8 A
Indices:+ ]& P" z) Y4 M+ p
i = plants: {8 Q! F$ U8 @- m8 R- J
j = markets R5 J5 P) G' [1 @$ r9 VGiven Data: 1 ^% ^3 O4 |- N" u( i! Dai = supply of commodity of plant i (in cases) 0 z: l8 R/ O f$ {bj = demand for commodity at market j (cases) % G w& l3 W4 } B0 f3 A8 i. n& u' \cij = cost per unit shipment between plant i and market j ($/case) , o9 i0 ]) g# V# V' R8 {1 I: MDecision Variables:. D' e# N( q" m" n/ H$ n+ b+ p
Xij = amount of commodity to ship from plant i to market j. G& o9 `; c I0 o
在这里唯一的连续变量是Xi,j,/ T( \0 k/ ^ a. u
模型就不用我说了吧。。。。6 e$ r& @2 s. _& |
, e [2 ]9 Y7 L! u& v& v0 e
这是一个典型的线性规划问题,他的GAMS code is8 p9 A( n- J" c
5 v0 S }# t8 M3 j
Sets; v; G3 h3 k! B( z2 D) M
i canning plants / seattle, san-diego / 5 W2 Y O' {8 e0 A" Uj markets / new-york, chicago, topeka / ; * k) ^/ y* _; ]Parameters$ k3 x- c3 `) I" K% K
a(i) capacity of plant i in cases: r& n( {' W) q( l9 Y, \ b
/ seattle 350( r9 f( m/ o) E ~
san-diego 600 /3 d* m! r: ?; t
b(j) demand at market j in cases , L5 O, W. N: H/ x" u( C8 a' L. O/ new-york 3256 f; V5 u- I p4 w1 t) q7 S
chicago 300 * |- ?1 N3 F3 }5 i7 ktopeka 275 / ;4 _) ]: k6 L! a/ k0 k6 k
Table d(i,j) distance in thousands of miles. g" l) Z" I% v: l9 \# O
new-york chicago topeka + Z% _3 z' u" Aseattle 2.5 1.7 1.82 l2 z" u2 r, v' B2 @* W
san-diego 2.5 1.8 1.4 ;( e4 U' Y4 i0 A) }/ J
Scalar f freight in dollars per case per thousand miles /90/ ;: Q/ v" d$ W! L, t' V
Parameter c(i,j) transport cost in thousands of dollars per case ; ; m! `$ G% A8 g A$ F1 s& Dc(i,j) = f * d(i,j) / 1000 ;4 I6 K* j+ l6 y+ d1 E
Variables0 r/ _& t1 G! D. S- Z9 e8 T
x(i,j) shipment quantities in cases : {7 e2 x8 e4 ?+ H& lz total transportation costs in thousands of dollars ; : X6 i7 e; n8 n' fPositive Variable x ;8 D) X- J8 d0 s+ w
Equations5 m+ q K& C# Q f4 C( q: e0 F1 c
cost define objective function/ p# P% P; B t- w
supply(i) observe supply limit at plant i , B' Y; B* T: ~, [demand(j) satisfy demand at market j ; 9 Z( _5 {; V0 T& G4 O J5 Rcost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; - g2 x. D, q. f5 K+ S) Qsupply(i) .. sum(j, x(i,j)) =l= a(i) ;9 \# ^8 r G- f1 N8 m
demand(j) .. sum(i, x(i,j)) =g= b(j) ;" `6 b' B9 i: |
Model transport /all/ ; 9 c9 @$ a/ `& E# q; C2 gSolve transport using lp minimizing z ; @ W, b+ s% T3 x9 F( VDisplay x.l, x.m ;3 f% O* N/ E* r( H: R0 }
这是一个非常典型的LP(linear programming)问题,所有的变量和约束都是线性相关的。