nested GAMS calls with save and restart

Problems with syntax of GAMS
LaurentFranckx
User
User
Posts: 7
Joined: 4 months ago

nested GAMS calls with save and restart

Postby LaurentFranckx » 1 month ago

Dear all

I am trying to implement nested GAMS calls.

To be more concrete, I have a top-level GAMS file, say, root.GMS, which calls a PowerShell script, say myscript.ps1, with the following code:

Code: Select all

execute "powershell -File C:\gams\MyModel\myscript.ps1" 
This PowerShell script loops through a series of parameters to call a set of other GAMS scripts:

Code: Select all

$Years = (2013..2030)
foreach ($CurrentYr in $Years ) { 
        gams branch.GMS --year=$CurrentYr 
}
The problem is that branch.GMS does not recognize the parameters that are used in root.GMS.

One obvious solution would be to split root.GMS in two, and to use the save and restart facilities. The first part would include all the code up to the call to myscript.ps1 (call this root1.GMS), and the second part would include all the code from myscript.ps1. (call this root2.GMS).

The following PowerShell code should work then (assuming no parameters are defined in branch.GMS that are needed in root2.GMS):

Code: Select all

gams root1.GMS  s=root1
$Years = (2013..2030)
foreach ($CurrentYr in $Years ) { 
        gams branch.GMS --year=$CurrentYr r=root1
}
gams root2.GMS  r=root1
However, this solution would quickly become unwieldy with several layers of nesting. Is there any other approach that would allow me to pass on the parameters defined in root1.GMS to branch.GMS without abandoning the nesting structure?

User avatar
Renger
Posts: 55
Joined: 1 year ago

Re: nested GAMS calls with save and restart

Postby Renger » 1 month ago

Hi

Perhaps you could dump all the information you need in a gdx file and load the necessary parameters in the next nest.
You only have to define these parameters in the next step.

Cheers
Renger

LaurentFranckx
User
User
Posts: 7
Joined: 4 months ago

Re: nested GAMS calls with save and restart

Postby LaurentFranckx » 1 month ago

@Renger Thanks for the tip. Technically, that would be solution, but it is also error prone: if you add new parameters or variables, you could easily lose track of them. Now that I think of it, this is precisely a key advantage of the 'save' and 'restart' commands.
I have worked around the problem by implementing the solution I had discussed in my first post: I now call all GAMS scripts from a single PowerScript script. It's not very elegant, but it does work.


Who is online

Users browsing this forum: No registered users and 1 guest