Automated calculation of several example instances

I have modelled a MIP and want to solve several instances. So far, I have read and analysed each file from Excel by hand. I would like to automate this process as follows:
The different Excel files with the instances (instance 1, instance 2 etc). should be read from Excel into GAMS one after the other and the model should be solved for the corresponding instance in each case. The results of each instance are to be output in a separate row in Excel.

At the moment I read in an instance as follows:

[code]
$call gdxxrw Instance1.xlsx o=Data.gdx @text file
$gdxin Data.gdx
$load a, b, c, d
$gdxin
;
[\code]
Is there a way to automate this process? I’ve tried it with a loop, but unfortunately I can’t get any further. I would be grateful for a tip.

I would not do that in a loop. I would parameterize your model (the name of the Excel instance file) and then have a script that calls GAMS for each instance:

In your model you have

$if not set instance $abort Need to set --instance=filename
$call gdxxrw %instance%.xlsx o=Data.gdx @textfile
...

Then in a separate script (he I use a GAMS script, but you can do this in a cmd or sh script too):

$call gams mymodel --instance=instance1 fileStem=instance1 lo=2
$call gams mymodel --instance=instance2 fileStem=instance2 lo=2
...

Appending to the output with Excel is a little tricky. Perhaps, you can just write the results to a CSV file (that opens also nicely in Excel). With that you can use the GAMS put facility to append to your result file. So in your model you have, e.g.

file fr / results.csv /; fr.ap=1;
put fr '%instance%,' obj.l;

Make sure to remove the results.csv when you start a new set of runs. You could automate this by adding $call rm -f results.csv to the top of the script that runs the various instances.

Hope this helps,
-Michael