# CouenneExprBCos.hpp

Go to the documentation of this file.

    00001 /* $Id: CouenneExprBCos.hpp 748 2011-07-28 16:13:32Z pbelotti $ */
    00002 /*
    00003  * Name:    exprBCos.hpp
    00004  * Author:  Pietro Belotti
    00005  * Purpose: definition of operators to compute lower/upper bounds of cosines
    00006  *
    00007  * (C) Carnegie-Mellon University, 2006.
    00008  * This file is licensed under the Eclipse Public License (EPL)
    00009  */
    00010
    00011 #ifndef COUENNE_EXPRBCOS_HPP
    00012 #define COUENNE_EXPRBCOS_HPP
    00013
    00014 #include "CouenneExprOp.hpp"
    00015 #include "CoinHelperFunctions.hpp"
    00016
    00017 #include <math.h>
    00018 #ifndef M_PI
    00019 # define M_PI 3.14159265358979323846
    00020 #endif
    00021
    00022 namespace Couenne {
    00023
    00026
    00027 class exprLBCos: public exprOp {
    00028
    00029  public:
    00030
    00032   exprLBCos (expression *lb, expression *ub):
    00033     exprOp (new expression * [2], 2) {
    00034     arglist_ [0] = lb;
    00035     arglist_ [1] = ub;
    00036   } //< non-leaf expression, with argument list
    00037
    00039   expression *clone (Domain *d = NULL) const
    00040   {return new exprLBCos (arglist_ [0] -> clone (d),
    00041                          arglist_ [1] -> clone (d));}
    00042
    00044   CouNumber operator () ();
    00045
    00047   enum pos printPos () const
    00048     {return PRE;}
    00049
    00051   std::string printOp () const
    00052     {return "LB_Cos";}
    00053 };
    00054
    00055
    00057
    00058 inline CouNumber exprLBCos::operator () () {
    00059
    00060   register CouNumber
    00061     l = (*(arglist_ [0])) (),
    00062     u = (*(arglist_ [1])) ();
    00063
    00064   CouNumber pi2 = 2 * M_PI;
    00065
    00066   if ((u - l >= pi2) ||       // 1) interval spans whole cycle
    00067       (floor (l/pi2 - 0.5) < // 2) there is a pi + 2k pi between l and u
    00068        floor (u/pi2 - 0.5)))
    00069     return -1.;
    00070
    00071   return CoinMin (cos (l), cos (u));
    00072 }
    00073
    00074
    00076
    00079
    00080 class exprUBCos: public exprOp {
    00081
    00082  public:
    00083
    00085   exprUBCos (expression *lb, expression *ub):
    00086     exprOp (new expression * [2], 2) {
    00087     arglist_ [0] = lb;
    00088     arglist_ [1] = ub;
    00089   } //< non-leaf expression, with argument list
    00090
    00092   expression *clone (Domain *d = NULL) const
    00093   {return new exprUBCos (arglist_ [0] -> clone (d),
    00094                          arglist_ [1] -> clone (d));}
    00095
    00097   CouNumber operator () ();
    00098
    00100   std::string printOp () const
    00101     {return "UB_Cos";}
    00102
    00104   enum pos printPos () const
    00105     {return PRE;}
    00106 };
    00107
    00108
    00110
    00111 inline CouNumber exprUBCos::operator () () {
    00112
    00113   register CouNumber
    00114     l = (*(arglist_ [0])) (),
    00115     u = (*(arglist_ [1])) ();
    00116
    00117   CouNumber pi2 = 2 * M_PI;
    00118
    00119   if ((u - l >= pi2) || // 1) interval spans whole cycle
    00120       (floor (l/pi2) < // 2) there is a 3/2 pi + 2k pi between l and u
    00121        floor (u/pi2)))
    00122     return 1.;
    00123
    00124   return CoinMax (cos (l), cos (u));
    00125 }
    00126
    00127 }
    00128
    00129 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines