将参数从Excel导入GAMS:获取全零

问题描述

我有一个带有电子表格GAMS的Excel文件GAMS2.xlsx,其中包含如图所示的数据

enter image description here

在GAMS中,我编写了这样的代码

Set t /t1*t5/;
 
Parameters
W(t);
$call gdxxrw GAMS2.xlsx par=W rng=GAMS!A3:B7 rdim=1 dset=t rng=GAMS!A3:A7 rdim=1
$gdxin GAMS2.gdx
$load W
$gdxin

display W;

然后我得到了很好的gdx文件

enter image description here

因此,运行后我没有任何错误,但是参数W的所有值均为零。在第一个文件中,我看到:

----     6 ParaMETER W

                      ( ALL       0.000 )

我怎么了?任何帮助将不胜感激,谢谢!

解决方法

看起来您在Excel文件中的集合t1 to 5,而在GAMS模型中您的集合tt1 to t5。因此,您没有匹配的域,因此不会加载任何值。如果您使用$loadDC(用于域检查的DC)而不是$load,GAMS将会停止并立即通知您。

BTW:您也可以使用隐式集合定义从GDX中轻松填充集合t。看起来像这样:

Set t;
 
Parameters W(t<);

$call gdxxrw GAMS2.xlsx par=W rng=GAMS!A3:B7 rdim=1 dset=t rng=GAMS!A3:A7 rdim=1
$gdxin GAMS2.gdx
$load W
$gdxin

Display W;