How to execute many "programs" at one time?

Problems with syntax of GAMS
Post Reply
Jarenka
User
User
Posts: 55
Joined: 1 year ago

How to execute many "programs" at one time?

Post by Jarenka » 1 week ago

Dear,

I have a couple of sections (see in the attachment, all LINE ...), which I would like to run at one time, not separately as I do it now. Each section contains parameters that might repeat in another section, but not necessary.
How to do it in GAMS?

My point is to run each of them and create *gdx files each for each section separately.

Best
Irena
sections.JPG

User avatar
Renger
Posts: 406
Joined: 3 years ago

Re: How to execute many "programs" at one time?

Post by Renger » 1 week ago

Hi Jarenka

You could use a file with all commonly used parameters in an include file at the root.
Then you could use a dos batch file and walk through the subfolders, like

cd subfolder1
call gams modelsub1
cd..
cd subfolder2
call gams modelsub2
cd..
etc.

Is that what you are looking for?
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

Jarenka
User
User
Posts: 55
Joined: 1 year ago

Re: How to execute many "programs" at one time?

Post by Jarenka » 1 week ago

The most important think is to receive *gdx file with all parameters for each specified section.
Usually, I start with running LINE1A_Data and create *gdx file (with the same name usually). Then I run LINE1A_Incomes.gms and create *.gdx file again.
And so on ...
The point is to run each section independently with its own *gdx file (with the same name and including all parameters).
Every section contains a link to a program (called LINE.gms) that includes specification of sets and parameters for all sections.
It somehow has to use $onMulti statement, probably.

I do not know how this batch file works. Do you have a program to create such file?

Irena

User avatar
Renger
Posts: 406
Joined: 3 years ago

Re: How to execute many "programs" at one time?

Post by Renger » 1 week ago

Hi Irena
No, it is just a text file that runs in a dos window (like the one you can start from the Gams editor) using DOS commands (you could also do it with the newer script tool in Windows called powershell).

I could write the following batch file named "run.bat":

Code: Select all

cd directory1a
call gams line1a_income
cd..
cd directory1b
call gams line1b_income
cd..
If you open a command window ("cmd"), you just type "run" (without the ".bat" at the end) and this will jump to the subdirectory named "directory1a", call gams to solve line1a_income, go one directory up (by cd..) and then to the subdirectory "directory1b", solve line1b_income and return to the root directory.

The advantage is that if you make a mistake in one of your model files, it only will stop the execution of that file, but then jumps to the next directory and solves the gams model there.

Here an example to solve also multiple occasions of the same model by using global settings with "setglobal". For example, if you want to solve the same model for different datasets.

You would then have the following in your model file "mymodel.gms":

Code: Select all

$setglobal agglevel full

$if %agglevel% == "full" $call 'gdxxrw SAM2014full o=%agglevel%.gdx index=gams!a1:f34 Trace=3'
$if %agglevel% == "agg10" $call 'gdxxrw SAM2014agg.xlsx o=.\temp\data_%agglevel%.gdx index=gams!a1:f34 Trace=3'
...
solve mymodel
Your batch file would look like this

Code: Select all

call gams mymodel  --agglevel=full
call gams mymodel --agglevel=agg10
This would run the model with both aggregation levels.

Hope this gives you an idea of the power of using batch files.

Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

Jarenka
User
User
Posts: 55
Joined: 1 year ago

Re: How to execute many "programs" at one time?

Post by Jarenka » 3 days ago

Hi,

Thank you!

I have created a *bat file called run.bat in a simple text editor.
But when I want to run it (by clicking on it) it does not come anything.

Here below is a code in it.
I think I am doing something wrong. It seems to be too simple for me!

Irena
Capture.JPG

GFA
User
User
Posts: 9
Joined: 1 year ago

Re: How to execute many "programs" at one time?

Post by GFA » 2 days ago

Hi,

You can use in your bat-file the complete path to gams, e.g.:
"C:\Program Files\GAMS\win64\25.1\gams" C:\GAMSfile.gms
And it will open GAMSfile.gms

I think you can also use "gams C:\GAMSfile.gms" when you make a windows environment variable of GAMS

GFA

Post Reply