User Tools

Site Tools


gams:reusing_optimal_values

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
gams:reusing_optimal_values [2017/09/02 19:21]
support
gams:reusing_optimal_values [2020/05/18 15:15]
Michael Bussieck
Line 3: Line 3:
 //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.// ​ //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  +Write the level and the marginals of the variables you are interested in into a GDX container ​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):+load that GDX container ​into your second model
  
-  Execute_Unload ​'​results.gdx',​ x; +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 before the solve statement''​execute_loadpoint '​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 GAMS distribution,​ 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.+
  
 +Another approach is to use the [[https://​www.gams.com/​latest/​docs/​UG_GamsCall.html#​GAMSAOsavepoint|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';''​.
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/reusing_optimal_values.txt · Last modified: 2020/05/18 15:15 by Michael Bussieck