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

Loops GAMS:将循环中生成的输出保存到单个.gdx文件,而不覆盖以前的条目,loops,random,indexing,gams-math,Loops,Random,Indexing,Gams Math,我希望在GAMS中运行3次,其中我还希望将集合“代码”的3个随机选择的元素中的每一个保存到一个.gdx文件中,而不让每个条目被循环中下一个随机生成的输出覆盖。如何防止这种覆盖,以便能够将循环中随机生成的每个输出保存在一个output.gdx文件中?以下是我目前的代码: SET codes /aaa, aab, aac, aad, aae, aaf, aag, aah, aaj, aak, aal/ selected(codes); $gdxout outputs loo

我希望在GAMS中运行3次,其中我还希望将集合“代码”的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文件,这是集合“代码”中最后一个(第3个)随机选择的元素。对此,我们将非常感谢您提供的帮助。

您可以在执行循环时使用一个附加的“场景索引”将结果存储在参数中,并在结束时立即导出所有内容,如下所示:

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;
我帮你,那就帮你! Lutz

在执行循环时,您可以使用一个附加的“场景索引”将结果存储在参数中,并在结束时立即导出所有内容,如下所示:

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;
我帮你,那就帮你! 卢茨