Version:

limdom03.gms : Test the syntax of the model statement for limited domains for variables

**Description**

With GAMS 31 we introduced the capability to limit the domain of variables in the model statement. This test makes sure, that the syntax for this works as expected. Contributor: Lutz Westermann, March 2020

**Small Model of Type : ** GAMS

**Category :** GAMS Test library

**Main file : ** limdom03.gms

```
$Title Test the syntax of the model statement for limited domains for variables (limdom03,SEQ=814)
$ontext
With GAMS 31 we introduced the capability to limit the domain of variables
in the model statement. This test makes sure, that the syntax for this works
as expected.
Contributor: Lutz Westermann, March 2020
$offtext
Set i / i1 * i3 /
j / j1 * j3 /;
Set sub (i,j) /i2. j2 /
sub2(i,j) /i2.(j2,j3)/
sub3(j,j) /j2.(j2,j3)/
sub4(*,*) /i2.(j2,j3)/
sub5(i,j)
sub6;
Positive Variable x(i,j);
Variable z;
Equation obj Dummy objective function;
obj.. z =e= sum((i,j), x(i,j));
Model m1 / obj /;
solve m1 min z use lp;
abort$(m1.numVar<>10) 'Expected 10 variables in complete model'
Model m2 / obj, x(sub) /;
solve m2 min z use lp;
abort$(m2.numVar<>2) 'Expected 2 variables in DL model'
* This should be a noOpt
Model m3 / m1 - x /;
solve m3 min z use lp;
abort$(m3.numVar<>10) 'Expected 10 variables in complete model'
* This should be a noOpt
Model m4 / m1 - x(sub) /;
solve m4 min z use lp;
abort$(m4.numVar<>10) 'Expected 10 variables in complete model'
* This should remove the DL part of m2
Model m5 / m2 - x /;
solve m5 min z use lp;
abort$(m5.numVar<>10) 'Expected 10 variables in complete model'
* This should replace the previous defined DL part of m2
Model m6 / m2 + x(sub2) /;
solve m6 min z use lp;
abort$(m6.numVar<>3) 'Expected 3 variables in complete model'
*** The following examples should trigger errors ***
* This should give an error since x(sub2) was never added
Model e1 / m2 - x(sub2) /;
$if errorfree $abort 'This should give an error since x(sub2) was never added'
$clearerror
* This should give an error since x has a DL condition already
Model e2 / m2, x(sub2) /;
$if errorfree $abort 'This should give an error since x has a DL condition already'
$clearerror
* This should give an error since x needs a limiting set
Model e3 / obj, x /;
$if errorfree $abort 'This should give an error since x needs a limiting set'
$clearerror
* This should give an error since x needs a limiting set
Model e4 / obj + x /;
$if errorfree $abort 'This should give an error since x needs a limiting set'
$clearerror
* This should give an error since x and sub3 have no matching domain
Model e5 / obj + x(sub3) /;
$if errorfree $abort 'This should give an error since x and sub3 have no matching domain'
$clearerror
* This should give an error since x and sub4 have no matching domain
Model e6 / obj + x(sub4) /;
$if errorfree $abort 'This should give an error since x and sub4 have no matching domain'
$clearerror
* This should give an error since sub5 is not initialized
Model e7 / obj + x(sub5) /;
Solve e7 min z use lp;
$if errorfree $abort 'This should give an error since sub5 is not initialized'
$clearerror
* This should give an error since sub6 has no known dimension
Model e8 / obj + x(sub6) /;
$if errorfree $abort 'This should give an error since sub6 has no known dimension'
$clearerror
* This should give an error since we use a domain limitation on a variable with suffix
Equation suf;
suf.. z =l= sum((i,j), x.l(i,j));
Model e9 / obj, suf, x(sub) /;
Solve e9 min z use lp;
$if errorfree $abort 'This should give an error since we use a domain limitation on a variable with suffix'
$clearerror
* This should make the last error disappear
$onSuffixDLVars
Solve e9 min z use lp;
```