Description
With GAMS 25.2 we introduced the new dollar control option "$onMultiR" which works similar to "$onMulti" but replaces existing data instead of merging into it. Here we test for the expected behavior. Contributor: Lutz Westermann, October 2018 $onMultiR does not extend existing data but replaces it
Small Model of Type : GAMS
Category : GAMS Test library
Main file : onmulti8.gms
$title 'Test for $onMultiR' (ONMULTI8,SEQ=787)
$onText
With GAMS 25.2 we introduced the new dollar control option "$onMultiR" which
works similar to "$onMulti" but replaces existing data instead of merging into
it. Here we test for the expected behavior.
Contributor: Lutz Westermann, October 2018
$offText
* $onMultiR does not extend existing data but replaces it
$onEcho > test.gms
set i / a, b /;
$onMultiR
set i / c /;
Alias(u,*);
Set iWant / c /
iTest(u);
iTest(u) = iWant(u) xor i(u);
abort$card(iTest) iTest;
$offEcho
$call gams test.gms lo=%GAMS.lo%
$ifE errorLevel<>0 $abort Problem in line %system.line%
* $onMultiR does also change dependent sets, if a domain set gets reduced
$onEcho > test.gms
set i / a, b, c /;
Parameter p(i) / #i 2 /;
Variable v(i) / #i.l 3 /;
$onMultiR
Set i / c, d /;
Alias(u,*);
Parameter pWant(u) / c 2 /;
Variable vWant(u) / c.l 3 /;
Set pTest(u),
vTest(u);
pTest(i) = pWant(i) <> p(i);
abort$card(pTest) 'Problem in line %system.line%', pTest;
vTest(i) = vWant.l(i) <> v.l(i);
abort$card(vTest) 'Problem in line %system.line%', vTest;
$offEcho
$call gams test.gms lo=%GAMS.lo% gdx iCD
$ifE errorLevel<>0 $abort Problem in line %system.line%
* $onMultiR should also work with a table
$onEcho > test.gms
set i / i1*i3 /
ii(i,i) / #i.#i /;
Table t(i,i)
i1 i2 i3
i1 1 2 3
i2 4 5 6
i3 7 8 9 ;
$onMultiR
Table t(i,i)
i1 i3
i2 4 6
i3 9 ;
Set Table ti(i,i)
i1 i3
i2 4 6
i3 9 ;
Table tWant(i,i)
i1 i3
i2 4 6
i3 9 ;
Set Table tiWant(i,i)
i1 i3
i2 4 6
i3 9 ;
Set tTest (i,i)
tiTest(i,i);
Alias (i,j);
tTest(i,j) = tWant(i,j) <> t(i,j);
abort$card(tTest) 'Problem in line %system.line%', tTest;
tiTest(i,j) = tiWant(i,j) xor ti(i,j);
abort$card(tTest) 'Problem in line %system.line%', tTest;
$offEcho
$call gams test.gms lo=%GAMS.lo%
$ifE errorLevel<>0 $abort Problem in line %system.line%
* $onMultiR should also work with $loadR; also with domain sets
$onEcho > test.gms
set i / a, b, c /;
Parameter p(i) / #i 2 /;
$onMultiR
$gdxIn iCD.gdx
$loadR i
Alias(u,*);
Parameter pWant(u) / c 2 /;
Set pTest(u);
pTest(i) = pWant(i) <> p(i);
abort$card(pTest) 'Problem in line %system.line%', pTest;
$offEcho
$call gams test.gms lo=%GAMS.lo%
$ifE errorLevel<>0 $abort Problem in line %system.line%
* $onMultiR should also work with $load (should behave the same as $loadR); also with domain sets
$onEcho > test.gms
set i / a, b, c /;
Parameter p(i) / #i 2 /;
$onMultiR
$gdxIn iCD.gdx
$load i
Alias(u,*);
Parameter pWant(u) / c 2 /;
Set pTest(u);
pTest(i) = pWant(i) <> p(i);
abort$card(pTest) 'Problem in line %system.line%', pTest;
$offEcho
$call gams test.gms lo=%GAMS.lo%
$ifE errorLevel<>0 $abort Problem in line %system.line%
* $onMultiR should also work with $loadM; also with domain sets
$onEcho > test.gms
set i / a, b, c /;
Parameter p(i) / #i 2 /;
$onMultiR
$gdxIn iCD.gdx
$loadM i
Alias(u,*);
Set iWant / a, b, c, d /;
Parameter pWant(u) / (a, b, c) 2 /;
Set iTest(u)
pTest(u);
iTest(u) = iWant(u) xor i(u);
abort$card(iTest) iTest;
pTest(i) = pWant(i) <> p(i);
abort$card(pTest) 'Problem in line %system.line%', pTest;
$offEcho
$call gams test.gms lo=%GAMS.lo%
$ifE errorLevel<>0 $abort Problem in line %system.line%
* $onMultiR should also work with empty data statements ($onEmpty); also with domain sets
$onEcho > test.gms
set i / a, b, c /;
Parameter p(i) / #i 2 /;
$onMultiR
$onEmpty
Set i / /;
abort$card(p) 'Problem in line %system.line%', p;
$offEcho
$call gams test.gms lo=%GAMS.lo%
$ifE errorLevel<>0 $abort Problem in line %system.line%
* $onMultiR should also work with var/equ data statements
$onEcho > test.gms
set i / a, b, c /;
Variable v(i) / #i.l 3 /;
Variable Table w(i)
l
a 1
b 2
c 3
;
$onMultiR
Variable v(i) / c.l 3 /;
Variable Table w(i)
l
b 2
;
Alias(u,*);
Variable vWant(u) / c.l 3 /
wWant(u) / b.l 2 /;
Set vTest(u)
wTest(u);
vTest(i) = vWant.l(i) <> v.l(i);
abort$card(vTest) 'Problem in line %system.line%', vTest;
wTest(i) = wWant.l(i) <> w.l(i);
abort$card(wTest) 'Problem in line %system.line%', wTest;
$offEcho
$call gams test.gms lo=%GAMS.lo%
$ifE errorLevel<>0 $abort Problem in line %system.line%
* $onMultiR should allow to redefine equations
$onEcho > test.gms
Variable v, z;
Equation e;
v.fx = 1;
e.. z =e= v;
$onMultiR
e.. z =e= 2*v;
model m /e/;
solve m use lp min z;
abort$(z.l <> 2) 'Problem in line %system.line%', z.l;
$offEcho
$call gams test.gms lo=%GAMS.lo%
$ifE errorLevel<>0 $abort Problem in line %system.line%
* $onMultiR should also work with $load while redefining a domain set
$onEchoV > data.gms
Set i / %uels% /
Parameter p(i) / #i 1 /;
$offEcho
$onEchoV > test.gms
Set i /1*5/;
Parameter p(i);
$gdxIn data.gdx
$onMultiR
$load p i p
display p,i;
Alias(u,*);
Parameter pWant(u) / (%uels%) 1 /;
Set pTest(u);
pTest(i) = pWant(i) <> p(i);
abort$card(pTest) 'Problem in line %system.line%', pTest;
$offEcho
$call.checkErrorLevel gams data.gms gdx=data.gdx lo=%GAMS.lo% --uels="1*10"
$call gams test.gms lo=%GAMS.lo% --uels="1*10"
$ifE errorLevel<>0 $abort Problem in line %system.line%
$call.checkErrorLevel gams data.gms gdx=data.gdx lo=%GAMS.lo% --uels="A*E"
$call gams test.gms lo=%GAMS.lo% --uels="A*E"
$ifE errorLevel<>0 $abort Problem in line %system.line%