zerotoeps1.gms : Test data loading with $onEps and option zeroToEps

Description

With $onEps (compile time) and option zeroToEps=on one can change the data loading
behavior, so that 0 values get loaded as EPS. This influences non-scalar
parameters and sets.

Contributor: Lutz Westermann, May 2020


Small Model of Type : GAMS


Category : GAMS Test library


Main file : zerotoeps1.gms

$Title Test data loading with $onEps and option zeroToEps (zerotoeps1,SEQ=821)

$ontext
With $onEps (compile time) and option zeroToEps=on one can change the data loading
behavior, so that 0 values get loaded as EPS. This influences non-scalar
parameters and sets.

Contributor: Lutz Westermann, May 2020
$offtext


$log --- Using Python library %sysEnv.GMSPYTHONLIB%



Set s,t;
Parameter p(s<,t<);

$gdxIn zeropar.gdx
$onText
P looks like this:
   t1        t2        t3
s1 0         0.843267  
s2 0.224053  0.349831  0
s3           0         5
$offText
$load p
abort$(card(p)<>4) 'By default, p should ignore the 0 values and have 4 records', p;

Set sp(s,t);
$load sp=p
abort$(card(sp)<>7) 'sp get records also for zeros and should have 7 records', sp;

Parameter pEC(s);
$onEmbeddedCode Python:
p = [('s1',1), ('s3',0)]
gams.set('pEC',p)
$offEmbeddedCode pEC
abort$(card(pEC)<>1) 'By default, pEC should ignore the 0 values and have 1 record', pEC;


$onEps
Parameter pOnEps(s,t);
$load pOnEps=p
abort$(card(pOnEps)<>7) 'With $onEps, 0 values should be read as EPS and pOnEps should have 7 records', pOnEps;

Set spOnEps(s,t);
$load spOnEps=p
abort$(card(spOnEps)<>7) 'spOnEps get records also for zeros and should have 7 records', spOnEps;

Parameter pECOnEps(s);
$onEmbeddedCode Python:
p = [('s1',1), ('s3',0)]
gams.set('pECOnEps',p)
$offEmbeddedCode pECOnEps
abort$(card(pECOnEps)<>2) 'With $onEps, 0 values should be read as EPS and pECOnEps should have 2 records', pECOnEps;

Parameter pET(s,t);
Set       spET(s,t);
Execute_load 'zeropar.gdx', pET=p, spET=p;
abort$(card(pET) <>4) 'By default, pET should ignore the 0 values and have 4 records', pET;
abort$(card(spET)<>4) 'By default, spET should ignore the 0 values and have 4 records', spET;

Parameter pECET(s);
EmbeddedCode Python:
p = [('s1',1), ('s3',0)]
gams.set('pECET',p)
endEmbeddedCode pECET
abort$(card(pECET)<>1) 'By default, pECET should ignore the 0 values and have 1 record', pECET;


option zeroToEps=on;
Parameter pETOnEps(s,t);
Set       spETOnEps(s,t);
Execute_load 'zeropar.gdx', pETOnEps=p, spETOnEps=p;
abort$(card(pETOnEps) <>7) 'With zeroToEps=on, pETOnEps should read the 0 values as EPS and have 7 records', pETOnEps;
abort$(card(spETOnEps)<>7) 'With zeroToEps=on, spETOnEps should read the 0 values as EPS and have 7 records', spETOnEps;

Parameter pECETOnEps(s);
EmbeddedCode Python:
p = [('s1',1), ('s3',0)]
gams.set('pECETOnEps',p)
endEmbeddedCode pECETOnEps
abort$(card(pECETOnEps)<>2) 'With zeroToEps=on, pECETOnEps should read the 0 values as EPS and have 2 records', pECETOnEps;