【问题标题】:GAMS: changing names of files to include in a loopGAMS:更改文件名以包含在循环中
【发布时间】:2018-12-05 07:47:51
【问题描述】:

我想包含多个csv 文件,并且我想在循环中引用它们。我所有的文件都有系统名称:file1.csv, file2.csv etc。 如何创建包含所有文件的循环?

我正在寻找这样的东西:

set j /1*10/
loop(j,
  $include "filej.csv")

我该怎么做?

【问题讨论】:

    标签: gams-math


    【解决方案1】:

    一种方法是使用Put Writing Facility

    set     fn      / '1.csv' * '10.csv' /;
    file    output  / output.rsp /;
    put     output  /;
    
    loop(fn, 
            put '$include file' fn.tl /);
    

    这将生成一个文件output.rsp,其内容为:

    $include file1.csv
    $include file2.csv
    ...
    $include file10.csv
    

    然后在相关的.gms 文件中添加$include output.rsp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-15
      • 1970-01-01
      • 2012-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多