Suppressing calculation of items (left 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.  One may cause the items to be changed only if certain conditions are met.  This is controlled with conditionals.  $conditionals are used to do this and may control whether the replacement calculation is done alt all or whether selected cases of it are done (only if the left hand side is defined over set elements) on a case by case basis.  The general format for such a case is

 

namedparameter$logical condition=term;

or

namedparameter(setelementdependency)$logical condition=term;

 

and specifies that the namedparameter is set equal to the term only if the logical condition is true.

Examples:

(conditional.gms)

X$(qq gt 0)=3;

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

qq $ (sum(i,abs(a(i))) gt 0)=1/sum(i,a(i));

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

a(i) $a(i) = q(i)/a(i);

 

All say implement this replacement statement changing the value of this parameter or its specific case only if the logical condition is true.  Thus after the first statement above if X started with a value of 7 and qq was negative causing a false evaluation of the logical condition then X would finish that statement with a value of 7.  On the other hand, if qq was positive then X would finish that statement with a value of 3.

Notes:

In these cases the namedparameter value will be altered only if the logical condition is true.  Otherwise, if the logical condition is false, the value of the item namedparameter will retain it's original value (or the default value of zero).
This is known in GAMS terminology as a conditional on the left hand side.
Many other logical condition forms are possible as explained below.
The third and fifth assignments contain a common procedure where a division is done only if the denominator is non-zero.
When the $ is on the left hand side, the equation is only computed if the logical condition is true potentially making the program faster.
The first four cases cause the replacement statement to be entirely skipped if the conditional is false.  The last conditional operates on a case specific basis since the replacement is done for the elements of i and the conditional is also dependent on i with its truth dependent upon the choice of i.  Thus in the last statement a(i) is calculated only when it has a non zero value.
The conditional in the next to last case does not include terms dependent on i so none of the a(i) will be replaced if the conditional fails.