如何取出参数中不需要的集合并从一个参数复制到另一个参数

How to take out unneeded sets in a parameter and copy from one parameter into another

我想从 GAMS 中的参数中删除不必要的集合(或索引)

问题定义如下:

我有一个参数(我从 GDX 文件中获得)

parameter
Prices_data(AreaCode,centralamerica,ItemCode,crops,ElementCode,dollars,YearCode,Year,Unit)

在列表文件中显示时,它看起来像这样:

166.Panama    .56 .Maize     .5532.Producer Price (USD/tonne).1999.1999.USD 281
48 .Costa Rica.56 .Maize     .5532.Producer Price (USD/tonne).1999.1999.USD 217

不过有些数据栏是没用的,比如Areacode, Itemcode, elementcode等

我希望它显示为:

Panama.Maize.1999 281
Costa Rica.Maize.1999 217

将参数更改为这种格式:

parameter
Prices_data(centralamerica,crops,Year))

我在 forum.gamsworld.com 中问了这个问题,有人回复告诉我这样做:

Prices_data(centralamerica,crops,Year) = sum((AreaCode, ItemCode, ElementCode, dollars, YearCode), Prices_data(AreaCode,centralamerica,ItemCode,crops,ElementCode,dollars,YearCode,Year,Unit));

但是,我收到一条错误消息:

Error 171 Domain violation for set
Error 148 Dimension different - The symbol is referenced with more/less indices as declared
Error 149 Uncontrolled set entered as constant

到目前为止,在 GAMS 论坛中还没有人找到解决方案。

在您的作业中,您在左侧和右侧使用参数 Prices_data,但索引不同。这行不通,因为其中只有一个与声明匹配。如果您想使用建议的方法,您需要有两个不同的参数(具有不同的名称),如下所示:

parameter
Prices_data(AreaCode,centralamerica,ItemCode,crops,ElementCode,dollars,YearCode,Year,Unit)
Prices_data_Clean(centralamerica,crops,Year);

Prices_data_Clean(centralamerica,crops,Year) = sum((AreaCode, ItemCode, ElementCode, dollars, YearCode), Prices_data(AreaCode,centralamerica,ItemCode,crops,ElementCode,dollars,YearCode,Year,Unit));