, {4 U6 ]! D4 F |8 }$ W* Y) S- S5 n4 y! G1 I- P
6 X2 A- y+ ^; _# w6 l1 Z
0 M) ], a( F- w" b$ e! x第一章,基本概况 ' J) z' U2 l6 ]1 c3 P p3 [0 f6 N3 J# m
GAMS是一种非常简单易学的运筹学建模语言 (www.gams.com),是由WORLD BANK 开发的。由于近几十年计算机软硬件的的高速发展,世界银行决定投资开发GAMS, 来提供:+ |/ G7 D' c6 U
1. 建立复杂模型的高级语言4 v% j& A9 {- ]; l- M S: w2 X; J' G
2. 简单易学& g2 Q. f q; c z+ Z% ]
3. 强大的描述代数及逻辑关系 \' P/ x8 T) Z# z$ z5 H4. 模型可以独立于算法系统1 g' ?0 u! h: ^! @9 r$ W9 E
GAMS 可以让使用者专心致力于模型的建立而省略了解法方面的考虑因为GAMS包含了解决通用的LP,NLP,MILP,MINLP等各类模型所需要的solver. 另外,GAMS提供了和外界进行交互的输入输出借口。使得用户很方便的导入导出data。9 I8 M" g0 R2 t7 F
下面当然是tutorial了,就想学习任何一种编程语言一样,最开始都要学习输出 hello world. 我们这里当然要复杂一点了,举一个最简单的例子,运输问题.( p5 S# f) R5 Y7 R. i
这是一个经典的LP问题(不用解释什么是LP吧,呵呵) ( o- E5 T) F5 j0 J0 T* |, w% }用点英语,呵呵,, m+ j+ l5 `1 D
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? . l4 e# P5 n" F8 p就是说,我们已知有一些工厂,生产出的产品要运往一些市场来满足他们的需求,每一个工厂的生产能力(每个工厂能提供产品的数量)以及每个市场的需求(每个市场需要产品的数量)是已知的。另外,我们还知道从特定的工厂到特定的市场,运输一件产品的运费。那么我们怎么样设计从每个工厂到每个市场运送货物的数量,使得总运费最小?- Z! K( ] e. l( w, f
Indices: ) ]1 L/ d7 w Y8 ai = plants + Q) {1 Z4 k( x) [& E$ wj = markets % V0 F# T( `. u9 ]. m0 hGiven Data: 1 F, f; r$ T8 A6 P" {3 lai = supply of commodity of plant i (in cases) $ ^9 T* j" Y3 l$ G3 e! J: t6 j6 r8 `/ Xbj = demand for commodity at market j (cases)( |7 H+ X6 J# W
cij = cost per unit shipment between plant i and market j ($/case)$ d8 D9 e) w2 W
Decision Variables: + i; r# w( i: m0 nXij = amount of commodity to ship from plant i to market j p' ~: F6 O2 `0 @1 I
在这里唯一的连续变量是Xi,j, ; f/ Y) R4 J. B( \, k8 V+ P模型就不用我说了吧。。。。 5 y! A% g3 \! N1 l* E! N; k8 f$ L( { 6 i! W, e. W3 R0 \! S这是一个典型的线性规划问题,他的GAMS code is $ H3 y* W9 Z9 n9 i* D9 J( t8 ], N- L- K
Sets5 l) l4 }5 ]# C0 s' L: N% Q
i canning plants / seattle, san-diego / / T- _9 o2 M9 L Lj markets / new-york, chicago, topeka / ;9 Q1 ?( ~! |. Q6 H# [
Parameters2 ?8 u( Q d3 r0 B
a(i) capacity of plant i in cases3 w" V3 j0 P8 }# r o' z* ~
/ seattle 350' }% t$ c8 c% K: i% f6 o5 h
san-diego 600 /. q! t# z- T2 s& Q6 O8 G
b(j) demand at market j in cases& h# C: e# P9 i9 H
/ new-york 325 # f8 L; H+ P! J+ y, D1 _chicago 300 1 M) J# [8 J; o# atopeka 275 / ;! B+ I* y+ ]! [. {# T* g
Table d(i,j) distance in thousands of miles" W$ r& O( w6 n* {
new-york chicago topeka% Y/ I- W: X$ w1 o' M
seattle 2.5 1.7 1.8; {' z+ {( x; t% O% u
san-diego 2.5 1.8 1.4 ;) F* o, _) \% l" Y7 C' G: ]
Scalar f freight in dollars per case per thousand miles /90/ ; # d+ R) I: F9 _! R6 `5 LParameter c(i,j) transport cost in thousands of dollars per case ;. P( t9 l- _9 h/ J- j
c(i,j) = f * d(i,j) / 1000 ; % M9 i7 i/ g H& N: C9 H+ I4 y6 [* _0 iVariables 5 N% Y$ [+ M7 v) f; W. a$ rx(i,j) shipment quantities in cases8 d: p2 o q- `, N7 h E$ T+ p
z total transportation costs in thousands of dollars ;( B, F1 I. U4 L0 @) f
Positive Variable x ; ! Y. N6 \% Y. f aEquations ' A! E. a! K& zcost define objective function5 E" Q9 h" y0 o. c2 a% L
supply(i) observe supply limit at plant i3 j6 k0 @* m5 | N
demand(j) satisfy demand at market j ;- Y5 t/ K7 ]* k
cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;/ l$ A: H C9 m
supply(i) .. sum(j, x(i,j)) =l= a(i) ;0 }6 F G% H! J7 {3 V/ {
demand(j) .. sum(i, x(i,j)) =g= b(j) ; ; b. G. L( H: s+ V# dModel transport /all/ ; ' W: P% M+ w& h) Z8 \) h9 H' cSolve transport using lp minimizing z ; * h( {" x* e. h3 z" N/ I) w) S( QDisplay x.l, x.m ;7 P- E4 n# m# O1 L
这是一个非常典型的LP(linear programming)问题,所有的变量和约束都是线性相关的。