How to execute many "programs" at one time?

Problems with syntax of GAMS
Jarenka
User
User
Posts: 64
Joined: 5 years ago

How to execute many "programs" at one time?

Post by Jarenka »

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: 639
Joined: 7 years ago

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

Post by Renger »

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: 64
Joined: 5 years ago

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

Post by Jarenka »

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: 639
Joined: 7 years ago

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

Post by Renger »

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: 64
Joined: 5 years ago

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

Post by Jarenka »

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: 50
Joined: 5 years ago

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

Post by GFA »

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
Jarenka
User
User
Posts: 64
Joined: 5 years ago

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

Post by Jarenka »

Hi,

I am still struggling with this *bat file. I cannot make it working.
Here below, I want to execute two gams files: LINE1A_Data and LINE1A_Incomes:
Capture.JPG
When I click on the run.bat file nothing happens.

I do not understand this kind of programming w/ many files.

Jarenka
User avatar
Renger
Posts: 639
Joined: 7 years ago

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

Post by Renger »

Hi Jarenka

It should read

Code: Select all

gams yourmodel.gms
Delete the "cd" in front of the line.

Hope this helps
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Jarenka
User
User
Posts: 64
Joined: 5 years ago

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

Post by Jarenka »

Thank you Renger,

It helped, but did not create *gdx-files for these two sections. It has only created two new *lst-files.

What should I write to execute these two sections and create gdx-files for each of the sections.

Best
Irena
Capture.JPG
User avatar
Renger
Posts: 639
Joined: 7 years ago

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

Post by Renger »

Hi Jelenka
Do they produce gdx files when you run it from the Gamside/Gams Studio?
I don't know what the commands are you used, but you can also add the command option

Code: Select all

gdx=file_name
in your batch file at the end of each line and replace file_name with the name you want the gdx file to have.
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply