Set dependency: Dimension

Top  Previous  Next

An item may be declared as being indexed by zero through 20 sets.  A conditional can be structured to determine how many sets are involved in the declaration.  The syntax then would be one of the following

To test if this item of dimension zero (a scalar)

 

$If dimension 0 itemname gamsstatement

 

To test if this item of dimension 1 (a  parameter with one index set -- a(i))

 

$If dimension 1 itemname gamsstatement

 

To test if this item of dimension 3 (a  parameter a(i,j,k))

 

$If dimension 3 itemname gamsstatement

 

Note cases 0-10 are allowed.

Example:

Suppose I use this syntax within a file that I will batinclude.  In that file I use conditionally compiled statements to change formatting of the option relative to the display of an item to reallocate the items in rows and columns dependent upon the number of sets that defines a passed named GAMS item.  In this case the file to batinclude is dimdisp.gms and call it with a single argument.

 

*testing %1

$If dimension  0 %1 display '%1 is 0 dimensional',%1;

$If dimension  1 %1 display '%1 is 1 dimensional',%1;

$If dimension  2 %1 option %1:0:1:1;display '%1 is  2 dimensional',%1;

$If dimension  3 %1 option %1:0:1:2;display '%1 is  3 dimensional',%1;

$If dimension  4 %1 option %1:0:1:3;display '%1 is  4 dimensional',%1;

$If dimension  5 %1 option %1:0:1:4;display '%1 is  5 dimensional',%1;

$If dimension  6 %1 option %1:0:2:4;display '%1 is  6 dimensional',%1;

$If dimension  7 %1 option %1:0:2:5;display '%1 is  7 dimensional',%1;

$If dimension  8 %1 option %1:0:2:6;display '%1 is  8 dimensional',%1;

$If dimension  9 %1 option %1:0:2:7;display '%1 is  9 dimensional',%1;

$If dimension 10 %1 option %1:0:2:8;display '%1 is 10 dimensional',%1;

 

In turn suppose I call the file several times over with different objects are different dimensions (basicif.gms).

 

scalar eee /1/;

set set1 /a,b/;

set set2 /d,e/;

set set3 /1,2/;

set set4 /g,h/;

parameter fff(set1);

fff(set1)=1;

set ggg(set1,set2,set3,set4);

ggg(set1,set2,set3,set4)=yes;

parameter hhh(set1,set2,set3,set4,set4);

hhh(set1,set2,set3,set4,set4)=ord(set1)+ord(set4);

$batinclude dimdisp eee

$batinclude dimdisp set1

$batinclude dimdisp fff

$batinclude dimdisp ggg

$batinclude dimdisp hhh

 

The resultant code that is executed in the batinclude section is

 

BATINCLUDE C:\GAMS\GAMSPDF\BIGONE\DIMDISP.GMS

  86  display 'eee is 0 dimensional',eee;

BATINCLUDE C:\GAMS\GAMSPDF\BIGONE\DIMDISP.GMS

 100  display 'set1 is 1 dimensional',set1;

BATINCLUDE C:\GAMS\GAMSPDF\BIGONE\DIMDISP.GMS

 113  display 'fff is 1 dimensional',fff;

BATINCLUDE C:\GAMS\GAMSPDF\BIGONE\DIMDISP.GMS

 129  option ggg:0:1:3;display 'ggg is  4 dimensional',ggg;

BATINCLUDE C:\GAMS\GAMSPDF\BIGONE\DIMDISP.GMS

143option hhh:0:1:4;display 'hhh is  5 dimensional',hhh;

 

Note that each time the batinclude file is called that only one of the 11 different display statements becomes active.  Also note that the one that is chosen corresponds to the dimension of the named item used as an argument in the batinclude.