Suppressing terms in equations (right hand side)

Top  Previous  Next

GAMS replacement statements involve an item to change in value on the left hand side and a set of terms that constitute the new value on the right hand side.  The terms on the right hand side may be conditionally included.  $conditionals are used to do this and may act on the term for all cases or on a case by case basis (only if the conditional is set element dependent).  They may  occur in replacement statements or in model equation specification statements (.. statements).  The general format for such a case is

 

Namedparameter = term1+term$logical condition

or

Namedequation.. term1+term$logical condition =L= other terms;

 

and specifies that the term is added into the calculation of namedparameter or the namedequation only if the logical condition is true.

Example:

(conditional.gms)

qq     =  qq+1$(x gt 0);

qq     =  1$(x gt 0);

q(i)   =  a(i)+1$(a(i) gt 0);

q(i)   =  a(i)$(a(i) gt 0);

X      =  sum(I,q(i))$(qq gt 0)+4;

Eq4..     xvar+yvar$(qq gt 0)=e=3;

Eq5(i)..  ivar(i)$(a(i) gt 0)+yvar$(qq gt 0)=e=3;

 

All say include this term only if the logical condition is true.

Notes:

In these cases the term will be included only if the logical condition is true.
The third fourth and last cases include terms differentially depending on the set element I being referenced.
The term may be the only one in a replacement as in the second case.  In such a situation the expression is treated as if it were  qq     = 0 + 1$(x gt 0);  where the item on the left hand side becomes zero if the condition on the right hand side fails.
This is known in GAMS terminology as a conditional on the right hand side.
Many other logical condition forms are possible as explained below.
When the $ is placed outside a sum then the sum is only computed if the logical condition is true potentially making the program faster.
Right hand side conditionals do not stop replacements from occurring, but left hand side ones do as elaborated on in the Calculating chapter.