1
$\begingroup$

I wrote my model down in GAMS:

  • all sets
  • parameter
  • obj. function
  • constraints

and used $include in order to feed the model differently sized data... I am currently using

$include "C:\Users\...\GAMS modelling\P3T5.inc"

in order to import my data file.

My file name is always "P{number of products}T{Number of time periods}.inc" What would be the best way to access all the files in a loop? How can I change the file name during the loop statement? I am thinking of making a set of all product numbers and period numbers, but I don't know how to use the index in the loop to alter the command of the include.

$\endgroup$
3
$\begingroup$

You cannot loop over include files ($include is compile-time, while loop is execution- time, this is similar to say C where you cannot loop over #include). One could loop over complete GAMS models (call gams inside a loop), or over reading data from GDX (GAMS data) files. But often a better approach is the following.

I would just read in all problem data in one big swoop (possibly with an extra index indicating the scenario). Once you have all the data (checked and possibly transformed) do a solve loop. This was discussed already before in a previous question. So, to summarize, I usually do:

 1. load all data, do data checks and data transformations
 2. loop over scenarios, execute solve statements, and collect results
 3. reporting

This approach has many advantages, not in the least better structuring of the model. Cleanly organized models are much to be preferred over messy models. In addition, checking all data before starting solving is often more convenient than intersperse these operations (I want to stop and complain before running expensive solves). This approach makes it also easier to use more advanced techniques such as parallel processing and using the scenario solver.

$\endgroup$
3
  • $\begingroup$ This sounds like a reasonable approach! Do you have reference-code for scenario creation? Is this the best page to start: gams.com/latest/docs/UG_ComparativeAnalysis.html ? $\endgroup$
    – DerEddie
    Nov 15 '20 at 11:49
  • $\begingroup$ I was referring to gams.com/latest/docs/S_GUSS.html $\endgroup$ Nov 16 '20 at 13:32
  • $\begingroup$ thanks for the answer! how do i read in all instances in a big swoop? they are .inc files and include only works for one file i found out. $onMulti is maybe the solution, but i am not sure if "merging" is what i want..? $\endgroup$
    – DerEddie
    Nov 18 '20 at 1:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.