Suppressing model equations (left hand side)

Top  Previous  Next

Occasions occur where constraints should only be included in a model if particular conditions are met.  This again can be accomplished using $conditionals.  The general format for such a case is

 

equation name$logical condition..  equation specification;

 

and specifies that the named equation is defined as that given in the equation specification only if the logical condition is true.

Examples:

(conditional.gms)

Eq1$(qq gt 0)..                  xvar=e=3;

Eq2$(sum(I,q(i)) gt 0)..  yvar=l=4;

Eq3(i)$(a(i) gt 0)..           ivar(i)=g= -a(i);

Eq7(i)$(qq gt 0)..        sum(j,ijvar(I,j))=g= -a(i);

 

All say define this equation only if the logical condition is true.

Notes:

In these cases, the whole named equation (see the Eq1 case above) or cases thereof when defined over a set (see the Eq3 case above) will be entered into the model only if the logical condition is true.
The last condition on Eq7 will suppress all the cases of the equation since the conditional is not dependent on the set element i.
This is also known in GAMS terminology as a conditional on the left hand side.  This is essentially identical to the suppressing calculation of items in a replacement context as discussed above.  Here the constraint will not be defined unless the conditional is true whereas above the execution of a replacement was determined by the conditional.
Many other logical condition forms are possible as explained below.
When the $ is on the left hand side the equation is only formed if the logical condition is true potentially making the program faster.