16.01.2015 Views

GAMS — The Solver Manuals - Available Software

GAMS — The Solver Manuals - Available Software

GAMS — The Solver Manuals - Available Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CONOPT 129<br />

Although <strong>GAMS</strong> has a SIGN function, it cannot be used in a model because of its discontinuous nature. Instead,<br />

the pressure loss can be modeled with the equation dH =E= const * Q * ABS(Q)**(P-1), where the sign of the<br />

Q-term takes care of the sign of dH, and the ABS function guaranties that the real power ** is applied to a<br />

non-negative number. Although the expression involves the ABS function, the derivatives are smooth as long as<br />

P is greater than 1. <strong>The</strong> derivative with respect to Q is const * (P-1) * ABS(Q)**(P-1) for Q > 0 and -const *<br />

(P-1) * ABS(Q)**(P-1) for Q < 0. <strong>The</strong> limit for Q going to zero from both right and left is 0, so the derivative<br />

is smooth in the critical point Q = 0 and the overall model is therefore smooth.<br />

Another example of a smooth expression is the following terribly looking Sigmoid expression:<br />

Sigmoid(x) = exp( min(x,0) ) / (1+exp(-abs(x)))<br />

<strong>The</strong> standard definition of the sigmoid function is<br />

Sigmoid(x) = exp(x) / ( 1+exp(x) )<br />

This definition is well behaved for negative and small positive x, but it not well behaved for large positive x since<br />

exp overflows. <strong>The</strong> alternative definition:<br />

Sigmoid(x) = 1 / ( 1+exp(-x) )<br />

is well behaved for positive and slightly negative x, but it overflows for very negative x. Ideally, we would like<br />

to select the first expression when x is negative and the second when x is positive, i.e.<br />

Sigmoid(x) = (exp(x)/(1+exp(x)))$(x lt 0) + (1/(1+exp(-x)))$(x gt 0)<br />

but a $ -control that depends on an endogenous variable is illegal. <strong>The</strong> first expression above solves this problem.<br />

When x is negative, the nominator becomes exp(x) and the denominator becomes 1+exp(x). And when x is<br />

positive, the nominator becomes exp(0) = 1 and the denominator becomes 1+exp(-x). Since the two expressions<br />

are mathematically identical, the combined expression is of course smooth, and the exp function is never evaluated<br />

for a positive argument.<br />

Unfortunately, <strong>GAMS</strong> cannot recognize this and similar special cases so you must always solve models with<br />

endogenous ABS, MAX, or MIN as DNLP models, even in the cases where the model is smooth.<br />

7.5 Are NLP Models Always Smooth<br />

NLP models are defined as models in which all operators and functions are smooth. <strong>The</strong> derivatives of composite<br />

functions, that can be derived using the chain rule, will therefore in general be smooth. However, it is not always<br />

the case. <strong>The</strong> following simple composite function is not smooth: y = SQRT( SQR(x) ). <strong>The</strong> composite function<br />

is equivalent to y = ABS(x), one of the non-smooth DNLP functions.<br />

What went wrong <strong>The</strong> chain rule for computing derivatives of a composite function assumes that all intermediate<br />

expressions are well defined. However, the derivative of SQRT grows without bound when the argument<br />

approaches zero, violating the assumption.<br />

<strong>The</strong>re are not many cases that can lead to non-smooth composite functions, and they are all related to the case<br />

above: <strong>The</strong> real power, x**y, for 0 < y < 1 and x approaching zero. <strong>The</strong> SQRT function is a special case since<br />

it is equivalent to x**y for y = 0.5.<br />

If you have expressions involving a real power with an exponent between 0 and 1 or a SQRT, you should in<br />

most cases add bounds to your variables to ensure that the derivative or any intermediate terms used in their<br />

calculation become undefined. In the example above, SQRT( SQR(x) ), a bound on x is not possible since x should<br />

be allowed to be both positive and negative. Instead, changing the expression to SQRT( SQR(x) + SQR(delta))<br />

may lead to an appropriate smooth formulation.<br />

Again, <strong>GAMS</strong> cannot recognize the potential danger in an expression involving a real power, and the presence<br />

of a real power operator is not considered enough to flag a model as a DNLP model. During the solution process,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!