gams advanced syntax from mccarl guide from own guess-based experiments

24
GAMS advanced GAMS advanced syntax syntax From McCarl Guide From McCarl Guide From own guess-based experiments From own guess-based experiments

Upload: cecil-richards

Post on 17-Dec-2015

228 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: GAMS advanced syntax From McCarl Guide From own guess-based experiments

GAMS advanced GAMS advanced syntaxsyntax

From McCarl GuideFrom McCarl Guide

From own guess-based experimentsFrom own guess-based experiments

Page 2: GAMS advanced syntax From McCarl Guide From own guess-based experiments

Sys

tem

Attr

ibut

esS

yste

m A

ttrib

utes

Page 3: GAMS advanced syntax From McCarl Guide From own guess-based experiments

Gam

s A

ttrib

utes

Gam

s A

ttrib

utes

Page 4: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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;

Page 5: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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;

Page 6: GAMS advanced syntax From McCarl Guide From own guess-based experiments

GAMS TimingGAMS Timing

CompilationCompilation

Syntax checkSyntax check

$control $control operationsoperations

ExecutionExecution

Syntax Syntax executionexecution

Page 7: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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, …

Page 8: GAMS advanced syntax From McCarl Guide From own guess-based experiments

At Compilation TimeAt Compilation Time

Check GAMS syntaxCheck GAMS syntax Execute special $ sign syntaxExecute special $ sign syntax

$call$call $load$load $unload$unload

Page 9: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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

Page 10: GAMS advanced syntax From McCarl Guide From own guess-based experiments

$ 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!

Page 11: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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%)

Page 12: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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

Page 13: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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……

Page 14: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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

Page 15: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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

Page 16: GAMS advanced syntax From McCarl Guide From own guess-based experiments

GAMS syntax symbol substitutionGAMS syntax symbol substitution

$comment $comment  $stars$stars $dollar$dollar $eolcom$eolcom $inlinecom$inlinecom

Why change?Why change?

Page 17: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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

Page 18: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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)

Page 19: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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

Page 20: GAMS advanced syntax From McCarl Guide From own guess-based experiments

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

Page 21: GAMS advanced syntax From McCarl Guide From own guess-based experiments

File Creation at Compile TimeFile Creation at Compile Time

$Onecho > file$Onecho > file $Offecho$Offecho

Page 22: GAMS advanced syntax From McCarl Guide From own guess-based experiments

$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);

Page 23: GAMS advanced syntax From McCarl Guide From own guess-based experiments

Other featuresOther features

askask

Allows user dialogAllows user dialog

Page 24: GAMS advanced syntax From McCarl Guide From own guess-based experiments

UndocumentedUndocumented

$maxgoto$maxgoto

$onuni $onuni