constant_hessian.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00034 #include <acado/nlp_derivative_approximation/constant_hessian.hpp>
00035 
00036 
00037 
00038 BEGIN_NAMESPACE_ACADO
00039 
00040 
00041 //
00042 // PUBLIC MEMBER FUNCTIONS:
00043 //
00044 
00045 ConstantHessian::ConstantHessian( ) : NLPderivativeApproximation( )
00046 {
00047 }
00048 
00049 
00050 ConstantHessian::ConstantHessian( UserInteraction* _userInteraction ) : NLPderivativeApproximation( _userInteraction )
00051 {
00052 }
00053 
00054 
00055 ConstantHessian::ConstantHessian( const ConstantHessian& rhs ) : NLPderivativeApproximation( rhs )
00056 {
00057 }
00058 
00059 
00060 ConstantHessian::~ConstantHessian( )
00061 {
00062 }
00063 
00064 
00065 ConstantHessian& ConstantHessian::operator=( const ConstantHessian& rhs )
00066 {
00067         if ( this != &rhs )
00068         {
00069                 NLPderivativeApproximation::operator=( rhs );
00070         }
00071 
00072         return *this;
00073 }
00074 
00075 
00076 NLPderivativeApproximation* ConstantHessian::clone( ) const
00077 {
00078         return new ConstantHessian( *this );
00079 }
00080 
00081 
00082 
00083 returnValue ConstantHessian::initHessian(       BlockMatrix& B,
00084                                                                                         uint N,
00085                                                                                         const OCPiterate& iter
00086                                                                                         )
00087 {
00088         if( N > 1 )
00089         {
00090                 for( uint run1=0; run1<N; ++run1 )
00091                 {
00092                         if ( iter.getNX() != 0 )
00093                                 B.setIdentity( run1,run1, iter.getNX() );
00094 
00095                         if ( iter.getNXA() != 0 )
00096                                 B.setIdentity( N+run1,N+run1, iter.getNXA() );
00097 
00098                         if ( ( iter.getNP() != 0 ) && ( run1 != N-1 ) )
00099                                 B.setIdentity( 2*N+run1,2*N+run1, iter.getNP() );
00100 
00101                         if ( ( iter.getNU() != 0 ) && ( run1 != N-1 ) )
00102                                 B.setIdentity( 3*N+run1,3*N+run1, iter.getNU() );
00103 
00104                         if ( ( iter.getNW() != 0 ) && ( run1 != N-1 ) )
00105                                 B.setIdentity( 4*N+run1,4*N+run1, iter.getNW() );
00106                 }
00107         }
00108         else
00109         {
00110                 if ( iter.getNP() != 0 )
00111                         B.setIdentity( 2,2, iter.getNP() );
00112 
00113                 if ( iter.getNU() != 0 )
00114                         B.setIdentity( 3,3, iter.getNU() );
00115 
00116                 if ( iter.getNW() != 0 )
00117                         B.setIdentity( 4,4, iter.getNW() );
00118         }
00119 
00120         return SUCCESSFUL_RETURN;
00121 }
00122 
00123 
00124 returnValue ConstantHessian::initScaling(       BlockMatrix& B,
00125                                                                                         const BlockMatrix& x,
00126                                                                                         const BlockMatrix& y
00127                                                                                         )
00128 {
00129     DMatrix scale1, scale2;
00130 
00131     (x^x).getSubBlock(0,0,scale1,1,1);
00132     (y^y).getSubBlock(0,0,scale2,1,1);
00133 
00134     if ( ( scale1(0,0) <= 1000.0*EPS ) || ( scale2(0,0) <= 1000.0*EPS ) )
00135         {
00136                 hessianScaling = 1.0;
00137         }
00138         else
00139         {
00140                 hessianScaling = sqrt( scale2(0,0)/scale1(0,0) );
00141         }
00142 
00143         B *= hessianScaling;
00144 
00145     return SUCCESSFUL_RETURN;
00146 }
00147 
00148 
00149 returnValue ConstantHessian::apply(     BlockMatrix &B,
00150                                                                         const BlockMatrix &x,
00151                                                                         const BlockMatrix &y
00152                                                                         )
00153 {
00154         return SUCCESSFUL_RETURN;
00155 }
00156 
00157 
00158 
00159 //
00160 // PROTECTED MEMBER FUNCTIONS:
00161 //
00162 
00163 
00164 
00165 
00166 
00167 CLOSE_NAMESPACE_ACADO
00168 
00169 // end of file.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:58:04