Running multiple gms files: order of gms files affects results

Problems with syntax of GAMS
Post Reply
edwardmw
User
User
Posts: 5
Joined: 1 year ago

Running multiple gms files: order of gms files affects results

Post by edwardmw »

Hello friends,

Longtime reader, first time poster!

(Note: I believe this is a question for syntax rather than modeling (or another grouping) but if I am wrong I am happy to repost in the appropriate place.)

I am trying to run several component gms files at once using a master gms file. Each component gms file is all written to solve the same model, but each file has slight variation in set elements or parameter values (for a little background, these variations are meant to characterize different market structures or policy shocks).

The problem I am having is that the results from each component gms file vary depending on the order in which the gms files are included. This suggests to me that some values from the run of the first gms file persist through the second gms file, and so forth.

Is there a simple way to clear ALL variable and parameter values (and if need be, set values) before including each gms file? The only relevant command I can find is "clear" but it is indicated in the user guide that this is performed during compilation and not execution. It seems to me that I would need the values cleared during execution.

My file structure is the following:
Master gams file with code that
-loads in gdx data
-defines sets
-defines some parameters and assigns values to these parameters; these parameters are unchanged throughout all of the gms files included
-defines remaining parameters that are assigned values in each of the gms files
-defines the model (including variables and equations) that is solved in each of the gms files

Further down in this same master gms file, I include multiple gms files. Each gms file that I include takes about an hour to solve (hence the desire to click run and walk away) and has the following structure:
-assigning parameter values to those defined in the master data
-assigning initial guesses to the model variables using the assigned parameter values
-solving the model
-dumping the results into a gdx file

I hope this is clear enough, but I am happy to edit or respond with clarifications. Thank you in advance!
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Running multiple gms files: order of gms files affects results

Post by bussieck »

I guess it is related to all the variables and equations that have not been set by the scenario procedure. They will be different depending on the order of the solves/scenarios/includes. If you could do without a starting there are ways to tell the solver to ignore the initial point (see https://www.gams.com/latest/docs/UG_Gam ... MSAObratio), but since you pay attention to setting an initial point, this must matter to you (and the solver). So this is not an option.

Assuming that the model rim is identical in all scenarios you could use the solution of a reference run that you load into your variables and equations before you modify the .l and .m in your specific scenario. You would need to run one scenario (without the others in parallel) with the option savepoint=1 (https://www.gams.com/latest/docs/UG_Gam ... Osavepoint) and use execute_loadpoint (https://www.gams.com/latest/docs/UG_GDX ... _LOADPOINT) with the GDX point file generate by the first solve (don't forget to set savepoint=0 after the first solve so the file does not get overwritten by the scenario solves) but no symbols, so GAMS matches what it finds in the GDX file. This guarantees that your solve is independent of what solves happened before (with the exception of the reference run).

-Michael
Post Reply