scp_step_linesearch.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_solver/scp_step_linesearch.hpp>
00035 
00036 
00037 
00038 BEGIN_NAMESPACE_ACADO
00039 
00040 
00041 //
00042 // PUBLIC MEMBER FUNCTIONS:
00043 //
00044 
00045 SCPstepLinesearch::SCPstepLinesearch( ) : SCPstep( )
00046 {
00047 }
00048 
00049 
00050 SCPstepLinesearch::SCPstepLinesearch( UserInteraction* _userInteraction ) : SCPstep( _userInteraction )
00051 {
00052 }
00053 
00054 
00055 SCPstepLinesearch::SCPstepLinesearch( const SCPstepLinesearch& rhs ) : SCPstep( rhs )
00056 {
00057 }
00058 
00059 
00060 SCPstepLinesearch::~SCPstepLinesearch( )
00061 {
00062 }
00063 
00064 
00065 SCPstepLinesearch& SCPstepLinesearch::operator=( const SCPstepLinesearch& rhs )
00066 {
00067     if ( this != &rhs )
00068     {
00069                 SCPstep::operator=( rhs );
00070     }
00071 
00072     return *this;
00073 }
00074 
00075 
00076 
00077 
00078 SCPstep* SCPstepLinesearch::clone() const
00079 {
00080         return new SCPstepLinesearch( *this );
00081 }
00082 
00083 
00084 
00085 returnValue SCPstepLinesearch::performStep(     OCPiterate& iter,
00086                                                                                 BandedCP& cp,
00087                                                                                 SCPevaluation* eval
00088                                                                                         )
00089 {
00090         returnValue returnvalue;
00091 
00092         double alpha = 1.0;
00093         double lineSearchTOL, alphaMin;
00094 
00095         get( LINESEARCH_TOLERANCE    , lineSearchTOL );
00096         get( MIN_LINESEARCH_PARAMETER, alphaMin      );
00097 
00098 //      iter.print();
00099         
00100         if( eval->getKKTtolerance( iter,cp ) > lineSearchTOL )
00101         {
00102                 returnvalue = performLineSearch( iter,cp,*eval, alpha,alphaMin );
00103                 if( returnvalue != SUCCESSFUL_RETURN ) ACADOERROR(returnvalue);
00104         }
00105         else
00106         {
00107                 returnvalue = performLineSearch( iter,cp,*eval, alpha,1.0 );
00108                 if( returnvalue != SUCCESSFUL_RETURN ) ACADOERROR(returnvalue);
00109         }
00110         setLast( LOG_LINESEARCH_STEPLENGTH, alpha );
00111 
00112         returnvalue = applyStep( iter,cp,alpha );
00113         if( returnvalue != SUCCESSFUL_RETURN )
00114                 ACADOERROR( returnvalue );
00115 
00116 
00117         return SUCCESSFUL_RETURN;
00118 }
00119 
00120 
00121 
00122 
00123 //
00124 // PROTECTED MEMBER FUNCTIONS:
00125 //
00126 
00127 
00128 
00129 returnValue SCPstepLinesearch::performLineSearch(       const OCPiterate& iter,
00130                                                                                                         BandedCP& cp,
00131                                                                                                         SCPevaluation& eval,
00132                                                                                                         double& alpha,
00133                                                                                                         const double& alphaMin
00134                                                                                                         )
00135 {
00136 
00137     const int     maxIter = 50;
00138     const double  kappa   = 0.5;
00139 
00140     alpha   = 1.0;
00141 
00142     double meritFcnValue1 = INFTY;
00143         double meritFcnValue2 = INFTY;
00144 
00145         if ( meritFcn->evaluate( 0.0,iter,cp,eval, meritFcnValue1 ) != SUCCESSFUL_RETURN )
00146                 return ACADOERROR( RET_UNKNOWN_BUG );
00147 
00148     int run1 = 0;
00149     while( run1 < maxIter ){
00150         meritFcn->evaluate( alpha,iter,cp,eval, meritFcnValue2 );
00151 
00152 //         acadoPrintf("LineSearch: T1 = %.16e  T2 = %.16e  alpha = %.3e \n", meritFcnValue1, meritFcnValue2, alpha  );
00153 
00154         if( meritFcnValue2 <= meritFcnValue1 + EPS ) break;
00155         if( alpha <= alphaMin+EPS ) break;
00156         alpha *= kappa;
00157         run1++;
00158     }
00159 
00160         setLast( LOG_MERIT_FUNCTION_VALUE,meritFcnValue2 );
00161 
00162     return SUCCESSFUL_RETURN;
00163 }
00164 
00165 
00166 
00167 
00168 CLOSE_NAMESPACE_ACADO
00169 
00170 // end of file.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:38:51