Right and left hand side conditionals

Top  Previous  Next

Conditionals may be used on either the right or left hand side of assignment statements but the operation is very different.

A conditional on the left-hand side specifies the condition under which a statement is executed.  Thus, no assignment is made unless the conditional is satisfied.
A conditional on the right-hand side specifies the condition under which a term is computed.  Thus, the assignment is always made but the term is zero unless the conditional is satisfied.

This means that with a conditional on the left hand side of an assignment the previous contents of the parameter will remain unchanged for conditionals that are not satisfied.

For example in the GAMS code below (leftright.gms)

 

Y=2;

Z=2;

X=0;

Y$X=4;

Z=4$X;

 

Y will end with a value of 2 but Z will equal zero since the Y calculation with the left hand side conditional will not be executed since X=0.  But the Z calculation is always done and the right hand side conditional 4$X term will be zero since X is zero.

Analogous conditions hold for models where

A conditional on the left-hand side of the .. specifies the condition under which an equation is defined.  Thus, the constraint equation is not present unless the conditional is satisfied.
A conditional on the right-hand side after the .. specifies the condition under which a term is computed in the equation.  Thus, the equation is defined but the term is zero unless the conditional is satisfied.

This means that with a left hand side conditional the equation is not entered into the model.

For example in the GAMS code below (leftright.gms)

 

 C1$x..   YY=e=4;

 C2..     YY=e=4$X;

 

 YY will not be constrained by C1 since it has a left hand side conditional and will not be defined as an equation since X=0.  But the C2 equation is always defined and the YY will be set equal to zero since the right hand side conditional 4$X term becomes zero since X is zero.