- Q/ F! W9 N& X0 Z" |6 |( `/ x% S A( U; f
第一章,基本概况 2 C5 d1 b/ x5 b$ U+ K. f. o& t7 m" Y! Y q. ~! O) [( S1 D
GAMS是一种非常简单易学的运筹学建模语言 (www.gams.com),是由WORLD BANK 开发的。由于近几十年计算机软硬件的的高速发展,世界银行决定投资开发GAMS, 来提供:% _: U( `- Y4 v* ^/ `/ N- Z+ Y
1. 建立复杂模型的高级语言 6 u( s( Q' O% j& B, p' a2. 简单易学8 M/ u- x8 P* a& v! X1 m
3. 强大的描述代数及逻辑关系: n0 Z! g5 q9 b% X1 @( A4 ]
4. 模型可以独立于算法系统 / S8 o9 t; L% z0 k: y z) p6 fGAMS 可以让使用者专心致力于模型的建立而省略了解法方面的考虑因为GAMS包含了解决通用的LP,NLP,MILP,MINLP等各类模型所需要的solver. 另外,GAMS提供了和外界进行交互的输入输出借口。使得用户很方便的导入导出data。 , h$ H2 B& |7 W% i/ w* l下面当然是tutorial了,就想学习任何一种编程语言一样,最开始都要学习输出 hello world. 我们这里当然要复杂一点了,举一个最简单的例子,运输问题.% Z1 a: z' x" G1 U# f' _' J6 W
这是一个经典的LP问题(不用解释什么是LP吧,呵呵) 2 e" ]* z' a7 z- Z9 s3 E6 ^用点英语,呵呵, - z6 H j% _8 `1 Z0 ^% {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? + c, K5 ]7 q# O就是说,我们已知有一些工厂,生产出的产品要运往一些市场来满足他们的需求,每一个工厂的生产能力(每个工厂能提供产品的数量)以及每个市场的需求(每个市场需要产品的数量)是已知的。另外,我们还知道从特定的工厂到特定的市场,运输一件产品的运费。那么我们怎么样设计从每个工厂到每个市场运送货物的数量,使得总运费最小? , p# l7 I' H$ |8 K% _- Y# ~Indices: 2 j A6 u+ \; {i = plants - O- S7 u' j' D5 p2 _" r7 ej = markets ( O& h* R$ u; l% VGiven Data:1 h" ]' G: S/ q' z$ C
ai = supply of commodity of plant i (in cases), S: O( U* R: l1 X6 r5 N
bj = demand for commodity at market j (cases) % x" i2 F9 S) L7 q* Gcij = cost per unit shipment between plant i and market j ($/case) 0 Q5 V9 _6 _2 A$ e$ u0 J- ?$ SDecision Variables:2 n9 }2 i7 Z* P
Xij = amount of commodity to ship from plant i to market j 7 Y8 O& {, c% y, h* i" H在这里唯一的连续变量是Xi,j,2 ~" D5 \9 w& C3 [& k
模型就不用我说了吧。。。。% x" u! V* } ]: p
2 |6 x8 ^, y3 j这是一个典型的线性规划问题,他的GAMS code is 3 V6 [: u' _: D8 g) \4 S : @/ J+ a; m. H& S3 R3 m! f* ]Sets 0 w3 h b& B1 H9 r0 ki canning plants / seattle, san-diego / * k( j# b% Z! h/ t/ Nj markets / new-york, chicago, topeka / ; 5 Z4 W% T) n" Q1 zParameters / `$ N0 r" q7 q9 Sa(i) capacity of plant i in cases 4 U8 C% A# o7 P( @) K" Y/ seattle 3501 b: t; I; ^% B- w2 v9 f
san-diego 600 /8 U$ L& G( f/ B. z8 }: G2 z$ j- U
b(j) demand at market j in cases0 q# n# S4 `6 k$ s7 l1 x
/ new-york 3253 S6 _5 b I* k. Y X
chicago 3001 w& K6 {- J3 d7 T% V5 ?8 h
topeka 275 / ;2 n2 y- V7 X& P+ M) `) p
Table d(i,j) distance in thousands of miles8 G, _+ ~- `9 K. z# D0 l
new-york chicago topeka: u( U9 z$ l6 Q) B
seattle 2.5 1.7 1.8 ) c0 e4 F, p- n: J5 T/ Csan-diego 2.5 1.8 1.4 ;' p1 A" N4 H3 M5 K
Scalar f freight in dollars per case per thousand miles /90/ ; / Z, q( P4 h9 _6 |Parameter c(i,j) transport cost in thousands of dollars per case ; + Z L, N! @' r/ Ac(i,j) = f * d(i,j) / 1000 ; . L; J' p' i/ x& G" \7 L$ F1 y, U/ wVariables 0 \. P9 [, t: U/ Y$ P& Z1 T6 cx(i,j) shipment quantities in cases 7 q* d9 j0 S' z& cz total transportation costs in thousands of dollars ; " T2 y3 N: w. a6 e$ R7 lPositive Variable x ;' s/ D- ]- L+ Z+ ], f8 c% E
Equations `- E" t- X' H8 rcost define objective function % z n- [) R$ C/ E+ e/ O* B6 Ksupply(i) observe supply limit at plant i 9 b$ W$ S* @. ~( h" K3 t6 Z2 wdemand(j) satisfy demand at market j ; : ~) z0 c* Z" ^8 l" zcost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;+ @; R2 A& z5 B6 H
supply(i) .. sum(j, x(i,j)) =l= a(i) ; * o0 P" U6 U+ g5 q6 Q1 Z% ddemand(j) .. sum(i, x(i,j)) =g= b(j) ;/ k' @4 a6 m: T. k1 b/ {. V
Model transport /all/ ;+ ~' Y' C6 |! m# K9 O
Solve transport using lp minimizing z ; 1 A8 ?4 u5 Y3 x) I1 R! A% ]Display x.l, x.m ;2 w! o+ x6 ` I! j9 a& S6 w9 i5 O
这是一个非常典型的LP(linear programming)问题,所有的变量和约束都是线性相关的。