# CouenneFunTriplets.hpp

Go to the documentation of this file.

    00001 /* $Id: CouenneFunTriplets.hpp 940 2013-01-13 19:49:02Z pbelotti $
    00002  *
    00003  * Name:    funtriplets.hpp
    00004  * Author:  Pietro Belotti
    00005  * Purpose: class for representing a function and its first- and second-order derivative
    00006  *
    00007  * (C) Carnegie-Mellon University, 2007-10
    00008  * This file is licensed under the Eclipse Public License (EPL)
    00009  */
    00010
    00011 #ifndef Funtriplets_hpp
    00012 #define Funtriplets_hpp
    00013
    00014 #include <math.h>
    00015
    00016 #include "CouenneExprPow.hpp"
    00017
    00018 namespace Couenne
    00019 {
    00020
    00022 class funtriplet {
    00023
    00024 public:
    00025
    00027   funtriplet () {}
    00028
    00030   virtual ~funtriplet () {}
    00031
    00032   virtual CouNumber F     (CouNumber x) = 0; //< main funtion
    00033   virtual CouNumber Fp    (CouNumber x) = 0; //< first-order derivative of main funtion
    00034   virtual CouNumber Fpp   (CouNumber x) = 0; //< second-order derivative of main funtion
    00035   virtual CouNumber FpInv (CouNumber x) = 0; //< inverse of the first-order derivative
    00036 };
    00037
    00038
    00040 class simpletriplet: public funtriplet {
    00041
    00042 protected:
    00043
    00044   unary_function f_;   //< the function
    00045   unary_function fp_;  //< the first-order derivative
    00046   unary_function fpp_; //< the second-order derivative
    00047   unary_function fpI_; //< the inverse of the first-order derivative
    00048
    00049 public:
    00050
    00052   simpletriplet (unary_function f   = NULL,
    00053                  unary_function fp  = NULL,
    00054                  unary_function fpp = NULL,
    00055                  unary_function fpI = NULL):
    00056     f_   (f),
    00057     fp_  (fp),
    00058     fpp_ (fpp),
    00059     fpI_ (fpI) {}
    00060
    00062   virtual ~simpletriplet () {}
    00063
    00064   virtual CouNumber F     (CouNumber x) {return f_   (x);} //< main funtion
    00065   virtual CouNumber Fp    (CouNumber x) {return fp_  (x);} //< first-order derivative
    00066   virtual CouNumber Fpp   (CouNumber x) {return fpp_ (x);} //< second-order derivative
    00067   virtual CouNumber FpInv (CouNumber x) {return fpI_ (x);} //< inverse of first-order derivative
    00068 };
    00069
    00070
    00072 class powertriplet: public funtriplet {
    00073
    00074 protected:
    00075
    00076   CouNumber exponent_;    //< defines the power function triplet
    00077   bool      issignpower_; //< determines if signed power
    00078
    00079 public:
    00080
    00082   powertriplet (CouNumber exponent, bool signpower = false):
    00083     exponent_ (exponent), issignpower_ (signpower) {}
    00084
    00086   virtual ~powertriplet () {}
    00087
    00088   virtual CouNumber F   (CouNumber x)
    00089   {return safe_pow (x, exponent_, issignpower_);}                                   //< main funtion
    00090
    00091   virtual CouNumber Fp  (CouNumber x)
    00092   {return exponent_ * safe_pow (issignpower_ ? fabs(x) : x, exponent_ - 1);}  //< first-order derivative
    00093
    00094   virtual CouNumber Fpp (CouNumber x)
    00095   {return exponent_ * (exponent_ - 1) * safe_pow (x, exponent_ - 2, issignpower_);} //< second-order derivative
    00096
    00097   virtual CouNumber FpInv (CouNumber x)
    00098   {return safe_pow (x / exponent_, 1 / (exponent_ - 1), issignpower_);} //< inverse of first derivative
    00099 };
    00100
    00101
    00103 class kpowertriplet: public powertriplet {
    00104
    00105 protected:
    00106
    00107   CouNumber mult_; //< pre-multiplier
    00108
    00109 public:
    00110
    00112   kpowertriplet (CouNumber exponent, CouNumber k):
    00113     powertriplet (exponent),
    00114     mult_ (k) {}
    00115
    00117   virtual ~kpowertriplet () {}
    00118
    00119   virtual CouNumber F   (CouNumber x)  //< main funtion
    00120   {return mult_ * safe_pow (x, exponent_);}
    00121
    00122   virtual CouNumber Fp  (CouNumber x)  //< first-order derivative
    00123   {return mult_ * exponent_ * safe_pow (x, exponent_ - 1);}
    00124
    00125   virtual CouNumber Fpp (CouNumber x)  //< second-order derivative
    00126   {return mult_ * exponent_ * (exponent_ - 1) * safe_pow (x, exponent_ - 2);}
    00127
    00128   virtual CouNumber FpInv (CouNumber x)
    00129   {return safe_pow (x / (mult_ * exponent_), 1 / (exponent_ - 1));} //< inverse of first derivative
    00130 };
    00131
    00132 }
    00133 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines