embgms03.gms : Test projection operator when loading data from embedded code

Description

Contributor: Michael Bussieck, January 2023


Small Model of Type : GAMS


Category : GAMS Test library


Main file : embgms03.gms

$title 'Test projection operator when loading data from embedded code' (EMBGMS03,SEQ=927)

$onText
Contributor: Michael Bussieck, January 2023
$offText


Parameter dataUniverse(*,*,*);
Set       d1Want / i1 /
          d2Want / j1, j2 /
          d3Want / k1, k3 /
          d1(*), d2(*), d3(*);

$macro checkIfAinB(a,b,Error) Set Error; Error(a) = not b(a); abort$card(Error) Error;

* Get set elements from specified dim of the parameter
$onEmbeddedCode GAMS:
  parameter dataUniverse / i1.j1.k1 11.9, i1.j2.k3 9.11 /;
$offEmbeddedCode d1<dataUniverse.dim1 d2<dataUniverse.dim2 d3<dataUniverse.dim3

checkIfAinB(d1,d1Want,Error1a)
checkIfAinB(d2,d2Want,Error2a)
checkIfAinB(d3,d3Want,Error3a)
checkIfAinB(d1Want,d1,Error1b)
checkIfAinB(d2Want,d2,Error2b)
checkIfAinB(d3Want,d3,Error3b)

Set       e1(*), e2(*), e3(*);
Parameter dataDomain(e1,e2,e3);

* Get set elements by domain matching of the parameter
$onEmbeddedCode GAMS:
  parameter dataDomain / i1.j1.k1 11.9, i1.j2.k3 9.11 /;
$offEmbeddedCode e1<dataDomain e2<dataDomain e3<dataDomain

checkIfAinB(e1,d1Want,Error1c)
checkIfAinB(e2,d2Want,Error2c)
checkIfAinB(e3,d3Want,Error3c)
checkIfAinB(d1Want,e1,Error1d)
checkIfAinB(d2Want,e2,Error2d)
checkIfAinB(d3Want,e3,Error3d)


Set       f1(*);
Parameter dataDomainF1(f1,f1,f1);

* Get set elements by domain matching of the parameter, start searching from the left
$onEmbeddedCode GAMS:
  parameter dataDomainF1 / i1.j1.k1 11.9, i1.j2.k3 9.11 /;
$offEmbeddedCode f1<=dataDomainF1

checkIfAinB(f1,d1Want,Error1e)
checkIfAinB(d1Want,f1,Error1f)

Set       f2(*);
Parameter dataDomainF2(f2,f2,f2);

* Get set elements by domain matching of the parameter, start searching from the right
$onEmbeddedCode GAMS:
  parameter dataDomainF2 / i1.j1.k1 11.9, i1.j2.k3 9.11 /;
$offEmbeddedCode f2<dataDomainF2

checkIfAinB(f2,d3Want,Error3e)
checkIfAinB(d3Want,f2,Error3f)

* Load filtered data - This example lead to an error at some stage because of out-of-order UELs when writing to GDX, see #5016
Set code, labId, rr(code,labId);
parameter raw(*,*,*);

$onEmbeddedCode GAMS:
parameter raw; set rr;
$gdxin getdata.gdx
$load raw rr
$offEmbeddedCode code<raw.dim1 labId<raw.dim2 rr

execute_unload 'dd.gdx' rr;

* For the following operations we expect failures

$onEcho > noDomMatch.gms
Parameter dataUniverse(*,*,*);
Set       d1(*), d2(*), d3(*);

$onEmbeddedCode GAMS:
  parameter dataUniverse / i1.j1.k1 11.9, i1.j2.k3 9.11 /;
$offEmbeddedCode d1<dataUniverse d2<dataUniverse d3<dataUniverse
$offEcho

$call gams noDomMatch.gms lo=%GAMS.lo%
$if not errorlevel 1 $abort Expected error from noDomMatch.gms

$onEcho > noParameter.gms
Parameter dataUniverse(*,*,*);
Parameter d1(*), d2(*), d3(*);

$onEmbeddedCode GAMS:
  parameter dataUniverse / i1.j1.k1 11.9, i1.j2.k3 9.11 /;
$offEmbeddedCode d1<dataUniverse.dim1 d2<dataUniverse.dim2 d3<dataUniverse.dim3
$offEcho

$call gams noParameter.gms lo=%GAMS.lo%
$if not errorlevel 1 $abort Expected error from noParameter.gms

$onEcho > wrongDim.gms
Parameter dataUniverse(*,*,*);
Set       d1(*,*), d2(*,*,*), d3(*,*,*);

$onEmbeddedCode GAMS:
  parameter dataUniverse / i1.j1.k1 11.9, i1.j2.k3 9.11 /;
$offEmbeddedCode d1<dataUniverse.dim1 d2<dataUniverse.dim2 d3<dataUniverse.dim3
$offEcho

$call gams wrongDim.gms lo=%GAMS.lo%
$if not errorlevel 1 $abort Expected error from wrongDim.gms