objective.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
27 
34 #ifndef ACADO_TOOLKIT_OBJECTIVE_HPP
35 #define ACADO_TOOLKIT_OBJECTIVE_HPP
36 
42 
44 
46 struct LsqData
47 {
48  LsqData(const DMatrix& _WW, const Function& _hh, bool _givenW = true)
49  : W( _WW ), h( _hh ), givenW( _givenW )
50  {}
51 
58  bool givenW;
59 };
60 
62 typedef std::vector< LsqData > LsqElements;
63 
66 {
67  LsqExternData(const DMatrix& _WW, const std::string& _hh, bool _givenW = true)
68  : W( _WW ), h( _hh ), givenW( _givenW )
69  {}
70 
75  std::string h;
77  bool givenW;
78 };
79 
81 typedef std::vector< LsqExternData > LsqExternElements;
82 
85 {
86  LsqLinearData(const DVector& _Wlx, const DVector& _Wlu, bool _givenW = true)
87  : Wlx( _Wlx ), Wlu( _Wlu ), givenW( _givenW )
88  {}
89 
92  DMatrix Wlx, Wlu;
94  bool givenW;
95 };
96 
98 typedef std::vector< LsqLinearData > LsqLinearElements;
99 
123 class Objective : public LagrangeTerm
124 {
125  //
126  // PUBLIC MEMBER FUNCTIONS:
127  //
128  public:
129 
131  Objective( );
132 
134  Objective( const Grid &grid_ );
135 
137  Objective( const Objective& rhs );
138 
140  virtual ~Objective( );
141 
143  Objective& operator=( const Objective& rhs );
144 
145 
146 
151  returnValue init( const Grid &grid_ );
152 
153 
154 // =======================================================================================
155 //
156 // LOADING ROUTINES
157 //
158 // =======================================================================================
159 
160 
164  inline returnValue addMayerTerm( const Expression& arg );
165  inline returnValue addMayerTerm( const Function& arg );
166 
167 
168 
180  returnValue addLSQ( const MatrixVariablesGrid *S_,
181  const Function& h ,
182  const VariablesGrid *r_ );
183 
184 
185 
195  returnValue addLSQEndTerm( const DMatrix & S,
196  const Function & m,
197  const DVector & r );
198 
199  //
200  // Code generation related functions
201  //
202 
203  returnValue addLSQ(const DMatrix& S, const Function& h);
204 
205  returnValue addLSQEndTerm(const DMatrix& S, const Function& h);
206 
207  returnValue addLSQ(const DMatrix& S, const std::string& h);
208 
209  returnValue addLSQEndTerm(const DMatrix& S, const std::string& h);
210 
211  returnValue addLSQ(const BMatrix& S, const Function& h);
212 
213  returnValue addLSQEndTerm(const BMatrix& S, const Function& h);
214 
215  returnValue addLSQ(const BMatrix& S, const std::string& h);
216 
217  returnValue addLSQEndTerm(const BMatrix& S, const std::string& h);
218 
219  returnValue addLSQLinearTerms(const DVector& Slx, const DVector& Slu);
220 
221  returnValue addLSQLinearTerms(const BVector& Slx, const BVector& Slu);
222 
223 // =======================================================================================
224 //
225 // INITIALIZATION ROUTINES
226 //
227 // =======================================================================================
228 
243  returnValue init( const int nStages ,
244  const int nTransitions,
245  DifferentialEquation **fcn ,
246  Transition *transitions ,
247  Constraint *constraint_ );
248 
249 
250 // =======================================================================================
251 //
252 // DEFINITION OF SEEDS:
253 //
254 // =======================================================================================
255 
256 
262  virtual returnValue setForwardSeed( BlockMatrix *xSeed_ ,
263  BlockMatrix *xaSeed_,
264  BlockMatrix *pSeed_ ,
265  BlockMatrix *uSeed_ ,
266  BlockMatrix *wSeed_ ,
267  int order );
268 
269 
270 
276  virtual returnValue setBackwardSeed( BlockMatrix *seed,
277  int order );
278 
279 
280 
287  virtual returnValue setUnitBackwardSeed( );
288 
289 
290 
291 // =======================================================================================
292 //
293 // EVALUATION ROUTINES
294 //
295 // =======================================================================================
296 
297 
298 
304  returnValue evaluate( const OCPiterate &x );
305 
306 
307 
313  returnValue evaluateSensitivities();
314 
315 
321  returnValue evaluateSensitivities( BlockMatrix &hessian );
322 
323 
331  returnValue evaluateSensitivitiesGN( BlockMatrix &hessian );
332 
333 
334 
335 
336 // =======================================================================================
337 //
338 // RESULTS OF THE EVALUATION
339 //
340 // =======================================================================================
341 
342 
347  virtual returnValue getObjectiveValue( double &objectiveValue );
348 
349 
350 
356  virtual returnValue getForwardSensitivities( BlockMatrix &D ,
359  int order );
360 
361 
362 
368  virtual returnValue getBackwardSensitivities( BlockMatrix &D ,
371  int order );
372 
373 
374 
375 
376 
377 // =======================================================================================
378 //
379 // DIMENSIONS
380 //
381 // =======================================================================================
382 
383 
387  inline int getNX () const;
388 
392  inline int getNXA () const;
393 
397  inline int getNP () const;
398 
402  inline int getNU () const;
403 
407  inline int getNW () const;
408 
409 
410 // =======================================================================================
411 
412 
419  inline BooleanType hasLSQform();
420 
421 
423  inline BooleanType isAffine();
424 
425 
427  inline BooleanType isQuadratic();
428 
429 
431  inline BooleanType isConvex();
432 
433 
438  inline returnValue setReference( const VariablesGrid &ref );
439 
440 
446  BooleanType isEmpty() const;
447 
450  returnValue getLSQTerms( LsqElements& _elements ) const;
451  returnValue getLSQEndTerms( LsqElements& _elements ) const;
452 
453  returnValue getLSQTerms( LsqExternElements& _elements ) const;
454  returnValue getLSQEndTerms( LsqExternElements& _elements ) const;
455 
456  returnValue getLSQLinearTerms( LsqLinearElements& _elements ) const;
457 
460  uint getNumMayerTerms( ) const;
461  uint getNumLagrangeTerms( ) const;
462 
463  returnValue getMayerTerm( uint index, Function& mayerTerm ) const;
464  returnValue getLagrangeTerm( uint index, Function& lagrangeTerm ) const;
465 
466  //
467  // DATA MEMBERS:
468  //
469  protected:
470 
481 
484 
486 };
487 
489 
490 #include <acado/objective/objective.ipp>
491 
492 #endif // ACADO_TOOLKIT_OBJECTIVE_HPP
493 
494 /*
495  * end of file
496  */
Data class for storing generic optimization variables.
Definition: ocp_iterate.hpp:57
bool givenW
Definition: objective.hpp:58
Implements a very rudimentary block sparse matrix class.
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
LSQTerm ** lsqTerm
Definition: objective.hpp:471
std::vector< LsqLinearData > LsqLinearElements
Definition: objective.hpp:98
LsqData(const DMatrix &_WW, const Function &_hh, bool _givenW=true)
Definition: objective.hpp:48
Stores and evaluates Mayer terms within optimal control problems.
Definition: mayer_term.hpp:57
Stores and evaluates the constraints of optimal control problems.
Definition: constraint.hpp:60
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Allows to pass back messages to the calling function.
DMatrix Wlx
Definition: objective.hpp:92
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
Allows to conveniently handle (one-dimensional) grids consisting of time points.
Definition: grid.hpp:58
LsqExternElements cgExternLsqElements
Definition: objective.hpp:482
LsqExternElements cgExternLsqEndTermElements
Definition: objective.hpp:483
#define CLOSE_NAMESPACE_ACADO
uint nEndLSQ
Definition: objective.hpp:476
std::string h
Definition: objective.hpp:75
Base class for all variables within the symbolic expressions family.
Definition: expression.hpp:56
LsqElements cgLsqEndTermElements
Definition: objective.hpp:480
Stores and evaluates LSQ mayer terms within optimal control problems.
Provides a time grid consisting of matrix-valued optimization variables at each grid point...
std::vector< LsqData > LsqElements
Definition: objective.hpp:62
uint nMayer
Definition: objective.hpp:477
void rhs(const real_t *x, real_t *f)
LSQEndTerm ** lsqEndTerm
Definition: objective.hpp:472
Allows to setup and evaluate transition functions based on SymbolicExpressions.
Definition: transition.hpp:53
LsqLinearElements cgLsqLinearElements
Definition: objective.hpp:485
MayerTerm ** mayerTerm
Definition: objective.hpp:473
std::vector< LsqExternData > LsqExternElements
Definition: objective.hpp:81
Stores and evaluates Lagrange terms within optimal control problems.
#define BEGIN_NAMESPACE_ACADO
Stores and evaluates LSQ terms within optimal control problems.
Definition: lsq_term.hpp:61
LsqLinearData(const DVector &_Wlx, const DVector &_Wlu, bool _givenW=true)
Definition: objective.hpp:86
Function h
Definition: objective.hpp:56
DMatrix W
Definition: objective.hpp:54
LsqExternData(const DMatrix &_WW, const std::string &_hh, bool _givenW=true)
Definition: objective.hpp:67
void init(int nV, int nC, SymmetricMatrix *H, real_t *g, Matrix *A, const real_t *const lb, const real_t *const ub, const real_t *const lbA, const real_t *const ubA, int nWSR, const real_t *const x0, Options *options, int nOutputs, mxArray *plhs[])
LsqElements cgLsqElements
Definition: objective.hpp:479
Stores and evaluates the objective function of optimal control problems.
Definition: objective.hpp:123
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:54