; G& [$ }# `* _' h3 pGAMS是一种非常简单易学的运筹学建模语言 (www.gams.com),是由WORLD BANK 开发的。由于近几十年计算机软硬件的的高速发展,世界银行决定投资开发GAMS, 来提供: 9 l+ a2 R5 C; q" e1 b& R1. 建立复杂模型的高级语言 ) I$ [* _5 d/ N, { G# N6 Z5 }2. 简单易学 x& ~8 Z0 F8 F- ?# L9 g
3. 强大的描述代数及逻辑关系 # ?& ^* n' O/ T3 B4. 模型可以独立于算法系统7 o* ?$ r2 X( I( z3 C+ W
GAMS 可以让使用者专心致力于模型的建立而省略了解法方面的考虑因为GAMS包含了解决通用的LP,NLP,MILP,MINLP等各类模型所需要的solver. 另外,GAMS提供了和外界进行交互的输入输出借口。使得用户很方便的导入导出data。 ; O/ ^8 R3 v' _3 R# H) k, ]下面当然是tutorial了,就想学习任何一种编程语言一样,最开始都要学习输出 hello world. 我们这里当然要复杂一点了,举一个最简单的例子,运输问题. - r9 p3 _1 d+ [% n4 y. d这是一个经典的LP问题(不用解释什么是LP吧,呵呵) $ k+ k8 E& @% x0 y/ f2 E用点英语,呵呵, 5 _2 s8 O9 A) U% V2 v) hIn 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? # L6 a3 }- B9 c. h就是说,我们已知有一些工厂,生产出的产品要运往一些市场来满足他们的需求,每一个工厂的生产能力(每个工厂能提供产品的数量)以及每个市场的需求(每个市场需要产品的数量)是已知的。另外,我们还知道从特定的工厂到特定的市场,运输一件产品的运费。那么我们怎么样设计从每个工厂到每个市场运送货物的数量,使得总运费最小? . ?1 W) D2 _ q- n8 G' ?3 RIndices: ! o2 H0 e1 Y' ri = plants 0 Y. ^1 N6 ^0 s- @/ Lj = markets 4 P3 G0 O e$ TGiven Data: e& t* V8 n' ]
ai = supply of commodity of plant i (in cases) # G( f9 r3 ^* L: f* vbj = demand for commodity at market j (cases) ) ~+ F0 }9 s; C- D, Ecij = cost per unit shipment between plant i and market j ($/case)% d5 ]2 m/ Y- ~$ G8 q0 I# n# V
Decision Variables: ) R, u' U. ?' hXij = amount of commodity to ship from plant i to market j & W8 Y" J- K: y% r! A" U在这里唯一的连续变量是Xi,j, 8 N/ i0 C' E1 I, y* H! Q模型就不用我说了吧。。。。1 V. E. }/ q. X8 T
3 r4 O- t! h! p! x7 J% l- l这是一个典型的线性规划问题,他的GAMS code is# K3 B; U* H' ?5 L8 G9 h; |
( V5 f; v! r$ `
Sets : {2 S+ a) o4 ?1 l4 ci canning plants / seattle, san-diego /3 \1 ?5 \. G5 h0 c6 g8 a
j markets / new-york, chicago, topeka / ;2 T' x' E2 R- z2 e+ S+ O9 H
Parameters " V" D& [/ r$ [a(i) capacity of plant i in cases 0 g: U' I5 X3 z8 L* V/ seattle 350( e2 F! \7 [) j( _7 W5 W
san-diego 600 /2 W: T2 J4 W7 d: H0 T8 f3 C' P9 n
b(j) demand at market j in cases 5 c1 x+ R$ D5 }, f/ new-york 325- I H) g- P8 ^3 a3 t5 j- Q! {
chicago 300 7 p4 _* n) Y/ i) z) _topeka 275 / ;4 R4 e1 ]1 N& q, c0 F! _
Table d(i,j) distance in thousands of miles1 W6 j. f- e! E
new-york chicago topeka 8 z7 A9 i+ e/ b$ Gseattle 2.5 1.7 1.8 & ?# Z7 _" z' F4 J6 z3 xsan-diego 2.5 1.8 1.4 ;$ W; B. X$ O9 Z. l4 h+ F& |% P: ^
Scalar f freight in dollars per case per thousand miles /90/ ;, u& \: g5 L' l7 G
Parameter c(i,j) transport cost in thousands of dollars per case ;1 |2 T5 K' |5 H% Z. v, }4 C
c(i,j) = f * d(i,j) / 1000 ; 6 K6 g+ [7 y: W) j5 jVariables0 e+ m9 q6 b8 h9 Y* E
x(i,j) shipment quantities in cases : J* N1 E" v" l) i+ dz total transportation costs in thousands of dollars ; 7 g$ S! T9 n$ J: W; \& }3 a {. YPositive Variable x ; 0 y Z0 f3 b' X0 P" YEquations 7 _7 N( G, `& A# Ecost define objective function + ]6 \6 y; i7 `, a; U( @supply(i) observe supply limit at plant i" q7 ~) r0 Y9 j
demand(j) satisfy demand at market j ; " z8 P7 ~( O' H' Rcost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; ; p6 v1 J& s8 U$ @/ }( v1 ~supply(i) .. sum(j, x(i,j)) =l= a(i) ;& F* m8 [. _, Y
demand(j) .. sum(i, x(i,j)) =g= b(j) ;' Q# e0 ]# o+ @/ P* Q! O
Model transport /all/ ; ' G a# x, y0 h5 B1 `Solve transport using lp minimizing z ;" `9 K E# h; ~" b
Display x.l, x.m ; & W! {, ]4 q) S8 R这是一个非常典型的LP(linear programming)问题,所有的变量和约束都是线性相关的。