single02.gms : Check assignment to singleton sets

Description

This test checks the behavior of assignments to Singleton Sets.

Contributor: Lutz Westermann, February 2014


Small Model of Type : GAMS


Category : GAMS Test library


Main file : single02.gms

$title 'Check assignment to singleton sets' (SINGLE02,SEQ=641)

$onText
This test checks the behavior of assignments to Singleton Sets.

Contributor: Lutz Westermann, February 2014
$offText


* Define macro for tests below
$macro notSame(a,b,size) sum(i$(a(i) and not(b(i))),1) + sum(i$(b(i) and not(a(i))),1) <> 0 or card(iHave) <> size

Set           i         /i1*i3/;
Singleton Set iWant(i)  /   i3/
              iHave(i)  /   i3/;

* Obvious: After same definition
abort$[notSame(iWant,iHave,1)] 'iWant <> iHave', iWant, iHave;

* New assignment should clear content first
iWant('i2') = yes;
iHave('i2') = yes;
abort$[notSame(iWant,iHave,1)] 'iWant <> iHave', iWant, iHave;

* New assignment should clear content first, even if nothing is assigned
option clear=iWant;
iHave(i) = 1=0;
abort$[notSame(iWant,iHave,0)] 'iWant <> iHave', iWant, iHave;

* With $onStrictSingleton data statements for a Singleton Set with more than one entry is NOT allowed
$onEcho > onStrictSingleton.gms
$onStrictSingleton
Set           i    /i1*i3/;
Singleton Set d(i) /i2,i3/;
$offEcho
execute 'gams onStrictSingleton.gms lo=%GAMS.lo%';
abort$(errorlevel=0) 'Error for onStrictSingleton.gms expected';

* With $offStrictSingleton data statements for a Singleton Set with more than one entry is allowed
$onEcho > offStrictSingleton.gms
$offStrictSingleton
Set           i    /i1*i3/;
Singleton Set d(i) /i2,i3/;
abort$[card(d) <> 1] 'bad d card';
abort$[sum{d(i), 1$sameas('i2',i)} <> 1] 'bad d element';
$offEcho
execute 'gams offStrictSingleton.gms lo=%GAMS.lo%';
abort$[errorlevel<>0] 'Error for offStrictSingleton.gms not expected';

* now test strictSingleton={0,1}
option StrictSingleton=0;
* in non-strict mode with multiple records on the right of an
* assignment, a singleton set should get the first one
iWant('i1') = yes;
iHave(i)    = yes;
abort$[execerror > 0] 'Execution error setting singleton';
abort$[notSame(iWant,iHave,1)] 'iWant <> iHave', iWant, iHave;

* With option StrictSingleton=1; multiple assignment to a Singleton Set is not allowed
option StrictSingleton=1;
iHave(i)    = yes;
abort$[execerror = 0] 'Error with option StrictSingleton=1 expected';
execerror = 0;