# CouenneExprBMul.hpp

Go to the documentation of this file.

    00001 /* $Id: CouenneExprBMul.hpp 591 2011-05-31 17:03:03Z pbelotti $
    00002  *
    00003  * Name:    exprBMul.hpp
    00004  * Author:  Pietro Belotti
    00005  * Purpose: definition of operators to compute lower/upper bounds of multiplications
    00006  *
    00007  * (C) Carnegie-Mellon University, 2006.
    00008  * This file is licensed under the Eclipse Public License (EPL)
    00009  */
    00010
    00011 #ifndef COUENNE_EXPRBMUL_H
    00012 #define COUENNE_EXPRBMUL_H
    00013
    00014 #include "CouenneExprOp.hpp"
    00015 #include "CouenneConfig.h"
    00016 #include "CoinHelperFunctions.hpp"
    00017 #include "CoinFinite.hpp"
    00018
    00019 namespace Couenne {
    00020
    00021 #define MUL_ZERO 1e-20
    00022 #define MUL_INF  sqrt (COIN_DBL_MAX)
    00023
    00025 inline CouNumber safeProd (register CouNumber a, register CouNumber b) {
    00026
    00027   if (a >  MUL_INF) return (b < -MUL_ZERO) ? -COIN_DBL_MAX : (b > MUL_ZERO) ?  COIN_DBL_MAX : 0.;
    00028   if (a < -MUL_INF) return (b < -MUL_ZERO) ?  COIN_DBL_MAX : (b > MUL_ZERO) ? -COIN_DBL_MAX : 0.;
    00029
    00030   if (b >  MUL_INF) return (a < -MUL_ZERO) ? -COIN_DBL_MAX : (a > MUL_ZERO) ?  COIN_DBL_MAX : 0.;
    00031   if (b < -MUL_INF) return (a < -MUL_ZERO) ?  COIN_DBL_MAX : (a > MUL_ZERO) ? -COIN_DBL_MAX : 0.;
    00032
    00033   return a*b;
    00034 }
    00035
    00036
    00039
    00040 class exprLBMul: public exprOp {
    00041
    00042  public:
    00043
    00045   exprLBMul  (expression **al, int n):
    00046     exprOp (al, n) {} //< non-leaf expression, with argument list
    00047
    00049   expression *clone (Domain *d = NULL) const
    00050     {return new exprLBMul (clonearglist (d), nargs_);}
    00051
    00053   CouNumber operator () ();
    00054
    00056   enum pos printPos () const
    00057     {return PRE;}
    00058
    00060   std::string printOp () const
    00061     {return "LB_Mul";}
    00062 };
    00063
    00064
    00066
    00067 inline CouNumber exprLBMul::operator () () {
    00068
    00069   register CouNumber n = (*(arglist_ [0])) ();
    00070   register CouNumber N = (*(arglist_ [1])) ();
    00071   register CouNumber d = (*(arglist_ [2])) ();
    00072   register CouNumber D = (*(arglist_ [3])) ();
    00073
    00074   if (d>=0)
    00075     if   (n>=0) return safeProd (n,d);
    00076     else        return safeProd (n,D);
    00077   else // d <= 0
    00078     if (N>0) {
    00079       CouNumber Nd = safeProd (N,d), nD;
    00080       if (n<0 && D>0 &&
    00081           (Nd > (nD = safeProd (n,D)))) return nD;
    00082       else                              return Nd;
    00083     }
    00084     else
    00085       if (D>0) return safeProd (n,D);
    00086       else     return safeProd (N,D);
    00087 }
    00088
    00089
    00092
    00093 class exprUBMul: public exprOp {
    00094
    00095  public:
    00096
    00098   exprUBMul  (expression **al, int n):
    00099     exprOp (al, n) {} //< non-leaf expression, with argument list
    00100
    00102   expression *clone (Domain *d = NULL) const
    00103     {return new exprUBMul (clonearglist (d), nargs_);}
    00104
    00106   CouNumber operator () ();
    00107
    00109   enum pos printPos () const
    00110     {return PRE;}
    00111
    00113   std::string printOp () const
    00114     {return "UB_Mul";}
    00115 };
    00116
    00117
    00119
    00120 inline CouNumber exprUBMul::operator () () {
    00121
    00122   //  exprOp:: operator () ();
    00123
    00124   register CouNumber n = (*(arglist_ [0])) ();
    00125   register CouNumber N = (*(arglist_ [1])) ();
    00126   register CouNumber d = (*(arglist_ [2])) ();
    00127   register CouNumber D = (*(arglist_ [3])) ();
    00128
    00129   if (d>0)
    00130     if (N<0) return safeProd (N,d);
    00131     else     return safeProd (N,D);
    00132   else // d <= 0
    00133     if (n<0) {
    00134       CouNumber nd = safeProd (n,d), ND;
    00135       if (N>0 && D>0 &&
    00136           ((ND = safeProd (N,D)) > nd)) return ND;
    00137       else                              return nd;
    00138     }
    00139     else
    00140       if (D>0) return safeProd (N,D);
    00141       else     return safeProd (n,D);
    00142 }
    00143
    00144 }
    00145
    00146 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines