libMC.so.0.1
is a library defining a C++ class for calculating the McCormick relaxation of a nonconvex function on a box, as well as valid subgradients of these relaxations. Any function can be considered, provided it is factorable.The relaxation is calculated based on the operator overloading and function overloading capabilities of C++. The overloaded operators are: `+', `-', `*', and `/'; the overloaded functions are: `exp', `log', and `pow'. (Trigonometric functions such as `cos', `sin' and `tan' aren't currently supported.)
Future versions of libAD
will allow dealing with a wider variety of mathematical functions. In particular, trigonometric functions such as `cos', `sin' and `tan' shall be implemented.
First, we shall define the variables and
. This is done as follows:
McCormick X( -2., 1., 0. ); McCormick Y( -2., 1., 0. );
Essentially, the first line means that X
is a variable of class McCormick, that it belongs to the interval , and that its current value is equal to
. The same holds for the McCormick variable
Y
.
Once and
have been defined, the McCormick's relaxations of
at
are simply calculated as
McCormick Z = X*pow(exp(X)-Y,2);
The value of the McCormick's convex underestimator and the McCormick's concave overestimator of on
at
are obtained as
double Zcvx = Z.cv(); double Zccv = Z.cc();
Likewise, a lower bound and an upper bound for the values of on
are obtained as
double Zlb = Z.l(); double Zub = Z.u();