Xor

Top  Previous  Next

When one wishes to perform an action if and only if one of two or more conditionals apply one can join them with an xor operator.  This involves using syntax like

 

Action$(logical condition 1 xor logical condition 2 xor

                        Logical condition 3)

or

If(logical condition 1 xor logical condition 2 xor

                        Logical condition 3, Action);

or

While(logical condition 1 xor logical condition 2 xor

                        Logical condition 3, Action);

Examples:

(complexcond.gms)

u(k)$(s(k) xor t(k)) = a(k);

u(k)$(s(k) xor u(k) xor t(k)) = a(k);

loop(k,if(s(k) lt 0 xor t(k), u(k) = a(k)) );

Notes:

One and only one not more than one of the logical conditions can be simultaneously true if the total logical condition to be true.
The xor operator can be mixed with other and , or , not, xor , nested $ in a complex logical condition.  When this is done GAMS will execute the various statement components according to a predefined operator precedence.  However it is advisable to be cautious and use parentheses to carefully control the meaning of the condition.