gams:reusing_optimal_values

**This is an old revision of the document!**

*How can I save the optimal values of a certain variable X that appears in one model, and reuse in another model that is otherwise unrelated, i.e. the save/restart facilities are not appropriate.*

Write the level and the marginals of the variables you are interested in into a gdxfile and load that gdx file into your second model at the end of the first model add something like (assuming that you are interested in x):

Execute_Unload 'results.gdx', x; * and load this data into your second model: <code> ... $GDXIN results.gdx $load x ... </code>

Another approach is to use the savepoint option. Just add a line “option Savepoint=1;” or“ “option Savepoint=2;” to your first model before the solve statement. In your second model add the line “Execute_loadpoint 'name_of_the_first_model_p.gdx';”. The McCarl Users Guide, which is included in the GAMSIDE, contains some more advanced examples.

With an older GAMS Version you may try the PUT statement to write out an include file for the second model. That PUT statement could look like:

file pf /'inc.inc'/; put pf; put "PARAMETER P(I,J) /" /; LOOP ((I,J), PUT " ",I.TL,".",J.TL," ",X.L(I,J):20:10 /; ); put "/;" /;

This would generate a file like:

PARAMETER P(I,J) / SEATTLE .NEW-YORK 0.0000000000 SEATTLE .CHICAGO 300.0000000000 SEATTLE .TOPEKA 0.0000000000 SAN-DIEGO .NEW-YORK 325.0000000000 SAN-DIEGO .CHICAGO 0.0000000000 SAN-DIEGO .TOPEKA 275.0000000000 /;

The only thing to worry about is that the sets I and J are identical for the first model and the second one. One way to make sure they are in sync is to the put these set declarations in an include file.

IMPRESSUM / LEGAL NOTICE
PRIVACY POLICY
gams/reusing_optimal_values.1442579361.txt.gz · Last modified: 2015/09/18 14:29 by Jarungjit Parnjai