optimization_algorithm.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/optimization_algorithm/optimization_algorithm.hpp>
00035 
00036 
00037 BEGIN_NAMESPACE_ACADO
00038 
00039 
00040 
00041 //
00042 // PUBLIC MEMBER FUNCTIONS:
00043 //
00044 
00045 
00046 OptimizationAlgorithm::OptimizationAlgorithm( ) : OptimizationAlgorithmBase( ), UserInteraction( )
00047 {
00048         setupOptions( );
00049         setupLogging( );
00050         
00051         setStatus( BS_UNDEFINED );
00052 }
00053 
00054 
00055 OptimizationAlgorithm::OptimizationAlgorithm( const OCP& ocp_ ) : OptimizationAlgorithmBase( ocp_ ), UserInteraction( )
00056 {
00057         setupOptions( );
00058         setupLogging( );
00059 }
00060 
00061 
00062 OptimizationAlgorithm::OptimizationAlgorithm( const OptimizationAlgorithm& arg )
00063                       : OptimizationAlgorithmBase( arg ), UserInteraction( arg )
00064 {
00065 }
00066 
00067 
00068 OptimizationAlgorithm::~OptimizationAlgorithm( )
00069 {
00070 }
00071 
00072 
00073 
00074 OptimizationAlgorithm& OptimizationAlgorithm::operator=( const OptimizationAlgorithm& arg )
00075 {
00076         if( this != &arg )
00077         {
00078                 OptimizationAlgorithmBase::operator=( arg );
00079                 UserInteraction::operator=( arg );
00080         }
00081 
00082         return *this;
00083 }
00084 
00085 
00086 returnValue OptimizationAlgorithm::init( )
00087 {
00088         if ( ( getStatus( ) == BS_READY ) && ( haveOptionsChanged( ) == BT_FALSE ) )
00089                 return SUCCESSFUL_RETURN;
00090 
00091         returnValue returnvalue = OptimizationAlgorithmBase::init( this );
00092 
00093         setStatus( BS_READY );
00094         declareOptionsUnchanged( );
00095 
00096         return returnvalue;
00097 }
00098 
00099 
00100 returnValue OptimizationAlgorithm::solve( ){
00101 
00102     returnValue returnvalue = SUCCESSFUL_RETURN;
00103 
00104         if ( ( getStatus( ) != BS_READY ) || ( haveOptionsChanged( ) == BT_TRUE ) )
00105         returnvalue = init( );
00106 
00107     if( returnvalue != SUCCESSFUL_RETURN ) return returnvalue;
00108     
00109     returnvalue = nlpSolver->solve( );
00110 
00111     if( returnvalue != SUCCESSFUL_RETURN &&
00112         returnvalue != CONVERGENCE_ACHIEVED )
00113         {
00114                 if ( returnvalue == RET_MAX_NUMBER_OF_STEPS_EXCEEDED)
00115                         return ACADOERROR( RET_MAX_NUMBER_OF_STEPS_EXCEEDED );
00116                 else
00117                         return ACADOERROR( RET_OPTALG_SOLVE_FAILED );
00118         }
00119     return SUCCESSFUL_RETURN;
00120 }
00121 
00122 
00123 
00124 
00125 //
00126 // PROTECTED MEMBER FUNCTIONS:
00127 //
00128 
00129 returnValue OptimizationAlgorithm::setupOptions( )
00130 {
00131         // add NLP solver options
00132         addOption( MAX_NUM_ITERATIONS          , defaultMaxNumIterations        );
00133         addOption( KKT_TOLERANCE               , defaultKKTtolerance            );
00134         addOption( KKT_TOLERANCE_SAFEGUARD     , defaultKKTtoleranceSafeguard   );
00135         addOption( LEVENBERG_MARQUARDT         , defaultLevenbergMarguardt      );
00136         addOption( HESSIAN_PROJECTION_FACTOR   , defaultHessianProjectionFactor );
00137         addOption( PRINTLEVEL                  , defaultPrintlevel              );
00138         addOption( PRINT_COPYRIGHT             , defaultPrintCopyright          );
00139         addOption( HESSIAN_APPROXIMATION       , defaultHessianApproximation    );
00140         addOption( DYNAMIC_HESSIAN_APPROXIMATION, defaultDynamicHessianApproximation );
00141         addOption( DYNAMIC_SENSITIVITY         , defaultDynamicSensitivity      );
00142         addOption( OBJECTIVE_SENSITIVITY       , defaultObjectiveSensitivity    );
00143         addOption( CONSTRAINT_SENSITIVITY      , defaultConstraintSensitivity   );
00144         addOption( DISCRETIZATION_TYPE         , defaultDiscretizationType      );
00145         addOption( LINESEARCH_TOLERANCE        , defaultLinesearchTolerance     );
00146         addOption( MIN_LINESEARCH_PARAMETER    , defaultMinLinesearchParameter  );
00147         addOption( MAX_NUM_QP_ITERATIONS       , defaultMaxNumQPiterations      );
00148         addOption( HOTSTART_QP                 , defaultHotstartQP              );
00149         addOption( INFEASIBLE_QP_RELAXATION    , defaultInfeasibleQPrelaxation  );
00150         addOption( INFEASIBLE_QP_HANDLING      , defaultInfeasibleQPhandling    );
00151         addOption( USE_REALTIME_ITERATIONS     , defaultUseRealtimeIterations   );
00152         addOption( TERMINATE_AT_CONVERGENCE    , defaultTerminateAtConvergence  );
00153         addOption( SPARSE_QP_SOLUTION          , defaultSparseQPsolution        );
00154         addOption( GLOBALIZATION_STRATEGY      , defaultGlobalizationStrategy   );
00155         addOption( PRINT_SCP_METHOD_PROFILE    , defaultprintSCPmethodProfile   );
00156 
00157         // add integration options
00158         addOption( FREEZE_INTEGRATOR           , defaultFreezeIntegrator        );
00159         addOption( INTEGRATOR_TYPE             , defaultIntegratorType          );
00160         addOption( FEASIBILITY_CHECK           , defaultFeasibilityCheck        );
00161         addOption( PLOT_RESOLUTION             , defaultPlotResoltion           );
00162         
00163         // add integrator options
00164         addOption( MAX_NUM_INTEGRATOR_STEPS    , defaultMaxNumSteps             );
00165         addOption( INTEGRATOR_TOLERANCE        , defaultIntegratorTolerance     );
00166         addOption( ABSOLUTE_TOLERANCE          , defaultAbsoluteTolerance       );
00167         addOption( INITIAL_INTEGRATOR_STEPSIZE , defaultInitialStepsize         );
00168         addOption( MIN_INTEGRATOR_STEPSIZE     , defaultMinStepsize             );
00169         addOption( MAX_INTEGRATOR_STEPSIZE     , defaultMaxStepsize             );
00170         addOption( STEPSIZE_TUNING             , defaultStepsizeTuning          );
00171         addOption( CORRECTOR_TOLERANCE         , defaultCorrectorTolerance      );
00172         addOption( INTEGRATOR_PRINTLEVEL       , defaultIntegratorPrintlevel    );
00173         addOption( LINEAR_ALGEBRA_SOLVER       , defaultLinearAlgebraSolver     );
00174         addOption( ALGEBRAIC_RELAXATION        , defaultAlgebraicRelaxation     );
00175         addOption( RELAXATION_PARAMETER        , defaultRelaxationParameter     );
00176         addOption( PRINT_INTEGRATOR_PROFILE    , defaultprintIntegratorProfile  );
00177 
00178         return SUCCESSFUL_RETURN;
00179 }
00180 
00181 
00182 returnValue OptimizationAlgorithm::setupLogging( )
00183 {
00184 //      LogRecord tmp( LOG_AT_EACH_ITERATION,stdout,PS_DEFAULT,BT_FALSE );
00185 // 
00186 //      tmp.addItem( LOG_NUM_NLP_ITERATIONS );
00187 // 
00188 //      addLogRecord( tmp );
00189   
00190         return SUCCESSFUL_RETURN;
00191 }
00192 
00193 
00194 returnValue OptimizationAlgorithm::allocateNlpSolver( Objective *F, DynamicDiscretization *G, Constraint *H )
00195 {
00196         if( nlpSolver != 0 )
00197                 delete nlpSolver;
00198 
00199         nlpSolver = new SCPmethod( this, F,G,H, isLinearQuadratic( F,G,H ) );
00200 
00201         return SUCCESSFUL_RETURN;
00202 }
00203 
00204 
00205 returnValue OptimizationAlgorithm::initializeNlpSolver( const OCPiterate& _userInit )
00206 {
00207         ACADO_TRY( nlpSolver->init( _userInit.x, _userInit.xa, _userInit.p, _userInit.u, _userInit.w ) );
00208         return SUCCESSFUL_RETURN;
00209 }
00210 
00211 
00212 returnValue OptimizationAlgorithm::initializeObjective( Objective* F
00213                                                                                                                 )
00214 {
00215         return SUCCESSFUL_RETURN;
00216 }
00217 
00218 
00219 
00220 
00221 CLOSE_NAMESPACE_ACADO
00222 
00223 
00224 // end of file.


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