GAMS>>GDX>>Excel导出的一个例子(含多维数组的导出)
gams吧
全部回复
仅看楼主
level 6
颍川raining 楼主
Sets
i canning plants / Seattle, San-Diego /
j markets / New-York, Chicago, Detroit /
p Property /attribute1,attribute2, attribute3/;
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
Detroit 275 / ;
table u(i,j,p)
attribute1 attribute2 attribute3
seattle.new-york 3 4 5
San-Diego.new-york 6 7 8
seattle.Chicago 9 10 11
San-Diego.Chicago 12 13 14
seattle.Detroit 15 16 17
San-Diego.Detroit 18 19 20 ;
Table d(i,j) distance in thousands of miles
New-York Chicago Detroit
Seattle 2.5 1.7 1.8
San-Diego 2.5 1.8 1.4;
scalar f freight in dollars per case per thousand miles/90/;
Parameter c(i,j) transport cost in 1000s of dollars per case;
c(i,j)= f*d(i,j)/1000;
Variables
x(i,j) shipment quantities in cases
z total transportation costs in 1000s of dollars;
Positive variables 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));
supply(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;
Execute_unload 'transport.gdx',c,x,z,u;
execute 'gdxxrw transport.gdx o= transport.xlsx par=c rng= AA!a1:d3 rdim=1 cdim=1';
execute 'gdxxrw transport.gdx o=transport.xlsx var=x rng= AA!a5:d7' ;
*execute 'gdxxrw transport.gdx o=transport.xlsx var=z rng= sheet1!e9' clear;
execute 'gdxxrw.exe transport.gdx var=z rng= AA!e9 clear';
*下面两句代码解释了rdim&cdim的确切用法
execute 'gdxxrw.exe transport.gdx par=u rng= AA!a10 rdim=1 cdim=2';
execute 'gdxxrw.exe transport.gdx par=u rng= AA!a14 rdim=2 cdim=1';
2016年04月16日 08点04分 1
level 1
请问是否需要提前生成一个gdx文件?
2017年03月06日 16点03分 3
不需要,软件会运行gdxxrw.exe从而生成excel
2017年03月09日 13点03分
明白了 谢谢
2017年03月10日 05点03分
level 1
请问,在solve之前输出变量到gdx文件您懂吗?我按网上编了程序但是数据传不过去
2018年07月12日 15点07分 5
1