GCOP  1.0
pqpdemcost.h
Go to the documentation of this file.
00001 #ifndef GCOP_PQPDEMCOST_H
00002 #define GCOP_PQPDEMCOST_H
00003 
00004 #include <limits>
00005 #include "constraintcost.h"
00006 #include "pqpdem.h"
00007 #include <iostream>
00008 
00009 namespace gcop {
00010   
00011   using namespace std;
00012   using namespace Eigen;
00013   
00014   template <typename T, 
00015     int _nx = Dynamic, 
00016     int _nu = Dynamic,
00017     int _np = Dynamic> class PqpDemCost : public ConstraintCost<T, _nx, _nu, _np, 1> {
00018     public:
00019 
00020   typedef Matrix<double, 1, 1> Vectorgd;
00021   typedef Matrix<double, 1, _nx> Matrixgxd;
00022   typedef Matrix<double, 1, _nu> Matrixgud;
00023   typedef Matrix<double, 1, _np> Matrixgpd;
00024 
00025   typedef Matrix<double, _nx, 1> Vectornd;
00026   typedef Matrix<double, _nu, 1> Vectorcd;
00027   typedef Matrix<double, _np, 1> Vectormd;
00028 
00029   typedef Matrix<double, _nx, _nx> Matrixnd;
00030   typedef Matrix<double, _nx, _nu> Matrixncd;
00031   typedef Matrix<double, _nu, _nx> Matrixcnd;
00032   typedef Matrix<double, _nu, _nu> Matrixcd;
00033   
00034   //  typedef Matrix<double, Dynamic, 1> Vectormd;
00035   typedef Matrix<double, _np, _np> Matrixmd;
00036   typedef Matrix<double, _nx, _np> Matrixnmd;
00037   typedef Matrix<double, _np, _nx> Matrixmnd;
00038       
00046     PqpDemCost(System<T, _nx, _nu, _np> &sys, tf, PqpDem<T, _nx, _nu, _np, 1> &con);   
00047 
00048     };
00049   
00050   template <typename T, int _nx, int _nu, int _np>
00051     PqpDemCost<T, _nx, _nu, _np>::PqpdemCost(System<T, _nx, _nu, _np> &sys, 
00052                                              tf, PqpDem<T, _nx, _nu, _np> &con) : 
00053     ConstraintCost(sys, tf, con)
00054     LsCost<T, _nx, _nu, _np, 1>(sys, tf, con.ng), con(con), b(1) {
00055 
00056     if (1 == Dynamic) {
00057       gp.resize(con.gn);
00058     }    
00059 
00060     if (_nx == Dynamic || 1 == Dynamic) {
00061       dgdx.resize(con.gn, sys.X.n);
00062     }
00063   }
00064   
00065   template <typename T, int _nx, int _nu, int _np, int 1> 
00066     double PqpdemCost<T, _nx, _nu, _np, 1y>::L(double t, const T &x, const Matrix<double, _nu, 1> &u,
00067                                                     double h,
00068                                                     const Matrix<double, _np, 1> *p,
00069                                                     Matrix<double, _nx, 1> *Lx, Matrix<double, _nx, _nx> *Lxx,
00070                                                     Matrix<double, _nu, 1> *Lu, Matrix<double, _nu, _nu> *Luu,
00071                                                     Matrix<double, _nx, _nu> *Lxu,
00072                                                     Matrix<double, _np, 1> *Lp, Matrix<double, _np, _np> *Lpp,
00073                                                     Matrix<double, _np, _nx> *Lpx) {
00074 
00075     // only consider state pqpdems for now
00076     this->con(this->g, t, x, u, p, Lx ? dgdx : 0);
00077 
00078     for (int i=0; i<con.ng; ++i) {
00079       if (this->g[i] < 0) { // if pqpdemy is satisfied then null it
00080         this->g[i] = 0;
00081         if (Lx)
00082           dgdx.row(i).setZero();
00083       }      
00084     }
00085     if (Lx)
00086       *Lx = b*dgdx.transpose()*this->g;
00087     if (Lxx)
00088       *Lxx = b*dgdx.transpose()*dgdx;
00089 
00090     return b/2*this->g.squaredNorm();
00091   }  
00092 }
00093 
00094 
00095 #endif