Compilation of $ifThenE statement

Problems with syntax of GAMS
Post Reply
zamry
User
User
Posts: 8
Joined: 2 years ago

Compilation of $ifThenE statement

Post 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
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Compilation of $ifThenE statement

Post 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
zamry
User
User
Posts: 8
Joined: 2 years ago

Re: Compilation of $ifThenE statement

Post by zamry »

Thank you Michael. Your response cleared things up.

Zamry
Post Reply