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