Page 1 of 1

Compilation of $ifThenE statement

Posted: Wed Dec 08, 2021 6:46 pm
by zamry
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 ?

Code: Select all

Scalar postsolve   / 0 /;

postsolve = card(devices);

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

Re: Compilation of $ifThenE statement

Posted: Thu Dec 09, 2021 8:09 am
by bussieck
Zamry,

You need to understand the difference between GAMS compile and execution time (see https://www.gams.com/latest/docs/UG_Gam ... ll_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:

Code: Select all

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

Re: Compilation of $ifThenE statement

Posted: Fri Feb 04, 2022 2:23 am
by zamry
Thank you Michael. Your response cleared things up.

Zamry