Compilation of $ifThenE statement

Hello, I have an issue with the code block below. The logic $ifThenE cleanup_solve>0 picks up the original 0 value of the scalar, but not the updated value. Any suggestion to make the $ifThenE picking the updated postsolve value ?

Scalar postsolve   / 0 /;

postsolve = card(devices);

$ifThenE postsolve>0
...(build model and solve it)
$endif

Zamry,

You need to understand the difference between GAMS compile and execution time (see https://www.gams.com/latest/docs/UG_GamsCall.html#UG_GamsCall_TwoPass). All compile time commands are performed before any execution time. So the “$ifThenE postsolve>0” is checked before you calculate “postsolve = card(devices);”. If devices is a set determined at compile time via e.g. “set deviced / d1*d10 /”, then you can do the check via “”$ifThenE card(devices)>0". If devices is a set determined at execution time, then you can’t do any $ifthen. In such cases a regular “if” might help:

Scalar postsolve   / 0 /;

postsolve = card(devices);

if(postsolve>0
...(build model and solve it)
);

You can’t do any declaration inside the if(), but that’s usually not a problem, you just do them before the if.

-Michael

Thank you Michael. Your response cleared things up.

Zamry