User Tools

Site Tools


A Loop with GDXXRW.exe

Q: I am solving a model for several levels in one parameter (comparative statics) and would like to store the results in excel. I would like to store the results for a particular variable in the same worksheet, having just one spreadsheet for the whole solution. The problem is that I do not know how to tell the program to go to the next line after each solution!

Have a look at the example below using the trnsport model from our library. We prepare an area for a report. After the first solve, we clear the report area before merging. Subsequent solves just merge the data in the report area.

$call'=gamslib trnsport'
$include trnsport.gms
set pv /pv1*pv7/;
set flds /seattle, san-diego, obj/;
execute_unload 'pv.gdx', pv, flds;
execute 'gdxxrw pv.gdx set=pv rng=a2 rdim=1 cdim=0 set=flds rng=b1 rdim=0 cdim=1';
execute 'shellexecute pv.xls';

parameter report(pv, flds);


  Solve transport using lp minimizing z ;
  report(pv, 'obj') = z.L;
  report(pv, 'seattle') = a('seattle');
  report(pv, 'san-diego') = a('san-diego');
  display report;
  execute_unload 'pv.gdx', report;
* we clear the data the first time
     execute 'gdxxrw pv.gdx par=report rng=a1 rdim=1 cdim=1 clear';
* other times e merge the data without overwriting existing data
     execute 'gdxxrw pv.gdx par=report rng=a1 rdim=1 cdim=1 merge';
* clear the row
  report(pv, flds) = 0;
* change the capacities
  a('seattle') = a('seattle') - 50.0;
  a('san-diego') = a('san-diego') + 50.0;
execute 'shellexecute pv.xls';
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY interfaces/a_loop_with_gdxxrw.exe.txt · Last modified: 2007/08/07 12:34 (external edit)