Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00034 #ifndef ACADO_TOOLKIT_OBJECTIVE_HPP
00035 #define ACADO_TOOLKIT_OBJECTIVE_HPP
00036
00037 #include <acado/objective/lagrange_term.hpp>
00038 #include <acado/objective/lsq_term.hpp>
00039 #include <acado/objective/lsq_end_term.hpp>
00040 #include <acado/objective/mayer_term.hpp>
00041 #include <acado/constraint/constraint.hpp>
00042
00043 BEGIN_NAMESPACE_ACADO
00044
00046 struct LsqData
00047 {
00048 LsqData(const DMatrix& _WW, const Function& _hh, bool _givenW = true)
00049 : W( _WW ), h( _hh ), givenW( _givenW )
00050 {}
00051
00054 DMatrix W;
00056 Function h;
00058 bool givenW;
00059 };
00060
00062 typedef std::vector< LsqData > LsqElements;
00063
00065 struct LsqExternData
00066 {
00067 LsqExternData(const DMatrix& _WW, const std::string& _hh, bool _givenW = true)
00068 : W( _WW ), h( _hh ), givenW( _givenW )
00069 {}
00070
00073 DMatrix W;
00075 std::string h;
00077 bool givenW;
00078 };
00079
00081 typedef std::vector< LsqExternData > LsqExternElements;
00082
00084 struct LsqLinearData
00085 {
00086 LsqLinearData(const DVector& _Wlx, const DVector& _Wlu, bool _givenW = true)
00087 : Wlx( _Wlx ), Wlu( _Wlu ), givenW( _givenW )
00088 {}
00089
00092 DMatrix Wlx, Wlu;
00094 bool givenW;
00095 };
00096
00098 typedef std::vector< LsqLinearData > LsqLinearElements;
00099
00123 class Objective : public LagrangeTerm
00124 {
00125
00126
00127
00128 public:
00129
00131 Objective( );
00132
00134 Objective( const Grid &grid_ );
00135
00137 Objective( const Objective& rhs );
00138
00140 virtual ~Objective( );
00141
00143 Objective& operator=( const Objective& rhs );
00144
00145
00146
00151 returnValue init( const Grid &grid_ );
00152
00153
00154
00155
00156
00157
00158
00159
00160
00164 inline returnValue addMayerTerm( const Expression& arg );
00165 inline returnValue addMayerTerm( const Function& arg );
00166
00167
00168
00180 returnValue addLSQ( const MatrixVariablesGrid *S_,
00181 const Function& h ,
00182 const VariablesGrid *r_ );
00183
00184
00185
00195 returnValue addLSQEndTerm( const DMatrix & S,
00196 const Function & m,
00197 const DVector & r );
00198
00199
00200
00201
00202
00203 returnValue addLSQ(const DMatrix& S, const Function& h);
00204
00205 returnValue addLSQEndTerm(const DMatrix& S, const Function& h);
00206
00207 returnValue addLSQ(const DMatrix& S, const std::string& h);
00208
00209 returnValue addLSQEndTerm(const DMatrix& S, const std::string& h);
00210
00211 returnValue addLSQ(const BMatrix& S, const Function& h);
00212
00213 returnValue addLSQEndTerm(const BMatrix& S, const Function& h);
00214
00215 returnValue addLSQ(const BMatrix& S, const std::string& h);
00216
00217 returnValue addLSQEndTerm(const BMatrix& S, const std::string& h);
00218
00219 returnValue addLSQLinearTerms(const DVector& Slx, const DVector& Slu);
00220
00221 returnValue addLSQLinearTerms(const BVector& Slx, const BVector& Slu);
00222
00223
00224
00225
00226
00227
00228
00243 returnValue init( const int nStages ,
00244 const int nTransitions,
00245 DifferentialEquation **fcn ,
00246 Transition *transitions ,
00247 Constraint *constraint_ );
00248
00249
00250
00251
00252
00253
00254
00255
00256
00262 virtual returnValue setForwardSeed( BlockMatrix *xSeed_ ,
00263 BlockMatrix *xaSeed_,
00264 BlockMatrix *pSeed_ ,
00265 BlockMatrix *uSeed_ ,
00266 BlockMatrix *wSeed_ ,
00267 int order );
00268
00269
00270
00276 virtual returnValue setBackwardSeed( BlockMatrix *seed,
00277 int order );
00278
00279
00280
00287 virtual returnValue setUnitBackwardSeed( );
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00304 returnValue evaluate( const OCPiterate &x );
00305
00306
00307
00313 returnValue evaluateSensitivities();
00314
00315
00321 returnValue evaluateSensitivities( BlockMatrix &hessian );
00322
00323
00331 returnValue evaluateSensitivitiesGN( BlockMatrix &hessian );
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00347 virtual returnValue getObjectiveValue( double &objectiveValue );
00348
00349
00350
00356 virtual returnValue getForwardSensitivities( BlockMatrix &D ,
00359 int order );
00360
00361
00362
00368 virtual returnValue getBackwardSensitivities( BlockMatrix &D ,
00371 int order );
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00387 inline int getNX () const;
00388
00392 inline int getNXA () const;
00393
00397 inline int getNP () const;
00398
00402 inline int getNU () const;
00403
00407 inline int getNW () const;
00408
00409
00410
00411
00412
00419 inline BooleanType hasLSQform();
00420
00421
00423 inline BooleanType isAffine();
00424
00425
00427 inline BooleanType isQuadratic();
00428
00429
00431 inline BooleanType isConvex();
00432
00433
00438 inline returnValue setReference( const VariablesGrid &ref );
00439
00440
00446 BooleanType isEmpty() const;
00447
00450 returnValue getLSQTerms( LsqElements& _elements ) const;
00451 returnValue getLSQEndTerms( LsqElements& _elements ) const;
00452
00453 returnValue getLSQTerms( LsqExternElements& _elements ) const;
00454 returnValue getLSQEndTerms( LsqExternElements& _elements ) const;
00455
00456 returnValue getLSQLinearTerms( LsqLinearElements& _elements ) const;
00457
00460 uint getNumMayerTerms( ) const;
00461 uint getNumLagrangeTerms( ) const;
00462
00463 returnValue getMayerTerm( uint index, Function& mayerTerm ) const;
00464 returnValue getLagrangeTerm( uint index, Function& lagrangeTerm ) const;
00465
00466
00467
00468
00469 protected:
00470
00471 LSQTerm **lsqTerm ;
00472 LSQEndTerm **lsqEndTerm;
00473 MayerTerm **mayerTerm ;
00475 uint nLSQ ;
00476 uint nEndLSQ ;
00477 uint nMayer ;
00479 LsqElements cgLsqElements;
00480 LsqElements cgLsqEndTermElements;
00481
00482 LsqExternElements cgExternLsqElements;
00483 LsqExternElements cgExternLsqEndTermElements;
00484
00485 LsqLinearElements cgLsqLinearElements;
00486 };
00487
00488 CLOSE_NAMESPACE_ACADO
00489
00490 #include <acado/objective/objective.ipp>
00491
00492 #endif // ACADO_TOOLKIT_OBJECTIVE_HPP
00493
00494
00495
00496