, _$ @, @- E* @9 _/ _. Z 3 w8 Y0 W3 ]& C , {* g2 V- Z, R, X 0 `, h0 b+ _4 v% Z 4 y$ H: R/ o9 c$ s第一章,基本概况+ G3 q3 d5 s# U9 f: z
b& r1 S" f0 z4 M6 a7 F, [
GAMS是一种非常简单易学的运筹学建模语言 (www.gams.com),是由WORLD BANK 开发的。由于近几十年计算机软硬件的的高速发展,世界银行决定投资开发GAMS, 来提供: ) o( @" q$ w3 {: y1. 建立复杂模型的高级语言 # {6 @, `$ R4 h" O4 H" h3 }* y2. 简单易学' e% L* D& }, M$ ]: O" w1 @; O
3. 强大的描述代数及逻辑关系3 `' y) ]4 L6 z8 v0 U$ F' W
4. 模型可以独立于算法系统 . d0 X) L& b' f/ C; `GAMS 可以让使用者专心致力于模型的建立而省略了解法方面的考虑因为GAMS包含了解决通用的LP,NLP,MILP,MINLP等各类模型所需要的solver. 另外,GAMS提供了和外界进行交互的输入输出借口。使得用户很方便的导入导出data。! N, p) V% U. Y% J
下面当然是tutorial了,就想学习任何一种编程语言一样,最开始都要学习输出 hello world. 我们这里当然要复杂一点了,举一个最简单的例子,运输问题. 9 d$ T* S2 e, w5 h# }; i这是一个经典的LP问题(不用解释什么是LP吧,呵呵)6 b0 J6 j5 ~% b: f8 `* } |
用点英语,呵呵,7 n6 B9 M1 G+ I4 v/ Y8 v6 |$ L
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? # G# U/ Z3 c- n2 t就是说,我们已知有一些工厂,生产出的产品要运往一些市场来满足他们的需求,每一个工厂的生产能力(每个工厂能提供产品的数量)以及每个市场的需求(每个市场需要产品的数量)是已知的。另外,我们还知道从特定的工厂到特定的市场,运输一件产品的运费。那么我们怎么样设计从每个工厂到每个市场运送货物的数量,使得总运费最小?/ z/ P: Q5 [5 b$ } S4 {% R
Indices:2 e$ Y+ O+ t* r! \' h2 L3 Q9 l/ i
i = plants# K7 T' Z, J. A7 {" m& h. Y" U
j = markets 5 g6 }4 D) O7 Q; {Given Data: $ j/ z8 _3 o7 @6 i/ Q% g/ tai = supply of commodity of plant i (in cases)& N6 t9 n) f$ c7 R
bj = demand for commodity at market j (cases), N7 H7 H$ n7 c0 Q+ Z/ a% g4 k
cij = cost per unit shipment between plant i and market j ($/case)# l7 H& w5 q0 v$ Y& G- E- q
Decision Variables: : ~6 g$ H1 P: } R8 gXij = amount of commodity to ship from plant i to market j 6 G, |7 N, @; V3 q0 l在这里唯一的连续变量是Xi,j,. Q; S) t8 m; Y U
模型就不用我说了吧。。。。 " D# Y7 T. h( p- o4 f % s9 ]& ?" M/ f( {$ l: V3 x这是一个典型的线性规划问题,他的GAMS code is9 b% r) l, W3 ^% f, k; G
( r k! H; J& o! E/ J4 fSets $ ^0 V3 V+ t; C; v; |& m; gi canning plants / seattle, san-diego / 4 y4 g: j' j1 t1 X7 a! dj markets / new-york, chicago, topeka / ;' S. {- v' x6 i+ p2 I9 y3 }
Parameters 5 R) N( C0 `( B u$ la(i) capacity of plant i in cases8 H3 v# w% h" i6 i; }! k" g5 o4 G8 D
/ seattle 350 # ^/ G6 T( p+ Q$ z$ Y9 @9 usan-diego 600 / 1 y+ Y- h6 g7 u( c" Nb(j) demand at market j in cases , O0 ?! ?+ H3 t9 I6 K$ S: z1 {( t/ new-york 3259 H2 _/ V/ y9 W( |$ Z0 r
chicago 300: q6 \: ~1 H# q
topeka 275 / ;: J ]6 _: |, ]
Table d(i,j) distance in thousands of miles 5 _; u+ q7 G2 ynew-york chicago topeka# y( _7 j4 t0 y; F6 M# @
seattle 2.5 1.7 1.8" [, C, c* m5 o E* w$ c0 J
san-diego 2.5 1.8 1.4 ;/ F m1 w2 E+ W4 h" S" y! C9 k( S% p
Scalar f freight in dollars per case per thousand miles /90/ ;3 e0 r& _4 e9 R! [
Parameter c(i,j) transport cost in thousands of dollars per case ; 9 q# U( t9 {+ O1 N5 q5 A! c! zc(i,j) = f * d(i,j) / 1000 ;4 `, o* S' f( ^0 Y( O+ A- d! }
Variables " R3 g& r1 j( |x(i,j) shipment quantities in cases ' o/ B. L' P1 V: y5 V2 g7 Uz total transportation costs in thousands of dollars ;0 W4 z% o4 z. `
Positive Variable x ; " n- g2 q' s/ E4 D' M' ~" R8 G# t/ `Equations 1 U# g/ Y+ r9 S" E( c6 Icost define objective function4 E2 X) |; J7 M. {; g8 n
supply(i) observe supply limit at plant i& S# u0 l `' i: h e
demand(j) satisfy demand at market j ;# g! S3 ~" Y- U0 a0 y
cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;* a/ t V6 H$ n' }8 {6 [6 q
supply(i) .. sum(j, x(i,j)) =l= a(i) ;/ h" T0 p: w! o* a8 \" ?
demand(j) .. sum(i, x(i,j)) =g= b(j) ; 4 J) o' @, k5 g' h1 cModel transport /all/ ;( M% X! D8 Z9 W R3 K& t
Solve transport using lp minimizing z ;" X" E7 s- k7 h g# }, H
Display x.l, x.m ;9 O: o- v1 @! n9 Y4 n3 [8 B, l
这是一个非常典型的LP(linear programming)问题,所有的变量和约束都是线性相关的。作者: fanghzou 时间: 2011-8-12 22:13
无人回复呀,版主,我也是化学工程,我觉得一般看这个的还是都是做石油化工的比较多吧。希望和版主交流一下,不知可否。作者: 历史的哭泣 时间: 2011-11-1 14:55
谢谢群主,我经常在这个数学中国上看到你,我是学习软件工程的,但是很喜欢数学,2010年参加数学建模竞赛,现在搞密码学,还是天天跟数学打交道,以前用matlab,不知道gams跟matlab有什么区别?群主能说一下嘛?作者: peterjiao 时间: 2012-4-15 17:03
楼主写的很是贴切啊,实践出真知,俺也在学习gams作者: constancemoon 时间: 2012-4-16 13:52
菜鸟级人物入门GAMS,觉得国内GAMS资源太少了!!!!作者: shenjun130 时间: 2013-4-27 16:05
感谢楼主,正在一点一点学习作者: 随墨枫飞 时间: 2013-5-30 13:34
嗯, 非常受教,但是一个人学,有难度的哦,请各位大侠讨论!!作者: LYJA 时间: 2015-10-13 07:32
very good, thank you very much!9 Y. |! K. \' O4 p" m 作者: 闲水闲云 时间: 2016-9-21 16:36
谢谢无私分享!感恩! - ]6 S x V& B5 R, i