4 r8 P z# P% v8 s! X$ `5 ? 4 |/ U* e* [' x* }" O6 M( o" b# S. p. c
3 Z9 U0 W1 K: b; k0 I* y' V; }1 ~! A# f, m; u6 E
7 G( K+ O2 K: u! ]
第一章,基本概况 3 A! @/ D6 A/ t* o L) \/ P/ E7 z. a" ~3 r2 {$ OGAMS是一种非常简单易学的运筹学建模语言 (www.gams.com),是由WORLD BANK 开发的。由于近几十年计算机软硬件的的高速发展,世界银行决定投资开发GAMS, 来提供:9 M+ }+ g& z4 D
1. 建立复杂模型的高级语言 - o' D; u2 E- Z R" I r4 T2. 简单易学 4 I0 T: s0 l4 t |7 Z3. 强大的描述代数及逻辑关系 h& B7 j6 L8 u# J3 f1 G d9 M
4. 模型可以独立于算法系统" U3 g; Q) I8 _- X' ]$ M5 I) a7 y
GAMS 可以让使用者专心致力于模型的建立而省略了解法方面的考虑因为GAMS包含了解决通用的LP,NLP,MILP,MINLP等各类模型所需要的solver. 另外,GAMS提供了和外界进行交互的输入输出借口。使得用户很方便的导入导出data。 2 T j' k! S; d b下面当然是tutorial了,就想学习任何一种编程语言一样,最开始都要学习输出 hello world. 我们这里当然要复杂一点了,举一个最简单的例子,运输问题.( X+ q2 Z! y( q9 |6 |& o7 s# h
这是一个经典的LP问题(不用解释什么是LP吧,呵呵)0 I6 {1 @0 x! r8 z5 h+ W1 u
用点英语,呵呵, / A( b6 p1 p- @8 JIn 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? 6 \1 W& Z b; h% |, v1 a$ ?# z就是说,我们已知有一些工厂,生产出的产品要运往一些市场来满足他们的需求,每一个工厂的生产能力(每个工厂能提供产品的数量)以及每个市场的需求(每个市场需要产品的数量)是已知的。另外,我们还知道从特定的工厂到特定的市场,运输一件产品的运费。那么我们怎么样设计从每个工厂到每个市场运送货物的数量,使得总运费最小?( P/ U* c9 k' S; a" i7 e- M
Indices:; Y7 s) A. _$ ?/ Y: }$ Q
i = plants " @/ W V8 x0 f3 [. d! X: F5 p! {j = markets ) z H1 V5 S0 B" ?Given Data: / d, Y# U# Z0 C% ^. _ai = supply of commodity of plant i (in cases)7 a6 x* b1 r5 a
bj = demand for commodity at market j (cases)! N3 { P8 i% X% A4 R, j5 W+ m) K
cij = cost per unit shipment between plant i and market j ($/case)# x8 g% x7 |& P/ C3 f1 i
Decision Variables:4 a8 P! d3 d: z6 v8 c' Q
Xij = amount of commodity to ship from plant i to market j8 L1 W" r& b. i7 H; T- @3 j
在这里唯一的连续变量是Xi,j,% V. T2 I/ d- l1 b
模型就不用我说了吧。。。。$ Z E( q0 j+ m; m* p
9 O, ]# G1 a' b; g# X+ ]
这是一个典型的线性规划问题,他的GAMS code is 1 R) W8 |6 h7 I, T9 B5 n6 w$ w9 z2 Z: B5 n8 L
Sets " g5 G4 E' q9 {i canning plants / seattle, san-diego / : D$ H. b; {8 k' ej markets / new-york, chicago, topeka / ; - Q/ r n' ^# S6 i$ m( ?Parameters) Y) f" ~' W1 B8 e j) `
a(i) capacity of plant i in cases . G5 X: k& \ ~0 q% z4 C" I2 B; C; K/ seattle 350/ M9 w9 B: T' `. I0 G. ~4 y8 ~
san-diego 600 / 5 I* p/ A' J' |9 ^8 L0 [b(j) demand at market j in cases $ I G% O/ V0 M) v; }+ t/ new-york 325 ' k( ? u* V4 M9 j9 J% zchicago 300 4 w0 M7 w- F. d @1 H% B r" ]5 e: vtopeka 275 / ; # h+ w3 G1 P2 y- e2 o8 S* L' I4 YTable d(i,j) distance in thousands of miles5 [0 c) j1 w$ `/ f- I* p y
new-york chicago topeka & B, M, @) k/ n8 l4 v, T9 e1 Eseattle 2.5 1.7 1.8 ; J& f) z$ }, L: J3 h( nsan-diego 2.5 1.8 1.4 ; ! O$ d( V5 i# `9 pScalar f freight in dollars per case per thousand miles /90/ ; 3 b- C" z0 p2 T# S* U8 M: uParameter c(i,j) transport cost in thousands of dollars per case ;+ e2 `! }+ c& t" u! \ D0 i3 l
c(i,j) = f * d(i,j) / 1000 ;' \3 \8 X3 p |
Variables : V% G# s5 c L% Q; l4 Jx(i,j) shipment quantities in cases ; c, ?5 v, H$ Y- n% hz total transportation costs in thousands of dollars ;/ L* R* r1 G' q b) }
Positive Variable x ; 1 M) d4 T8 B7 lEquations [0 C5 ~- \8 l- L# j/ `5 k0 _2 _
cost define objective function 4 T+ j: [- ]8 d* p& X `8 H( Nsupply(i) observe supply limit at plant i ) ?9 u6 v4 W5 G: D7 l idemand(j) satisfy demand at market j ; . |" T1 M$ J5 b& {9 [4 [cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;1 o& R, t$ Y/ A$ X' } r/ L4 [
supply(i) .. sum(j, x(i,j)) =l= a(i) ; , A4 [# L' ?1 K0 Q) a1 b% P6 ]6 X+ hdemand(j) .. sum(i, x(i,j)) =g= b(j) ;3 _2 U* f0 R$ R% [- f
Model transport /all/ ; ! _' f" |" U& g: i( |. R) SSolve transport using lp minimizing z ; $ S. d C8 Z3 l. H% c5 \Display x.l, x.m ;5 h( c6 M+ t) \0 x
这是一个非常典型的LP(linear programming)问题,所有的变量和约束都是线性相关的。