Running GAMS in phases Topic is solved

Problems with syntax of GAMS
Post Reply
anaaza
User
User
Posts: 8
Joined: 4 years ago

Running GAMS in phases

Post by anaaza »

Hi,

I am building an economic model in GAMS, which, differently from the famous "transport" model does not call for optimization using lp or others. Usually, I just press f9 and GAMS runs it.
However, I have reached a phase where I will:

1) export some tables to R (I am using an Excel file as intermediate cause I have not found out how to send it directly to R - but it does not matter now),
2) run some analysis In R, and
3) Import it back to GAMS to continue the model

I wrote (in the body of the model) the gdx routine to export the files to Excel and it worked well. The import routine, however, I wrote in a separate file (also works well). When I tried to put both routines in the same file (the one containing the original model), it didn't work as I would like.

What I want, is to divide my model into parts:
1) First, to run the model until the part where I export the tables
2) Then, to run the routine importing the tables back into GAMS
3) Finally, to run the rest of the model

How do I do that? Does the "solve model_name" works even for models that "are not optimizing" anything?

Thanks.

Cheers,
brucemccarl
User
User
Posts: 13
Joined: 6 years ago

Re: Running GAMS in phases

Post by brucemccarl »

look at save and restart

plus perhaps the sleep command to give R time to run
User avatar
dirkse
Moderator
Moderator
Posts: 215
Joined: 7 years ago
Location: Fairfax, VA

Re: Running GAMS in phases

Post by dirkse »

Hi,

There is a tendency to overuse the word "model" in this area. For example, a GAMS model can be:
  • A bunch of GAMS code stored in a file.
  • A GAMS symbol denoting a collection of equations, e.g.

    Code: Select all

    model m / all /;
The latter can be solved using the solve statement, but the former isn't something to "solve" in that sense.

There are many ways to arrange your GAMS code and language features to support this. In particular, you should look at calling a separate GAMS source file from within GAMS via the '$call' or 'execute' commands.

https://www.gams.com/latest/docs/UG_Dol ... _21_option
https://www.gams.com/latest/docs/UG_Gam ... larExecute

Also, two examples that will probably give you some ideas:

https://www.gams.com/31/testlib_ml/libh ... h=invert01
https://www.gams.com/31/datalib_ml/libh ... ch=invert1

In particular the last example shows in general how you can export some data from GAMS to R, do some work in R, and bring new data from R back to GAMS.

HTH,

Steve
anaaza
User
User
Posts: 8
Joined: 4 years ago

Re: Running GAMS in phases

Post by anaaza »

Thank you all for your replies.
After reading both suggestions and consulting GAMS documentation, I think brucemccarl's suggestion would fit my needs the best. The only problem is that I have an old version of GAMS (24.1) and apparently the save and restart does not work there. Am I right?
brucemccarl
User
User
Posts: 13
Joined: 6 years ago

Re: Running GAMS in phases

Post by brucemccarl »

save and restart has worked for decades
must be something else
Post Reply