Item type

Top  Previous  Next

A named item in a GAMS program can be one of eight fundamental types.  They are set, parameter, model, variable, equation, file, acronym, or function.  A conditional can be structured to test whether a passed argument or named item is of a particular type and in turn invoke type specific processing.  The syntax then would be one of the following where the text in pink is not part of the statement but rather a definition

 

$If acrtype itemname gamsstatement  is this item an acronym

$If equtype itemname gamsstatement  is this item an equation

$If funtype itemname gamsstatement  is this item a GAMS function

$If modtype itemname gamsstatement  is this item a model

$If filtype itemname gamsstatement  is it a local name for put file

$If partype itemname gamsstatement  is this item a parameter

$If settype itemname gamsstatement  is this item a set

$If vartype itemname gamsstatement  is this item a variable

 

If the item identified by itemname is the type signified by the keyword with the prefix and the word type the subsequent gamsstatement would be entered into the active code and executed.  If not the command is skipped.

Example:

(iftype.gms)

set itemname;

$If acrtype itemname  display "itemname is an acronym";

$If equtype itemname  display "itemname is an equation";

$If funtype itemname  display "itemname is a GAMS function";

$If modtype itemname  display "itemname is an model";

$If filtype itemname  display "itemname is localname for put file";

$If partype itemname  display "itemname is a parameter";

$If settype itemname  display "itemname is a set";

$If vartype itemname  display "itemname is a variable";

$If xxxtype itemname  display "%itemname% is a xxx";

$If pretype itemname  display "%itemname% is a pre";

$If protype itemname  display "%itemname% is a pro";

 

results in

 

 3        set itemname;

10 display "itemname is a set";

 

One also can use a batinclude version iftypeinc.gms as is included by calliftypeinc.gms

 

$If acrtype %1  display "%1 is an acronym";

$If equtype %1  display "%1 is an equation";

$If funtype %1  display "%1 is a GAMS function";

$If modtype %1  display "%1 is an model";

$If filtype %1  display "%1 is localname for put file";

$If partype %1  display "%1 is a parameter";

$If settype %1  display "%1 is a set";

$If vartype %1  display "%1 is a variable";

 

$If xxxtype %1  display "%1 is a xxx";

$If pretype %1  display "%1 is a pre";

$If protype %1  display "%1 is a pro"

 

along with (Iftype.gms)

 

set aset;

acronym acro;

$batinclude iftypeinc aset

$batinclude iftypeinc acro

$batinclude iftypeinc sqrt

 

results in

 

  17  set aset;

  18  acronym acro;

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

  28  display "aset is a set";

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

  37  display "acro is an acronym";

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

  54  display "sqrt is a GAMS function";