gdxmrw updating problem

Hi folks,

I am working on a project that involves calling a GAMS model
iteratively from matlab, with outputs from the GAMS model being
processed in matlab to produce new inputs. I am using the rgdx and
wgdx functions in gdxmrw inside a matlab for loop to achieve this. The
code appears to work properly for one (sometimes more) passes through
the loop. However, when I start looping many times, either the input
file (to GAMS) or the output file stop updating and my results start
repeating. I have run the code on two computers (both Windows) and
strangely, the failure to update seems to happen after a different
number of passes through the loop. I am wondering whether this has
something to do with either matlab or GAMS not waiting for the input/
output files to be written/read before executing the next line of
code? Any thoughts?

David Luke

Dummy code:

GAMS file:
initialize_sets;
execute_load ‘inputfile.gdx’, inputstruct1, inputstruct2, …;
model_commands;
execute_unload ‘outputfile.gdx’, outputstruct1, outputstruct2, …;

Matlab file:
for i=1:L
wgdx(‘inputfile.gdx’,inputstruct1, inputstruct2,…);
system(‘gams gamsfile.gms’);
rgdx(‘outputfile.gdx’,outputstruct1, outputstruct2, …);
[inputstruct1, inputstruct2, …] = processData(outputstruct1,
outputstruct2, …);
end

\

Hello again,

I just resolved the problem. It turned out not to be a problem with
the Matlab interface, but rather with the GAMS code itself. It was a
logic error that only arose in rare cases, which explains why the
model ran through several iterations before failing. Thanks.

David Luke

On Aug 4, 9:20 am, dloates wrote:

Hi folks,

I am working on a project that involves calling a GAMS model
iteratively from matlab, with outputs from the GAMS model being
processed in matlab to produce new inputs. I am using the rgdx and
wgdx functions in gdxmrw inside a matlab for loop to achieve this. The
code appears to work properly for one (sometimes more) passes through
the loop. However, when I start looping many times, either the input
file (to GAMS) or the output file stop updating and my results start
repeating. I have run the code on two computers (both Windows) and
strangely, the failure to update seems to happen after a different
number of passes through the loop. I am wondering whether this has
something to do with either matlab or GAMS not waiting for the input/
output files to be written/read before executing the next line of
code? Any thoughts?

David Luke

Dummy code:

GAMS file:
initialize_sets;
execute_load ‘inputfile.gdx’, inputstruct1, inputstruct2, …;
model_commands;
execute_unload ‘outputfile.gdx’, outputstruct1, outputstruct2, …;

Matlab file:
for i=1:L
wgdx(‘inputfile.gdx’,inputstruct1, inputstruct2,…);
system(‘gams gamsfile.gms’);
rgdx(‘outputfile.gdx’,outputstruct1, outputstruct2, …);
[inputstruct1, inputstruct2, …] = processData(outputstruct1,
outputstruct2, …);
end

\