# How can one iterate over all instances and solve them in GAMS?

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.

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. • 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 ? Nov 15 '20 at 11:49 • I was referring to gams.com/latest/docs/S_GUSS.html Nov 16 '20 at 13:32 • 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..? Nov 18 '20 at 1:18