GAMS advanced syntax From McCarl Guide From own guess-based experiments
System Attributes
Gams Attributes
System Attributes System.<attribute> Parameter report1(*); Set report2(*); report1("memory")=%system.memory%; report2("%system.date%")=yes; display report1,report2;
GAMS Attributes Command line arguments gams.<attribute> Parameter report1(*); Set report2(*); report1(“lpsolver")=%gams.lp%; report2("%gams.lp%")=yes; display report1,report2;
GAMS Timing Compilation Syntax check $control operations Execution Syntax execution
At Execution Time Execute normal GAMS syntax: Data(Set)=normal(10,2); Solve, If, Sum, Smin, Loop, … Execute, Execute_unload Option, Display, …
At Compilation Time Check GAMS syntax Execute special $ sign syntax $call $load $unload
Save Restart Break code into sequentially executed pieces Avoids compile time problems (if code segment 1 produces a file to be used in code segment 2) Can be nicely automated
$ Dollar Options $ must be in first column Several $ options can be in one line $onlisting offsymlist Some options require values, e.g. Generally, carried out at compile time!
External file inclusion $include filename $libinclude filename $libinclude filename $batinlcude filename $batinlcude filename $sysinclude filename $sysinclude filename Can append path statements before filename (absolute, relative, %var%)
GDX $Control Variables $Gdxin filename.gdx $Load p1 s1 $Gdxin $Gdxout filename.gdx $Unload p1 s1 dangerous because $Gdxout of compile time For unload use better: Execute_Unload
Output (*.lst file) $Control $onlisting $offlisting $onuellist $offuellist $onupper $offupper $show $single $double $onsymlist $offsymlist $onsymxref $offsymxref $offdollar $ondollar $offinclude $oninclude …
Input file control $offmargin $onmargin $mincol 20 maxcol 40 $ondelim $offdelim $ontext $offtext $offglobal $onglobal
Messages / Comments $log $error $error $remark $title $stitle $hidden $oneolcom $offeolcom $oninline $offinline $offnestcom $onnestcom
GAMS syntax symbol substitution $comment $comment $stars $dollar $eolcom $inlinecom Why change?
Forced program termination $exit… quits only local file $abort text… stops entire compilation $stop… stops without error $goto name… jumps to: $label name Usually these termination statements are combined with $if statements
Control Variables $set name value $setlocal name value $setglobal name value $drop name $droplocal name $dropglobal name Action scope differs: (setlocal < set < setglobal) (setlocal < set < setglobal)
Conditional Control Statements $If condition statementtoexecute $Ifi… case insensitive $if version $ife… $ifthen $ifelse $else
GAMS Symbol Tests $if exist filename statement $if dexist dirname statement $if declared symbol statement $if dimension 4 symbol statement $if defined symbol statement $if putopen statement $if settype symbol statement (partype, filtype, equtype, vartype, modtype, …) $if errorfree gamsstatement $if errorlevel n gamsstatement $if warnings gamsstatement Statement can be special or normal gams syntax
File Creation at Compile Time $Onecho > file $Offecho
$Macro $macro ratio(a,b) a/b $macro reciprocal(a) 1/a Scalar a /2/,d/4/,c; c=ratio(a,d); display c; c=reciprocal(d);
Other features ask Allows user dialog
Undocumented $maxgoto$onuni