Tuesday, June 3, 2008

Any uglier syntax possible?

To compose a file name for a gdx file, one can do:

set mds /mds1*mds3/;
parameter x;

* needed for put_utility
file dummy;
put dummy;


* remove all gdx files
execute 'del /q *.gdx';

loop(mds,

* solve etc here

* say solution is x
x = ord(mds);
display x;

* filename := 'sol_mds1', 'sol_mds2', ....
put_utility 'gdxout' / 'sol_' mds.tl:0;

* write to gdx file with changed name
execute_unload x;
);

* show what gdx files we now have
execute 'dir *.gdx';

* merge gdx files
execute 'gdxmerge sol_*.gdx';

* show that it created merged.gdx
execute 'dir *.gdx';

* show content of merged.gdx
execute 'gdxdump merged.gdx';


In my experience this is very difficult to explain. The put_utility syntax should really be replaced by something more elegant (not a very high bar).

Notice that we need a put file around even if we don't use it. It should not be too difficult to hide this from the modeler and handle this inside GAMS.

No comments:

Post a Comment