GAMS:将循环中生成的输出保存到单个 .gdx 文件而不覆盖以前的条目

GAMS: Saving outputs generated in a loop to a single .gdx file without overwriting previous entries

我想在 GAMS 中运行 3 次,我还想将集合 "codes" 的 3 个随机选择的元素中的每一个保存到 .gdx 文件中,而不是每个条目都被覆盖循环中的下一个随机生成的输出。我怎样才能防止这种覆盖,以便我能够将循环中每个随机生成的输出保存在一个 output.gdx 文件中?到目前为止,以下是我的代码:

SET
      codes /aaa, aab, aac, aad, aae, aaf, aag, aah, aaj, aak, aal/
      selected(codes);

$gdxout outputs
loop((1,3),
randnumber = uniformint(1,11);
selected(codes)=ord(codes)=randnumber;
execute_unload 'output.gdx',selected;
display selected;
);
$gdxout

上面代码的结果为我提供了一个只有 1 个条目的 .gdx 文件 - 集合 "codes" 中最后(第 3 个)随机选择的元素。对此提供一些帮助将不胜感激。

您可以使用加法 "scenario index" 在执行循环时将结果存储在参数中,并在结束时立即导出所有内容,如下所示:

SET
      codes /aaa, aab, aac, aad, aae, aaf, aag, aah, aaj, aak, aal/
      scenario /1*3/;

scalar
      randnumber;

parameter
      selected(scenario,codes);

loop(scenario,
  randnumber = uniformint(1,11);
  selected(scenario,codes)=ord(codes)=randnumber;
);

execute_unload 'output.gdx',selected;
display selected;

我帮助就是帮助! 卢茨