Multiple conditions in $Ifthen Topic is solved

Problems with syntax of GAMS
Post Reply
zhj0735
User
User
Posts: 16
Joined: 4 years ago

Multiple conditions in $Ifthen

Post by zhj0735 »

Hi GAMS friends,

I used $ifthen dollar conditions to activate the equation constraints. But when there are more than 2 such constraints, the code did not work as expected.

For example, I have two values to be satisfied (LCFSindex and carbonindex) in order to show the set. The example code is attached below. However, I cannot activate the display even if I have the right condition in the model (--LCFSindex=1.3 --carbonindex=0 ). Did I miss anything when put this dollar condition?

Thanks,
Jia

Code: Select all

set a/1/
$ifthen  (%LCFSindex%==1.3 and  %carbonindex%==0)
display a
$endif
User avatar
bussieck
Moderator
Moderator
Posts: 1038
Joined: 7 years ago

Re: Multiple conditions in $Ifthen

Post by bussieck »

The regular $ifThen does a string comparison, if you want to evaluate an expression, you need to use $ifThenE (https://www.gams.com/latest/docs/UG_Dol ... _21_option):

Code: Select all

$set LCFSindex 1.3
$set carbonindex 0

set a/1/
$ifThenE (%LCFSindex%=1.3)and(%carbonindex%=0)
display a
$endif
You can't have any spaces in the expression, so make intensive use of ().

-Michael
zhj0735
User
User
Posts: 16
Joined: 4 years ago

Re: Multiple conditions in $Ifthen

Post by zhj0735 »

Thanks Michael!
Post Reply