Page 1 of 1

Can I distinguish parameter value defined as zero vs default to zero

Posted: Mon Nov 08, 2021 3:21 am
by AndrewC
We are reading parameter data in from a GDX file (created using either GDXXRW and Excel or via Python depending on our application).

If the dataset did not have data entered for a given set of indexes, MY_PARAMETER(i,j) returns 0;
If the dataset did have data entered for a given set of indexes but that data was zero, MY_PARAMETER(i,j) returns 0;

Is there a way to determine if data was MISSING/NOT SPECIFIED vs explicitly set to zero when reading data from a GDX?

All help appreciated.

Re: Can I distinguish parameter value defined as zero vs default to zero

Posted: Tue Nov 09, 2021 11:37 am
by bussieck
GAMS is a sparse system and does not store zeros. If you want to store a 0 in GAMS you turn it into an EPS. Numerically EPS is truly 0 (not a small number) but it "exists". You can turn zeros (0) in data import into EPS with the compile time dollar control option $on/offEPS (see https://www.gams.com/36/docs/UG_DollarC ... ARonoffeps) or at execution with the option zeroToEPS (see https://www.gams.com/36/docs/UG_GamsCal ... Ozerotoeps). GDX does store true zeros so that this conversion works, but depending on the tool that wrote the GDX file (you mention GDXXRW) you might need to do some "extra" work that the zeros in Excel (or whatever your original data source is) make it as zeros into GDX. For example reading an Excel workbook with data like this
image.png
image.png (1.78 KiB) Viewed 2645 times
with the command "gdxxrw Book1.xlsx par=p rng=Sheet1!a1 rdim=1 cdim=0" the records with 0 don't make it into the GDX file:
image.png
image.png (3.49 KiB) Viewed 2645 times
adding the switch Squeeze=N to gdxxrw make the tool store default values (zeros for parameters) in GDX and we see the zeros stored in this case:
image.png
image.png (3.86 KiB) Viewed 2645 times
but the blank cell (with label "4") still did not make it as 0 into GDX.

If you read the latter GDX under default and display p:

Code: Select all

set i /1*4/; parameter p(i);
$gdxin Book1
$load p
display p;
you get:

Code: Select all

----      4 PARAMETER p  
1 EPS
If you add $onEPS before the $load you get

Code: Select all

----      5 PARAMETER p  
1 EPS,    2 EPS,    3 EPS
-Michael