Wednesday, September 23, 2009

GAMS: compile time vs execution time

if(ElasticityChg_switch = 1,
$CALL =GDXXRW.EXE IncomeElasticityAdjMatrix.xls …
$GDXIN ElastAdjFactor.gdx
$LOAD ElastAdjFactor=ElastAdjFactor
)

This code works differently than expected. The $ statements are carried out during compilation time while the if statement is executed during execution time. I.e. this actually is executed in the following order:

$CALL =GDXXRW.EXE IncomeElasticityAdjMatrix.xls …
$GDXIN ElastAdjFactor.gdx
$LOAD ElastAdjFactor=ElastAdjFactor

if(ElasticityChg_switch = 1,
)

This difference between compile time and execution time is not very well understood by most users. Unfortunately, the use of many of the newer gams constructs such as $call, $load requires a good understanding of these concepts. Originally GAMS had only a very few constructs that required such knowledge, so users could build models without being bothered by the difference between compilation and execution. This is no longer the case: nowadays a good GAMS modeler better understands this difference.

PS. We also should use $loaddc instead of $load (see http://yetanothermathprogrammingconsultant.blogspot.com/2009/08/gams-loaddc-vs-load.html).