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