Hello, GAMS experts
I would like to branch to two different module base on scalar ‘s’. The following is my GAMS code, however it is not working correctly.
Please help me what is problem for this model. If know, let me know what is best solution.
scalars
s / 100 /
;
if (s > 0,
$Setglobal optcase "Case1"
else
$Setglobal optcase "Case2"
);
display "%optcase%";
$If %optcase% == "Case2" $goto Subroutine2
$label Subroutine1
...
...
$goto SolverRun
$label Subroutine2
...
...
$label SolverRun
model myModel / all /;
solve myModel using MINLP minimizing myTarget;
Hi,
You are mixing compile time statements (like $setglobal) with execution time commands (like if/else).
GAMS is a two pass system with a compile time phase and an execution time phase (see https://www.gams.com/latest/docs/UG_GamsCall.html#UG_GamsCall_TwoPass).
$commands like setglobal are carried out at compile time where the execution time if/elsehas no meaning.
The solution is to replace your if/else with the compile time counterpart (https://www.gams.com/latest/docs/UG_DollarControlOptions.html#DOLLARifthen)
scalars
s / 100 /
;
$ifthene s>0
$ Setglobal optcase "Case1"
$else
$ Setglobal optcase "Case2"
$endif
display "%optcase%";
I hope this helps!
Fred
Thank so much Fred.
Your sample code is working well, It was clear.