, ?& V# B) n, ]* K f1 W6 Q- R; iGAMS是一种非常简单易学的运筹学建模语言 (www.gams.com),是由WORLD BANK 开发的。由于近几十年计算机软硬件的的高速发展,世界银行决定投资开发GAMS, 来提供:8 ~. O( d7 w- J. r5 n1 X" M
1. 建立复杂模型的高级语言: _# i3 W$ t- |& R: G% v
2. 简单易学 * J0 q5 ]: r1 c' V+ p3. 强大的描述代数及逻辑关系 8 x9 p Y6 d" m$ Y% v6 Z3 `4. 模型可以独立于算法系统) B5 _/ A! N; T' }& a- a
GAMS 可以让使用者专心致力于模型的建立而省略了解法方面的考虑因为GAMS包含了解决通用的LP,NLP,MILP,MINLP等各类模型所需要的solver. 另外,GAMS提供了和外界进行交互的输入输出借口。使得用户很方便的导入导出data。 " `. r9 l1 n9 {% W3 i9 d下面当然是tutorial了,就想学习任何一种编程语言一样,最开始都要学习输出 hello world. 我们这里当然要复杂一点了,举一个最简单的例子,运输问题./ V, P( w z- x0 G1 z, Z
这是一个经典的LP问题(不用解释什么是LP吧,呵呵) 1 ]9 j; V+ ?5 d/ M* W" j用点英语,呵呵, $ h; A7 r# g3 ^0 ]5 n/ qIn 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? & B# c, f% w6 X4 e- p4 J就是说,我们已知有一些工厂,生产出的产品要运往一些市场来满足他们的需求,每一个工厂的生产能力(每个工厂能提供产品的数量)以及每个市场的需求(每个市场需要产品的数量)是已知的。另外,我们还知道从特定的工厂到特定的市场,运输一件产品的运费。那么我们怎么样设计从每个工厂到每个市场运送货物的数量,使得总运费最小?+ I9 s6 ~1 o) _( \
Indices:. n6 u. O& Z: a" z0 V
i = plants / J; f! h Y9 e" U- K6 Uj = markets $ `' w9 u" S5 V ]; r) A5 S" PGiven Data:9 n5 P o: \" q0 h: A ~; M( r- a
ai = supply of commodity of plant i (in cases)$ m9 [2 t6 [8 A3 R
bj = demand for commodity at market j (cases)# m5 B, ^1 h- G* t! g" e
cij = cost per unit shipment between plant i and market j ($/case)' y# L( d8 c- X% A$ h
Decision Variables: $ _5 N; W/ l+ p+ r' b$ M0 Z! ]Xij = amount of commodity to ship from plant i to market j5 R3 p' z9 c5 o' Q# p4 s& r, T) A
在这里唯一的连续变量是Xi,j, ) V" b1 b+ C- Q9 F7 N1 Y6 r模型就不用我说了吧。。。。+ D% [) b1 u9 d5 A6 k. b* a r' ]
* R2 X& J3 A4 k) l) ~9 ^* f这是一个典型的线性规划问题,他的GAMS code is # }, P7 F5 N3 c4 I7 i+ T: A3 K& N# s1 s' e7 t4 ]* k' a
Sets 0 o* _$ K' C8 ^ l5 Ai canning plants / seattle, san-diego /! O* B# g9 e1 P# S6 o$ H
j markets / new-york, chicago, topeka / ; 7 t- K6 q5 g! _ r; Y0 D' X1 qParameters ' j/ O {- Z& {" F+ Y8 ma(i) capacity of plant i in cases ; I5 U) ?1 T* q- G! w) x% s/ seattle 350) N/ B9 I2 `5 r$ I+ `, F9 H
san-diego 600 / 7 M2 u5 @+ n- k9 t6 yb(j) demand at market j in cases, b. R' A: C* m/ T$ w4 ?7 p. ^! j
/ new-york 3259 j9 ~: m9 Y# T/ _4 ?5 J
chicago 300$ ^- K% g3 u Y" U8 c$ ?
topeka 275 / ; / T! _% A7 [1 B. N: h8 [% p+ CTable d(i,j) distance in thousands of miles ! W, N2 D/ s2 }: j4 vnew-york chicago topeka; _% ?3 Y1 ], l2 g6 |
seattle 2.5 1.7 1.8/ j6 ^+ O7 h5 q: G
san-diego 2.5 1.8 1.4 ; , p4 ~. A, m \' U- B8 FScalar f freight in dollars per case per thousand miles /90/ ; 2 }( A5 A4 ]! @8 EParameter c(i,j) transport cost in thousands of dollars per case ; & X& t! ?+ L* a3 g8 j, P# Jc(i,j) = f * d(i,j) / 1000 ;( J7 i0 L* X: J) \, Z/ S( A
Variables 9 U2 G) {; {; @" j# Ox(i,j) shipment quantities in cases7 [( t- J: X1 ?
z total transportation costs in thousands of dollars ; " l$ e/ g) o4 l; U4 t/ ]; xPositive Variable x ;7 A+ @8 W; L+ B% y. w) S3 C
Equations 6 A B3 \0 ], t9 ?4 Vcost define objective function3 W4 I& s0 Q( L! k s
supply(i) observe supply limit at plant i7 M, X* b; e) b
demand(j) satisfy demand at market j ; 5 ^! V9 w6 b. t2 m5 Acost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;) R2 h! t) B8 N
supply(i) .. sum(j, x(i,j)) =l= a(i) ;/ B6 c$ `4 Y7 ^% P( ^* L+ v
demand(j) .. sum(i, x(i,j)) =g= b(j) ;) S2 J! H4 w' Z
Model transport /all/ ;* \7 ]1 L& J* X0 d" P' h# P, N
Solve transport using lp minimizing z ; % S5 l! P3 x9 c3 U8 j) n, b4 Q# y0 [Display x.l, x.m ;' b$ ~1 ^' C S5 A( ]/ q. m
这是一个非常典型的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!; f: v e( c& r7 C+ L 作者: 闲水闲云 时间: 2016-9-21 16:36
谢谢无私分享!感恩! % i3 q' k9 m' u+ I. }