GDXXRWExample19.gms : Writing Parameter to Spreadsheet including Zero Values

Description

This model demonstrates two approaches for writing zero values of a parameter
to spreadsheet using GDXXRW. The first approach uses the epsOut option to write
zero's to spreadsheet, after all zero values within the parameter have been
stored as EPS, while the second approach regarding variables will exploit the
squeeze option to write zeros of the .l subfield to spreadsheet.

This model is referenced in "Writing Parameter to Spreadsheet including Zero
Values" from the GDXXRW Documentation.


Category : GAMS Data Utilities library


Main file : GDXXRWExample19.gms   includes :  GDXXRWExample19.gms

$title Writing Parameter to Spreadsheet including Zero Values (GDXXRWExample19,SEQ=121)

$onText
This model demonstrates two approaches for writing zero values of a parameter
to spreadsheet using GDXXRW. The first approach uses the epsOut option to write
zero's to spreadsheet, after all zero values within the parameter have been
stored as EPS, while the second approach regarding variables will exploit the
squeeze option to write zeros of the .l subfield to spreadsheet.

This model is referenced in "Writing Parameter to Spreadsheet including Zero
Values" from the GDXXRW Documentation.
$offText

Set i / i1*i9 /;
Parameter A(i), Amod(i);
A(i) = uniformInt(0,1);

* Amod(i) = A(i) if A(i) <> 0 and Amod(i) = EPS if A(i) = 0
Amod(i) = EPS$(not A(i)) + A(i);

* Unload the unmodified and modified parameter and write to spreadsheet using an option file
execute_unload 'zeroPar1.gdx' A Amod;

$onEcho > howToWrite1.txt
text="Parameter A" rng=A1
par=A rng=A2
text="Modified Parameter Amod written with epsOut: 0" rng=A5
epsOut=0 par=Amod rng=A6
$offEcho
execute 'gdxxrw zeroPar1.gdx output=writingZeros.xlsx @howToWrite1.txt trace=0';

Variable dummyPar(i);
dummyPar.l(i) = A(i);

* In order to write every entry of dummyPar in the spreadsheet, one must allocate
* a non-zero value to one of the variable attributes .m, .lo or .up
dummyPar.up(i) = 1;

* Unload the dummy variable and write the .l subfield to spreadsheet while disabling squeeze
execute_unload 'zeroPar2.gdx' dummyPar;

$onEcho > howToWrite2.txt
text="Variable dummyPar written with squeeze: n" rng=A9
squeeze=n var=dummyPar.l rng=A10
$offEcho
execute 'gdxxrw zeroPar2.gdx output=writingZeros.xlsx @howToWrite2.txt trace=0';