load17.gms : Test $declareAndLoad and $gdxLoadAll

Description

Test the dollar control options $gdxLoadAll and $declareAndLoad which allow a
convenient import of all (even undeclared) symbols from a GDX file at compile
time.

Contributor: Lutz Westermann, March 2023


Small Model of Type : GAMS


Category : GAMS Test library


Main file : load17.gms

$title 'Test $declareAndLoad and $gdxLoadAll' (LOAD17,SEQ=938)

$onText
Test the dollar control options $gdxLoadAll and $declareAndLoad which allow a
convenient import of all (even undeclared) symbols from a GDX file at compile
time. 

Contributor: Lutz Westermann, March 2023
$offText


* Generate some input
$call.checkErrorLevel gamslib -q 1
$call.checkErrorLevel gams trnsport gdx=trns lo=%GAMS.lo%

* $declareAndLoad should take everything
$echo $declareAndLoad trns.gdx > test.gms
$call.checkErrorLevel gams test.gms gdx=test lo=%GAMS.lo%
$call.checkErrorLevel gdxdiff trns.gdx test.gdx > %system.NullFile%

* $declareAndLoad should take everything - also if there is some (matching) declaration already
$onEcho > test.gms
Set i;
Scalar f;
Variable x(*,*);
$declareAndLoad trns.gdx 
$offEcho
$call.checkErrorLevel gams test.gms gdx=test lo=%GAMS.lo%
$call.checkErrorLevel gdxdiff trns.gdx test.gdx > %system.NullFile%

* $declareAndLoad should take everything - also if there is some (matching) declaration already, even with "wrong" data, if we use $onMultiR
$onEcho > test.gms
Set i / 'chicago', 'brunswick' /;
Scalar f / 89 /;
Variable x(*,*);
$onMultiR
$declareAndLoad trns.gdx 
$offEcho
$call.checkErrorLevel gams test.gms gdx=test lo=%GAMS.lo%
$call.checkErrorLevel gdxdiff trns.gdx test.gdx > %system.NullFile%

* $declareAndLoad should throw an error, if we have data already for symbols to be loaded and $onMulti[R] is not set
$onEcho > test.gms
Set i / 'chicago', 'brunswick' /;
Scalar f / 89 /;
Variable x(*,*);
$declareAndLoad trns.gdx 
$offEcho
$call gams test.gms gdx=test lo=%GAMS.lo%
$ifE errorLevel==0 $abort Expected error in line %system.IncLine%

* $declareAndLoad should throw an error, if we have a mismatching declaration
$onEcho > test.gms
Set i(*,*);
Equation f;
Variable x(*);
$declareAndLoad trns.gdx 
$offEcho
$call gams test.gms gdx=test lo=%GAMS.lo%
$ifE errorLevel==0 $abort Expected error in line %system.IncLine%

**************************

* $gdxLoadAll should take everything that is known
$onEcho > test.gms
Set i, j;
Parameter a(i), b(j), d(i,j), f, c(i,j);
Variable x(i,j), z;
Equation cost, supply(i), demand(j);
$gdxLoadAll trns.gdx 
$offEcho
$call.checkErrorLevel gams test.gms gdx=test lo=%GAMS.lo%
$call.checkErrorLevel gdxdiff trns.gdx test.gdx > %system.NullFile%

* $gdxLoadAll should take everything that is known - also if there is some (matching) declaration already, even with "wrong" data, if we use $onMultiR
$onEcho > test.gms
Set i / 'London' /, j;
Parameter a(i), b(j), d(i,j), f / 91 /, c(i,j);
Variable x(i,j), z;
Equation cost, supply(i), demand(j);
$onMultiR
$gdxLoadAll trns.gdx 
$offEcho
$call.checkErrorLevel gams test.gms gdx=test lo=%GAMS.lo%
$call.checkErrorLevel gdxdiff trns.gdx test.gdx > %system.NullFile%

* $gdxLoadAll should throw an error, if we have data already for symbols to be loaded and $onMulti[R] is not set
$onEcho > test.gms
Set i / 'London' /, j;
Parameter a(i), b(j), d(i,j), f / 91 /, c(i,j);
Variable x(i,j), z;
Equation cost, supply(i), demand(j);
$gdxLoadAll trns.gdx 
$offEcho
$call gams test.gms gdx=test lo=%GAMS.lo%
$ifE errorLevel==0 $abort Expected error in line %system.IncLine%

* $declareAndLoad should throw an error, if we have a mismatching declaration
$onEcho > test.gms
Set i(*,*);
Equation f;
Variable x(*);
$gdxLoadAll trns.gdx 
$offEcho
$call gams test.gms gdx=test lo=%GAMS.lo%
$ifE errorLevel==0 $abort Expected error in line %system.IncLine%