gdxmrw_wgdx01_init.gms : Writing structured data into a GDX file with WGDX

Description

Initialization: Write "wgdx01.m" and "foo1GAMS.gdx"

The program demonstrates writing a Matlab structure into a GDX file.

Intended use: interactive Matlab session

Contributor: Toni Lastusilta


Category : GAMS Data Utilities library


Main file : gdxmrw_wgdx01_init.gms   includes :  gdxmrw_wgdx01_init.gms

$Title Writing structured data into a GDX file with WGDX

$ontext
Initialization: Write "wgdx01.m" and "foo1GAMS.gdx"

The program demonstrates writing a Matlab structure into a GDX file.

Intended use: interactive Matlab session

Contributor: Toni Lastusilta

$offtext


*Write Matlab program
$onecho > wgdx01.m
% Using WGDX to write structured data into a GDX file

%Write foo1.gdx
%Specify set l and parameter matrix par
s1.name = 'l';
s1.uels = {{'i1', 'i2', 'i3'}, {'j1', 'j2'}};
c.name = 'par';
c.type = 'parameter';
c.val = eye(3);
c.form = 'full';
c.ts = '3 x 3 identity';
wgdx('foo1', s1, c);
gdxWhos('foo1.gdx');

%Define function: Generate a Unique Element Labels listing (gUEL)
guel = @(s,v) strcat(s,strsplit(num2str(v)));

%Write foo2.gdx
%Specify set l and l2
s2.name = 'l';
s2.uels = {guel('i',1:20),guel('j',1:40)};
s3.name = 'l2';
s3.uels = {guel('i',1:20),guel('j',1:40)};
s3.val = [1, 1; 2, 1; 3, 6; 4, 7];
%Specify parameters: scalar sval and parameter vector pval
s4.name = 'sval';
s4.val = 2;
s4.type = 'parameter';
s4.dim=0;
s4.ts = 'A zero dimensional scalar';
s5.name = 'pval';            %symbol name
s5.val = [2,4,6];            %value
s5.type = 'parameter';       %set/parameter
s5.form ='full';             %full/sparse
s5.uels={guel('i',1:3)};     %Unique Element Labels
s5.dim =1;                   %dimension
s5.ts = 'Vector - A one dimensional parameter';  %Text for Symbol
wgdx('foo2',s2,s3,s4,s5);
gdxWhos('foo2.gdx');

%Specify sets empty, one, two, three
s6.name = 'empty';
s6.uels = {{}};
s7.name = 'one';
s7.form = 'full';
s7.dim =1;
s7.uels = {{'i1','i2'}};
s7.val=[0 1];
s8.name = 'two';
s8.form = 'sparse';
s8.dim =1;
s8.uels = {{'i1','i2','i3'}};
s8.val=[1;3];
s9.name = 'three';
s9.form = 'sparse';
s9.dim =2;
s9.uels ={guel('i',1:4),guel('j',1:4)};
s9.val=[1,3 ;2,2 ;4,4];
wgdx('foo3',s6,s7,s8,s9);
gdxWhos('foo3.gdx');
%gdxInfo('foo3.gdx');

open wgdx01.m
$offecho


* Write fooGAMS.gdx
set a /i1*i3/;
set b /j1*j2/;
set l(a,b);
l(a,b) = yes;
Execute_unload 'foo1GAMS.gdx' l;


*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%;wgdx01" -nosplash -nodisplay';
$endIf