GAMS 简明教程:怎样安排运输使得我们的总运输成本最小?
Richard E.Rownthal写了一份 GAMS 简明教程,我自己大致在八年之前粗译。选择一些example,分享给大家。
考虑几个工厂的供应和几个市场的需求的商品,熟悉的运输问题中,给出从工厂运输商品到市场的单 位花费。这其中的经济学问题是:
怎样安排运输使得我们的总运输成本最小?
这个问题的代数表达:
在 GAMS 中,被采用的相关术语是:sets表示指数下标,parameters表示已知参数,variables表示决策变量,equations 表示约束方程和目标方程。
作为运输问题的例子,假设有两个罐头厂和三个市场,已知数据如表 2.1 所示。运输距离的单位是千英里,运输成本是$90.00 每箱每千英里。这个例子的 GAMS 表述是:
Sets
i canning plants / seattle, san-diego /
j markets / new-york, chicago, topeka / ;
Parameters
a(i) capacity of plant i in cases
/ seattle 350 san-diego 600 /
b(j) demand at market j in cases
/ new-york 325 chicago 300 topeka
275 / ;
Table d(i,j) distance in thousands of miles
new-york chicago topeka
Seattle 2.5 1.7 1.8
san-diego 2.5 1.8 1.4;
Scalar f freight in dollars per case perthousand miles /90/ ;
Parameter c(i,j) transport cost inthousands of dollars per case ;
c(i,j) = f * d(i,j) / 1000 ;
x(i,j) shipment quantities in cases
z total transportation costs in thousands of dollars ;
Positive Variable x ;
Equations
cost define objective function
supply(i) observe supply limit at plant i
demand(j) satisfy demand at market j ;
cost z =e= sum((i,j), c(i,j)*x(i,j)) ;
suply(i) sum(j, x(i,j)) =l= a(i) ;
demand(j) sum(i, x(i,j)) =g= b(j) ;
Model transport /all/ ;
Solve transport using lp minimizing z ;
Display x.l, x.m ;
如果你将上述语句输入GAMS程序,运输问题将会被公式化并得到解决。在不同的电脑上如何使用GAMS存在细微的差别,那就是如何在不同的电脑上援用GAMS,激活GAMS最简单(无冗余的)的方法是在输入文件名上加“gams”作后缀。你将会看到GAMS所作的进程被一些简洁的符行所表示,其中包括文件名,输出结果也在上面。
当 GAMS 程序结束时,检查文件,如果一切正常的话,那么最优化运输方案将显示如下:
你还将得到如下边际成本(单一乘数):