GCOP  1.0
lscost.h
Go to the documentation of this file.
00001 #ifndef GCOP_LSCOST_H
00002 #define GCOP_LSCOST_H
00003 
00004 #include <Eigen/Dense>
00005 #include <iostream>
00006 #include "system.h"
00007 #include "cost.h"
00008 
00009 namespace gcop {
00010 
00011   using namespace Eigen;
00012   using namespace std;
00013   
00025   template <typename T = VectorXd, 
00026     int _nx = Dynamic,
00027     int _nu = Dynamic,
00028     int _np = Dynamic,
00029     int _ng = Dynamic,
00030     typename Tc = T> class LsCost : public Cost<T, _nx, _nu, _np, Tc> {
00031     
00032   public:
00033   
00034   typedef Matrix<double, _ng, 1> Vectorgd;
00035   typedef Matrix<double, _ng, _nx> Matrixgxd;
00036   typedef Matrix<double, _ng, _nu> Matrixgud;
00037   typedef Matrix<double, _ng, _np> Matrixgpd;
00038   
00039   typedef Matrix<double, _nx, 1> Vectornd;
00040   typedef Matrix<double, _nu, 1> Vectorcd;
00041   typedef Matrix<double, _np, 1> Vectormd;
00042   
00043   typedef Matrix<double, _nx, _nx> Matrixnd;
00044   typedef Matrix<double, _nx, _nu> Matrixncd;
00045   typedef Matrix<double, _nu, _nx> Matrixcnd;
00046   typedef Matrix<double, _nu, _nu> Matrixcd;
00047   
00048   //  typedef Matrix<double, Dynamic, 1> Vectormd;
00049   typedef Matrix<double, _np, _np> Matrixmd;
00050   typedef Matrix<double, _nx, _np> Matrixnmd;
00051   typedef Matrix<double, _np, _nx> Matrixmnd;
00052   
00059   LsCost(System<T, _nx, _nu, _np> &sys, double tf, int ng = 0);
00060   
00073   virtual bool Res(Vectorgd &g, 
00074                    double t, const T &x, const Vectorcd &u, double h,
00075                    const Vectormd *p = 0,
00076                    Matrixgxd *dgdx = 0, Matrixgud *dgdu = 0,
00077                    Matrixgpd *dgdp = 0);
00078 
00079   int ng;       
00080   Vectorgd g;   
00081   };
00082   
00083   
00084   template <typename T, int _nx, int _nu, int _np, int _ng, typename Tc> 
00085     LsCost<T, _nx, _nu, _np, _ng, Tc>::LsCost(System<T, _nx, _nu, _np> &sys, 
00086                                               double tf, int ng) : 
00087     Cost<T, _nx, _nu, _np, Tc>(sys, tf), ng(_ng != Dynamic ? _ng : ng)
00088     {
00089       assert(ng > 0);
00090       if (_ng == Dynamic)
00091         g.resize(ng);
00092     }
00093   
00094   template <typename T, int _nx, int _nu, int _np, int _ng, typename Tc> 
00095     bool LsCost<T, _nx, _nu, _np, _ng, Tc>::Res(Vectorgd &g, 
00096                                                 double t, const T &x, const Vectorcd &u, double h,
00097                                                 const Vectormd *p,
00098                                                 Matrixgxd *dgdx, Matrixgud *dgdu,
00099                                                 Matrixgpd *dgdp) {
00100     cout << "[W] LsCost:Res: unimplemented! Subclasses should override." << endl;
00101     return false;
00102   }
00103 }
00104 
00105 #endif
00106