GCOP  1.0
constraint.h
Go to the documentation of this file.
00001 // This file is part of libgcop, a library for Geometric Control, Optimization, and Planning (GCOP)
00002 //
00003 // Copyright (C) 2004-2014 Marin Kobilarov <marin(at)jhu.edu>
00004 //
00005 // This Source Code Form is subject to the terms of the Mozilla
00006 // Public License v. 2.0. If a copy of the MPL was not distributed
00007 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008 
00009 #ifndef GCOP_CONSTRAINT_H
00010 #define GCOP_CONSTRAINT_H
00011 
00012 #include <Eigen/Dense>
00013 #include <assert.h>
00014 
00015 namespace gcop {
00016   
00017   using namespace Eigen;  
00018   
00019   template <typename T = VectorXd,
00020     int _nx = Dynamic, 
00021     int _nu = Dynamic, 
00022     int _np = Dynamic,
00023     int _ng = Dynamic> class Constraint {
00024     
00025   public:
00026   
00027   typedef Matrix<double, _nx, 1> Vectornd;
00028   typedef Matrix<double, _nu, 1> Vectorcd;
00029   typedef Matrix<double, _np, 1> Vectormd;
00030   typedef Matrix<double, _ng, 1> Vectorgd;
00031 
00032   typedef Matrix<double, _ng, _nx> Matrixgnd;
00033   typedef Matrix<double, _ng, _nu> Matrixgcd;
00034   typedef Matrix<double, _ng, _np> Matrixgmd;
00035 
00036   typedef Matrix<double, _nx, _nx> Matrixnd;
00037   typedef Matrix<double, _nx, _nu> Matrixncd;
00038   typedef Matrix<double, _nu, _nx> Matrixcnd;
00039   typedef Matrix<double, _nu, _nu> Matrixcd;
00040   
00041   //  typedef Matrix<double, Dynamic, 1> Vectormd;
00042   typedef Matrix<double, _np, _np> Matrixmd;
00043   typedef Matrix<double, _nx, _np> Matrixnmd;
00044   typedef Matrix<double, _np, _nx> Matrixmnd;
00045     
00046   Constraint(int ng = 0) : ng(_ng != Dynamic ? _ng : ng) {
00047     assert(this->ng > 0);    
00048   }
00049 
00050   // constraint g(t,x,u,p)<=0 
00051   virtual bool operator()(Vectorgd &g,
00052                           double t, const T &x, const Vectorcd &u,
00053                           const Vectormd *p = 0, 
00054                           Matrixgnd *dgdx = 0, Matrixgcd *dgdu = 0,
00055                           Matrixgmd *dgdp = 0) = 0;
00056   
00057   // constraint g(t,x)<=0 
00058   virtual bool operator()(Vectorgd &g,
00059                           double t, const T &x, 
00060                           Matrixgnd *dgdx = 0) {
00061     return (*this)(g, t, x, ub, 0, dgdx);
00062   }
00063 
00064   int ng;        
00065   
00066   private:
00067   Vectorcd ub;   
00068   };
00069 }
00070 
00071 #endif
00072