Running GAMS in phases

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,

look at save and restart

plus perhaps the sleep command to give R time to run

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.
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_DollarControlOptions.html#INDEX__25_call_2d__21_dollar_21_control_21_option
https://www.gams.com/latest/docs/UG_GamsCall.html#UG_DollarExecute

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

https://www.gams.com/31/testlib_ml/libhtml/testlib_invert01.html?search=invert01
https://www.gams.com/31/datalib_ml/libhtml/datalib_invert1.html?search=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

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?

save and restart has worked for decades
must be something else