/home/coin/SVN-release/CoinAll-1.1.0/cppad/cppad/local/ad.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_AD_INCLUDED
00002 # define CPPAD_AD_INCLUDED
00003 
00004 /* --------------------------------------------------------------------------
00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
00006 
00007 CppAD is distributed under multiple licenses. This distribution is under
00008 the terms of the 
00009                     GNU General Public License Version 2.
00010 
00011 A copy of this license is included in the COPYING file of this distribution.
00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00013 -------------------------------------------------------------------------- */
00014 
00015 // simple AD operations that must be defined for AD as well as base class
00016 # include <cppad/local/ordered.hpp>
00017 # include <cppad/local/identical.hpp>
00018 
00019 // define the template classes that are used by the AD template class
00020 # include <cppad/local/op_code.hpp>
00021 # include <cppad/local/tape_rec.hpp>
00022 # include <cppad/local/ad_tape.hpp>
00023 
00024 //  BEGIN CppAD namespace
00025 namespace CppAD {
00026 
00027 template <class Base>
00028 class AD {
00029 
00030         // template friend functions where template parameter is not bound
00031         template <class VectorAD>
00032         friend void Independent(VectorAD &x);
00033 
00034         // one argument functions
00035         friend bool GreaterThanZero    <Base> 
00036                 (const AD<Base>    &u);
00037         friend bool LessThanZero       <Base> 
00038                 (const AD<Base>    &u);
00039         friend bool LessThanOrZero     <Base> 
00040                 (const AD<Base>    &u);
00041         friend bool GreaterThanOrZero  <Base> 
00042                 (const AD<Base>    &u);
00043         friend bool Parameter          <Base> 
00044                 (const AD<Base>    &u);
00045         friend bool Parameter          <Base>
00046                 (const VecAD<Base> &u);
00047         friend bool Variable           <Base> 
00048                 (const AD<Base>    &u);
00049         friend bool Variable           <Base> 
00050                 (const VecAD<Base> &u);
00051         friend bool IdenticalPar       <Base> 
00052                 (const AD<Base>    &u);
00053         friend bool IdenticalZero      <Base> 
00054                 (const AD<Base>    &u);
00055         friend bool IdenticalOne       <Base> 
00056                 (const AD<Base>    &u);
00057         friend int  Integer            <Base> 
00058                 (const AD<Base>    &u);
00059         friend AD   Var2Par            <Base>
00060                 (const AD<Base>    &u);
00061 
00062         // power function
00063         friend AD pow <Base>
00064                 (const AD<Base> &x, const AD<Base> &y);
00065 
00066         // IdenticalEqualPar function
00067         friend bool IdenticalEqualPar <Base> 
00068                 (const AD<Base> &u, const AD<Base> &v);
00069 
00070         // EqualOpSeq function
00071         friend bool EqualOpSeq <Base> 
00072                 (const AD<Base> &u, const AD<Base> &v);
00073 
00074         // NearEqual function
00075         friend bool NearEqual <Base> (
00076         const AD<Base> &x, const AD<Base> &y, const Base &r, const Base &a);
00077 
00078         friend bool NearEqual <Base> (
00079         const Base &x, const AD<Base> &y, const Base &r, const Base &a);
00080 
00081         friend bool NearEqual <Base> (
00082         const AD<Base> &x, const Base &y, const Base &r, const Base &a);
00083 
00084         // CondExp function
00085         friend AD<Base> CondExpOp  <Base> (
00086                 enum CompareOp  cop       ,
00087                 const AD<Base> &left      , 
00088                 const AD<Base> &right     , 
00089                 const AD<Base> &trueCase  , 
00090                 const AD<Base> &falseCase 
00091         );
00092 
00093         // classes
00094         friend class ADTape<Base>;
00095         friend class ADDiscrete<Base>;
00096         friend class ADFun<Base>;
00097         friend class VecAD<Base>;
00098         friend class VecAD_reference<Base>;
00099 
00100         // output operations
00101         friend std::ostream& operator << <Base>
00102                 (std::ostream &os, const AD<Base> &x);
00103         friend void PrintFor <Base>
00104                 (const char *text, const AD<Base> &x);
00105 
00106 public:
00107         // type of value
00108         typedef Base value_type;
00109 
00110         // comparison operators
00111         inline bool operator <  (const AD &right) const;
00112         inline bool operator <= (const AD &right) const;
00113         inline bool operator >  (const AD &right) const;
00114         inline bool operator >= (const AD &right) const;
00115         inline bool operator == (const AD &right) const;
00116         inline bool operator != (const AD &right) const;
00117 
00118         // binary operators
00119         inline AD operator + (const AD &right) const;
00120         inline AD operator - (const AD &right) const;
00121         inline AD operator * (const AD &right) const;
00122         inline AD operator / (const AD &right) const;
00123 
00124         // default constructor
00125         inline AD(void);
00126 
00127         // use default copy constructor and assignment operator
00128         // inline AD(const AD &x);
00129         // inline AD& operator=(const AD &x);
00130 
00131         // construction and assingment from base type
00132         inline AD(const Base &b);
00133         inline AD& operator=(const Base &b); 
00134 
00135         // contructor and assignment from VecAD<Base>::reference
00136         inline AD(const VecAD_reference<Base> &x);
00137         inline AD& operator=(const VecAD_reference<Base> &x);
00138 
00139         // construction and assignment from some other type
00140         template <class T> inline AD(const T &t);
00141         template <class T> inline AD& operator=(const T &right);
00142 
00143         // base type corresponding to an AD object
00144         friend Base Value <Base> (const AD<Base> &x);
00145 
00146         // computed assignment operators
00147         inline AD& operator += (const AD &right);
00148         inline AD& operator -= (const AD &right);
00149         inline AD& operator *= (const AD &right);
00150         inline AD& operator /= (const AD &right);
00151 
00152         // unary operators
00153         inline AD operator +(void) const;
00154         inline AD operator -(void) const;
00155 
00156         // destructor
00157         ~AD(void)
00158         { }
00159 
00160         // interface so these functions need not be friends
00161         inline AD Abs(void) const;
00162         inline AD acos(void) const;
00163         inline AD asin(void) const;
00164         inline AD atan(void) const;
00165         inline AD cos(void) const;
00166         inline AD cosh(void) const;
00167         inline AD exp(void) const;
00168         inline AD log(void) const;
00169         inline AD sin(void) const;
00170         inline AD sinh(void) const;
00171         inline AD sqrt(void) const;
00172 
00173         // ----------------------------------------------------------
00174         // static public member functions
00175         static size_t      omp_max_thread(size_t number);
00176 
00177         // These functions declared public so can be accessed by user through
00178         // a macro interface and are not intended for direct use.
00179         // The macro interface is documented in bool_fun.hpp.
00180         // Developer documentation for these fucntions is in  bool_fun_link.hpp
00181         static inline bool UnaryBool(
00182                 bool FunName(const Base &x),
00183                 const AD<Base> &x
00184         );
00185         static inline bool BinaryBool(
00186                 bool FunName(const Base &x, const Base &y),
00187                 const AD<Base> &x , const AD<Base> &y
00188         );
00189 
00190 private:
00191         // value_ corresponding to this object
00192         Base value_;
00193 
00194         // tape identifier corresponding to taddr
00195         // This is a variable if and only if id_ == *id_handle()
00196         size_t id_;
00197 
00198         // taddr_ in tape for this variable 
00199         size_t taddr_;
00200         //
00201         // Make this variable a parameter
00202         //
00203         void make_parameter(void)
00204         {       CPPAD_ASSERT_UNKNOWN( Variable(*this) );  // currently a var
00205                 id_ = 0;
00206         }
00207         //
00208         // Make this parameter a new variable 
00209         //
00210         void make_variable(size_t id,  size_t taddr)
00211         {       CPPAD_ASSERT_UNKNOWN( Parameter(*this) ); // currently a par
00212                 CPPAD_ASSERT_UNKNOWN( taddr > 0 );        // sure valid taddr
00213 
00214                 taddr_ = taddr;
00215                 id_    = id;
00216         }
00217         // ---------------------------------------------------------------
00218         // tape linking functions
00219         // 
00220         // not static
00221         inline ADTape<Base> *tape_this(void) const;
00222         //
00223         // static 
00224         inline static size_t        *id_handle (size_t thread);
00225         inline static ADTape<Base> **tape_handle(size_t thread);
00226         static size_t                tape_new(void);
00227         static void                  tape_delete(size_t id);
00228         inline static ADTape<Base>  *tape_ptr(void);
00229         inline static ADTape<Base>  *tape_ptr(size_t id);
00230 }; 
00231 // ---------------------------------------------------------------------------
00232 
00233 } // END CppAD namespace
00234 
00235 // tape linking private functions
00236 # include <cppad/local/tape_link.hpp>
00237 
00238 // operations that expect the AD template class to be defined
00239 
00240 
00241 # endif

Generated on Sun Nov 14 14:06:33 2010 for Coin-All by  doxygen 1.4.7