export_nlp_solver.hpp
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 
00032 #ifndef ACADO_TOOLKIT_EXPORT_NLP_SOLVER_HPP
00033 #define ACADO_TOOLKIT_EXPORT_NLP_SOLVER_HPP
00034 
00035 #include <acado/utils/acado_utils.hpp>
00036 #include <acado/matrix_vector/matrix_vector.hpp>
00037 
00038 #include <acado/code_generation/export_algorithm_factory.hpp>
00039 #include <acado/code_generation/integrators/integrator_export.hpp>
00040 
00041 #include <acado/code_generation/export_cholesky_decomposition.hpp>
00042 #include <acado/code_generation/linear_solvers/householder_qr_export.hpp>
00043 
00044 BEGIN_NAMESPACE_ACADO
00045 
00046 class OCP;
00047 class Objective;
00048 
00062 class ExportNLPSolver : public ExportAlgorithm
00063 {
00064 public:
00065 
00071         ExportNLPSolver(        UserInteraction* _userInteraction = 0,
00072                                                 const std::string& _commonHeaderName = ""
00073                                                 );
00074 
00076         virtual ~ExportNLPSolver( )
00077         {}
00078 
00083         virtual returnValue setup( ) = 0;
00084 
00085 
00092         returnValue setIntegratorExport(        IntegratorExportPtr const _integrator
00093                                                                                 );
00094 
00101         returnValue setLevenbergMarquardt(      double _levenbergMarquardt
00102                                                                                 );
00103 
00104 
00112         virtual returnValue getDataDeclarations(        ExportStatementBlock& declarations,
00113                                                                                                 ExportStruct dataStruct = ACADO_ANY
00114                                                                                                 ) const;
00115 
00123         virtual returnValue getFunctionDeclarations(    ExportStatementBlock& declarations
00124                                                                                                         ) const = 0;
00125 
00126 
00134         virtual returnValue getCode(    ExportStatementBlock& code
00135                                                                         ) = 0;
00136 
00137 
00142         virtual unsigned getNumQPvars( ) const = 0;
00143 
00149         bool performsSingleShooting( ) const;
00150 
00157         returnValue setObjective(const Objective& _objective);
00158         returnValue setLSQObjective(const Objective& _objective);
00159         returnValue setGeneralObjective(const Objective& _objective);
00160 
00164         returnValue setConstraints(const OCP& _ocp);
00165 
00169         unsigned getNumComplexConstraints( void );
00170 
00173         unsigned weightingMatricesType( void ) const;
00174 
00176         bool initialStateFixed( ) const;
00177 
00179         bool usingLinearTerms() const;
00180 
00181 protected:
00182 
00189         virtual returnValue setupSimulation( void );
00190 
00195         virtual returnValue setupVariables( ) = 0;
00196 
00201         virtual returnValue setupMultiplicationRoutines( ) = 0;
00202 
00204         virtual returnValue setupEvaluation( ) = 0;
00205 
00207         virtual returnValue setupConstraintsEvaluation( ) = 0;
00208 
00210         returnValue setupAuxiliaryFunctions();
00211 
00213         virtual returnValue setupGetObjective();
00214 
00216         virtual returnValue setupGetLSQObjective();
00217 
00219         virtual returnValue setupGetGeneralObjective();
00220 
00222         returnValue setupArrivalCostCalculation();
00223 
00225         virtual returnValue setupInitialization();
00226 
00227 protected:
00228 
00233         IntegratorExportPtr integrator;
00234 
00235         ExportFunction modelSimulation;
00236 
00237         ExportVariable state;
00238         ExportVariable x;
00239         ExportVariable z;
00240         ExportVariable u;
00241         ExportVariable od;
00242         ExportVariable d;
00243 
00244         ExportVariable evGx; // stack of sensitivities w.r.t. x
00245         ExportVariable evGu; // stack of sensitivities w.r.t. u
00246 
00253         double levenbergMarquardt;
00254 
00255         ExportVariable y, yN, Dy, DyN;
00256 
00257         // lagrange multipliers
00258         ExportVariable mu;
00259 
00260         ExportVariable objS, objSEndTerm;
00261         ExportVariable objEvFx, objEvFu, objEvFxEnd; // aliasing
00262         ExportVariable objEvFxx, objEvFxu, objEvFuu, objEvFxxEnd; // aliasing
00263 
00264         ExportVariable objAuxVar, objValueIn, objValueOut;
00265         ExportAcadoFunction evaluateStageCost;
00266         ExportAcadoFunction evaluateTerminalCost;
00267 
00268         ExportVariable Q1, Q2;
00269         ExportVariable R1, R2;
00270         ExportVariable S1;
00271         ExportVariable QN1, QN2;
00272 
00273         ExportVariable objSlx, objSlu;
00274 
00275         bool diagonalH, diagonalHN;
00276 
00281         VariablesGrid uBounds;
00282         VariablesGrid xBounds;
00287         unsigned dimPacH;
00288         ExportAcadoFunction evaluatePathConstraints;
00289         ExportVariable conAuxVar;
00290         ExportVariable conValueIn;
00291         ExportVariable conValueOut;
00292 
00293         DVector lbPathConValues, ubPathConValues;
00294 
00295         ExportVariable pacEvH;
00296         ExportVariable pacEvHx, pacEvHu, pacEvHxd;
00301         unsigned dimPocH;
00302         std::vector< std::tr1::shared_ptr< ExportAcadoFunction > > evaluatePointConstraints;
00303         DVector lbPointConValues, ubPointConValues;
00304 
00305         std::vector< DVector > pocLbStack, pocUbStack;
00306 
00307         ExportVariable pocEvH;
00308         ExportVariable pocEvHx, pocEvHu, pocEvHxd;
00315         ExportFunction initialize;
00316 
00317         ExportFunction shiftStates;
00318         ExportFunction shiftControls;
00319         ExportFunction getObjective;
00320         ExportFunction initializeNodes;
00325         ExportFunction updateArrivalCost;
00326 
00327         ExportCholeskyDecomposition cholObjS;
00328         ExportCholeskyDecomposition cholSAC;
00329 
00330         ExportHouseholderQR acSolver;
00331 
00332         ExportVariable acA, acb, acP, acTmp;
00333         // acWL and acVL are assumed to be upper triangular matrices
00334         ExportVariable acWL, acVL, acHx, acHu, acXx, acXu, acXTilde, acHTilde;
00335 
00336         // Older stuff; TODO make this more unique
00337         ExportVariable SAC, xAC, DxAC;
00338 
00339         ExportFunction regularizeHessian;
00340         ExportFunction regularization;
00343 private:
00344         returnValue setupResidualVariables();
00345         returnValue setupObjectiveLinearTerms(const Objective& _objective);
00346 };
00347 
00349 enum ExportNLPType
00350 {
00351         GAUSS_NEWTON_CONDENSED,
00352         GAUSS_NEWTON_CN2,
00353         GAUSS_NEWTON_CN2_NEW,
00354         EXACT_HESSIAN_CN2,
00355         EXACT_HESSIAN_QPDUNES,
00356         GAUSS_NEWTON_CN2_FACTORIZATION,
00357         GAUSS_NEWTON_FORCES,
00358         GAUSS_NEWTON_QPDUNES,
00359         GAUSS_NEWTON_QPDUNES2,
00360         GAUSS_NEWTON_HPMPC
00361 };
00362 
00364 typedef ExportAlgorithmFactory<ExportNLPSolver, ExportNLPType> NLPSolverFactory;
00365 
00367 typedef std::tr1::shared_ptr< ExportNLPSolver > ExportNLPSolverPtr;
00368 
00369 CLOSE_NAMESPACE_ACADO
00370 
00371 #endif  // ACADO_TOOLKIT_EXPORT_NLP_SOLVER_HPP


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