CppAD: A C++ Algorithmic Differentiation Package  20130102
fun_record.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 # ifndef CPPAD_FUN_RECORD_INCLUDED
00003 # define CPPAD_FUN_RECORD_INCLUDED
00004 /* --------------------------------------------------------------------------
00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
00006 
00007 CppAD is distributed under multiple licenses. This distribution is under
00008 the terms of the 
00009                     Eclipse Public License Version 1.0.
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 # include "cppad_ipopt_nlp.hpp"
00015 
00016 // ---------------------------------------------------------------------------
00017 namespace cppad_ipopt {
00018 // ---------------------------------------------------------------------------
00019 /*!
00020 \defgroup fun_record_hpp fun_record.hpp
00021 \{
00022 \file fun_record.hpp
00023 \brief Records operation sequence for r_k (u) 
00024 */
00025 
00026 /*!
00027 Records operation sequence for \f$ r_k (u) \f$ at \f$u = [ J \circ n ] (x)\f$.
00028 
00029 \tparam NumVector
00030 is the type of the argumen \c x. It can either be
00031 <tt>Ipopt::Number*</tt> or 
00032 <tt>CppAD::vector<Ipopt::Number></tt>; i.e., <tt>NumberVector</tt>.
00033 
00034 \param fg_info
00035 Given a value \f$ u \in {\bf R}^{q[k]} \f$,
00036 \c fg_info returns the value \f$ r_k (u) \in {\bf R}^{p[k]} \f$.
00037 using the syntax
00038 \verbatim
00039      fg_info->eval_r(k, u);   
00040 \endverbatim
00041 No other use is made of \c fg_info.
00042 
00043 \param k
00044 is a value less that \c K specifying 
00045 the index value for \c k in the evaluation <tt>eval_r</tt>.
00046 
00047 \param p
00048 <tt>p[k]</tt> is dimension of the range space for \f$ r_k (u) \f$; i.e.,
00049 \f$ r_k (u) \in {\bf R}^{p(k)} \f$.
00050 
00051 \param q
00052 <tt>q[k]</tt> is dimension of the domain space for \f$ r_k (u) \f$; i.e.,
00053 \f$ u \in {\bf R}^{q(k)} \f$.
00054 
00055 \param n
00056 is the lenght of the vector \c x.
00057 
00058 \param x
00059 the length of \c x is equal to \c n and the point 
00060 \f[
00061      u = [ J \circ n ] (x)
00062 \f]
00063 is the point at which the operation sequence for \f$ r_k \f$ is recorded.
00064 
00065 \param J
00066 is a vector with lenght <tt>q[k]</tt> that projects from \f$ {\bf R}^n \f$
00067 to \f$ {\bf R}^{q[k]} \f$ 
00068 by selecting an ordered subset of the possible indices
00069 \f$ \{ 0 , \ldots , n-1 \} \f$.
00070 Hence, <tt>0 <= J[j] < n</tt> for <tt>j = 0 , ... , q[k]-1</tt>. 
00071 
00072 \param r_fun
00073 is the vector of AD function objects which has size size greater than \c k.
00074 Only the function object <tt>r_fun[k]</tt> is referenced.
00075 The input value of this function object does not matter.
00076 On output it is a recording of the function \f$ r_k (u) \f$
00077 at the value of \f$ u \f$ specified by \c x and \c J.
00078 */
00079 
00080 template <class NumVector>
00081 void fun_record( 
00082      cppad_ipopt_fg_info*                              fg_info ,
00083      size_t                                            k       ,
00084      const SizeVector&                                 p       ,
00085      const SizeVector&                                 q       ,
00086      size_t                                            n       ,
00087      const NumVector&                                  x       ,
00088      const SizeVector&                                 J       ,
00089      CppAD::vector< CppAD::ADFun<Ipopt::Number> >&     r_fun   )
00090 {    size_t j;
00091 
00092      // extract u from x
00093      ADVector u(q[k]);
00094      for(j = 0; j < q[k]; j++)
00095      {    // when NDEBUG is not defined, this error should be caught 
00096           // during the cppad_ipopt_nlp constructor.
00097           CPPAD_ASSERT_UNKNOWN( J[j] < n );
00098           u[j] = x[ J[j] ];
00099      }
00100 
00101      // start the recording
00102      CppAD::Independent(u);
00103 
00104      // record the evaulation of r_k (u)
00105      ADVector r_k = fg_info->eval_r(k, u);
00106      CPPAD_ASSERT_KNOWN( r_k.size() == p[k] ,
00107      "cppad_ipopt_nlp: eval_r return value size not equal to p[k]."
00108      );
00109 
00110      // stop the recording and store operation sequence in 
00111      r_fun[k].Dependent(u, r_k);
00112 }
00113 // ---------------------------------------------------------------------------
00114 /*! \} */
00115 } // end namespace cppad_ipopt
00116 // ---------------------------------------------------------------------------
00117 # endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines