gams advanced syntax from mccarl guide from own guess-based experiments
TRANSCRIPT
GAMS advanced GAMS advanced syntaxsyntax
From McCarl GuideFrom McCarl Guide
From own guess-based experimentsFrom own guess-based experiments
Sys
tem
Attr
ibut
esS
yste
m A
ttrib
utes
Gam
s A
ttrib
utes
Gam
s A
ttrib
utes
System AttributesSystem Attributes
System.<attribute>System.<attribute>
Parameter report1(*); Set report2(*);Parameter report1(*); Set report2(*); report1("memory")=%system.memory%;report1("memory")=%system.memory%; report2("%system.date%")=yes;report2("%system.date%")=yes; display report1,report2;display report1,report2;
GAMS AttributesGAMS Attributes
Command line argumentsCommand line argumentsgams.<attribute>gams.<attribute>
Parameter report1(*); Set report2(*);Parameter report1(*); Set report2(*); report1(“lpsolver")=%gams.lp%;report1(“lpsolver")=%gams.lp%; report2("%gams.lp%")=yes;report2("%gams.lp%")=yes; display report1,report2;display report1,report2;
GAMS TimingGAMS Timing
CompilationCompilation
Syntax checkSyntax check
$control $control operationsoperations
ExecutionExecution
Syntax Syntax executionexecution
At Execution TimeAt Execution Time
Execute normal GAMS syntax:Execute normal GAMS syntax:
Data(Set)=normal(10,2);Data(Set)=normal(10,2); Solve, If, Sum, Smin, Loop, …Solve, If, Sum, Smin, Loop, … Execute, Execute_unloadExecute, Execute_unload Option, Display, …Option, Display, …
At Compilation TimeAt Compilation Time
Check GAMS syntaxCheck GAMS syntax Execute special $ sign syntaxExecute special $ sign syntax
$call$call $load$load $unload$unload
Save RestartSave Restart
Break code into sequentially Break code into sequentially executed piecesexecuted pieces
Avoids compile time problems (if Avoids compile time problems (if code segment 1 produces a file to be code segment 1 produces a file to be used in code segment 2)used in code segment 2)
Can be nicely automatedCan be nicely automated
$ Dollar Options$ Dollar Options
$ must be in first column$ must be in first column
Several $ options can be in one lineSeveral $ options can be in one line $onlisting offsymlist$onlisting offsymlist
Some options require values, e.g.Some options require values, e.g. $eolcom @$$eolcom @$
Generally, Generally, carried out at compile time!carried out at compile time!
External file inclusionExternal file inclusion
$include $include filenamefilename
$libinclude $libinclude filenamefilename <arguments><arguments>
$batinlcude $batinlcude filenamefilename <arguments><arguments>
$sysinclude $sysinclude filenamefilename <arguments><arguments>
Can append path statements before Can append path statements before filename (absolute, relative, %var%)filename (absolute, relative, %var%)
GDX $Control VariablesGDX $Control Variables
$Gdxin filename.gdx$Gdxin filename.gdx$Load p1 s1$Load p1 s1$Gdxin $Gdxin
$Gdxout filename.gdx$Gdxout filename.gdx$Unload p1 s1 $Unload p1 s1 dangerous because dangerous because $Gdxout$Gdxout of compile timeof compile time
For unload use better:For unload use better: Execute_Unload Execute_Unload
Output (*.lst file) $ControlOutput (*.lst file) $Control
$onlisting$onlisting $offlisting$offlisting $onuellist$onuellist $offuellist$offuellist $onupper$onupper $offupper$offupper $show$show $single$single $double$double
$onsymlist$onsymlist $offsymlist$offsymlist $onsymxref $onsymxref $offsymxref$offsymxref $offdollar$offdollar $ondollar$ondollar $offinclude$offinclude $oninclude$oninclude……
Input file controlInput file control
$offmargin$offmargin $onmargin$onmargin $mincol 20 maxcol 40 $mincol 20 maxcol 40 $ondelim$ondelim $offdelim$offdelim $ontext $ontext $offtext$offtext $offglobal$offglobal $onglobal$onglobal
Messages / CommentsMessages / Comments
$log$log $error $error $remark$remark $title $title $stitle$stitle
$hidden$hidden $oneolcom$oneolcom $offeolcom$offeolcom $oninline $oninline $offinline$offinline $offnestcom$offnestcom $onnestcom$onnestcom
GAMS syntax symbol substitutionGAMS syntax symbol substitution
$comment $comment $stars$stars $dollar$dollar $eolcom$eolcom $inlinecom$inlinecom
Why change?Why change?
Forced program terminationForced program termination
$exit$exit … quits only local file… quits only local file
$abort text$abort text … stops entire compilation… stops entire compilation
$stop$stop … stops without error… stops without error
$goto name$goto name … jumps to: $label name … jumps to: $label name
Usually these termination statements are Usually these termination statements are combined with $if statementscombined with $if statements
Control VariablesControl Variables
$set $set namename valuevalue $setlocal $setlocal namename valuevalue $setglobal $setglobal namename valuevalue $drop $drop namename $droplocal $droplocal namename $dropglobal $dropglobal namename
Action scope differs:Action scope differs: (setlocal < set < setglobal)(setlocal < set < setglobal)
Conditional Control StatementsConditional Control Statements
$If $If conditioncondition statementtoexecutestatementtoexecute $Ifi$Ifi … case insensitive $if version… case insensitive $if version $ife$ife … … $ifthen$ifthen $ifelse$ifelse $else$else
GAMS Symbol TestsGAMS Symbol Tests
$if <not> exist $if <not> exist filename statementfilename statement $if <not> dexist $if <not> dexist dirname statementdirname statement $if <not> declared $if <not> declared symbol statementsymbol statement$if <not> dimension $if <not> dimension 44 symbol statementsymbol statement$if <not> defined $if <not> defined symbol statementsymbol statement$if <not> putopen $if <not> putopen statementstatement$if <not> settype $if <not> settype symbol statementsymbol statement(partype, filtype, equtype, vartype, modtype, …)(partype, filtype, equtype, vartype, modtype, …)$if errorfree $if errorfree gamsstatementgamsstatement$if errorlevel $if errorlevel nn gamsstatementgamsstatement$if warnings $if warnings gamsstatementgamsstatementStatement can be special or normal gams syntaxStatement can be special or normal gams syntax
File Creation at Compile TimeFile Creation at Compile Time
$Onecho > file$Onecho > file $Offecho$Offecho
$Macro$Macro
$macro ratio(a,b) a/b$macro ratio(a,b) a/b $macro reciprocal(a) 1/a$macro reciprocal(a) 1/a
Scalar a /2/,d/4/,c;Scalar a /2/,d/4/,c; c=ratio(a,d); display c;c=ratio(a,d); display c; c=reciprocal(d);c=reciprocal(d);
Other featuresOther features
askask
Allows user dialogAllows user dialog
UndocumentedUndocumented
$maxgoto$maxgoto
$onuni $onuni