gdxmrw_ext01_init.gms : Extended use of GDXMRW

Description

Initialization: Write "sample.gdx", "ext01.m" and "trnsport.gms"

Running Matlab program ext1.m will read special values from sample.gdx.
Furthermore, it runs the GAMS program trnsport.gms and displays the
model and solver status, as well as, the objective variable value.

Intended use: interactive Matlab session

Contributor: Toni Lastusilta


Category : GAMS Data Utilities library


Main file : gdxmrw_ext01_init.gms   includes :  gdxmrw_ext01_init.gms

$Title Extended use of GDXMRW

$ontext
Initialization: Write "sample.gdx", "ext01.m" and "trnsport.gms"

Running Matlab program ext1.m will read special values from sample.gdx.
Furthermore, it runs the GAMS program trnsport.gms and displays the
model and solver status, as well as, the objective variable value.

Intended use: interactive Matlab session

Contributor: Toni Lastusilta

$offtext


* Write sample.gdx
set l /1*4/;
Parameter special(l) /1 -Inf, 2 Na, 3 [pi], 4 Inf/;

set i        /1*2/
    j        /j1*j2/
    el(i,j)  This is 2D set with text elements /
    1.j1 element1
    1.j2 element2
    2.j1
   /;
Execute_Unload 'sample.gdx', special, el;


*Write Matlab program
$onecho > ext01.m
% Extended use of GDXMRW

%Read special values
s.name = 'special';
s.form = 'full';
s.compress = true;
x = rgdx('sample', s)
x_val=x.val

%Display text elements
s1.name = 'el';
s1.te = true;
s1.ts = true;
s1.compress = true
z = rgdx('sample', s1)
z_te=z.te
z_val=z.val

%Run GAMS model trnsport.gms and retrieve
%model and solver status, as well as, the objective variable value.
gamso.output = 'std';
gamso.form = 'full';
gamso.compress = true;
s2 = gams('trnsport')

%However, the recommended way is to use "system 'gams ...'", e.g.:
% system 'gams trnsport lo=3 gdx=output';
% returnsymbol.name = 'returnStat';
% ret=rgdx('output.gdx',returnsymbol);
% ret.val(:,2)
% uels=ret.uels{1}';uelnr=ret.val(:,1);value=ret.val(:,2);
% summary=[uels(uelnr) num2cell(value)]

open ext01.m
$offecho


*Retrieve and append to GAMS Model Library example trnsport.gms
$call gamslib trnsport
$onecho >> trnsport.gms
$set matout "'matsol.gdx', returnStat, str ";
set stat /modelstat,solvestat,objval/;
set str /'grunt', '%system.title%'/;
parameter returnStat(stat);
returnStat('modelstat') = transport.modelstat;
returnStat('solvestat') = transport.solvestat;
returnStat('objval')    = transport.objval;
execute_unload %matout%;
$offecho


*Call Matlab
$set WHICH which
$if not %system.filesys% == UNIX $set WHICH where
$call %WHICH% matlab
$ifThen errorLevel 1
$clearError
$abort.noerror 'Matlab is not available!';
$else
*Call Matlab at execution time
Execute.ASync 'matlab -r "cd %GAMS.cdir%;ext01" -nosplash -nodisplay'; 
$endIf