00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 #ifndef FN_H
00013 #define FN_H
00014 
00015 #include "libBM.h"
00016 
00017 namespace bdm{
00018 
00020 class constfn : public fnc
00021 {
00023                 vec val;
00024 
00025         public:
00026                 
00028                 vec eval ( const vec &cond ) {return val;};
00030                 constfn ( const vec &val0 ) :fnc(val0.length()), val ( val0 ) {};
00031 };
00032 
00034 class linfn: public fnc
00035 {
00037                 RV rv;
00039                 mat A;
00041                 vec B;
00042         public :
00043                 vec eval (const vec &cond ) {it_assert_debug ( cond.length() ==rv.count(), "linfn::eval Wrong cond." );return A*cond+B;};
00044 
00045 
00047                 linfn ( const RV &rv0 ) : fnc(rv0.count()), rv ( rv0 ),A ( eye ( rv0.count() ) ),B ( zeros ( rv0.count() ) ) { };
00049                 void set_parameters ( const mat &A0 , const vec &B0 ) {A=A0; B=B0;};
00050 };
00051 
00052 
00062 class diffbifn: public fnc
00063 {
00064         protected:
00066                 RV rvx;
00068                 RV rvu;
00070                 int dimx;
00072                 int dimu;
00073         public:
00075                 vec eval ( const vec &cond )
00076                 {
00077                         it_assert_debug ( cond.length() == ( dimx+dimu ), "linfn::eval Wrong cond." );
00078                         return eval ( cond ( 0,dimx-1 ),cond ( dimx,dimx+dimu ) );
00079                 };
00080 
00082                 virtual vec eval ( const vec &x0, const vec &u0 ) {return zeros ( dimy );};
00084                 virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full=true ) {};
00086                 virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {};
00088                 diffbifn (int dimy, const RV rvx0, const RV rvu0 ) : fnc(dimy), rvx ( rvx0 ),rvu ( rvu0 ) {dimx=rvx.count();dimu=rvu.count();};
00090                 int _dimx() const{return dimx;}
00092                 int _dimu() const{return dimu;}
00093 };
00094 
00096 
00097 class bilinfn: public diffbifn
00098 {
00099                 mat A;
00100                 mat B;
00101         public :
00102                 vec eval ( const  vec &x0, const vec &u0 );
00103 
00105                 bilinfn ( const RV &rvx0, const RV &rvu0 ) : diffbifn (dimx, rvx0,rvu0 ) ,A ( eye ( dimx ) ),B ( zeros ( dimx,dimu ) )  {};
00107                 bilinfn ( const RV &rvx0, const RV &rvu0, const mat &A0, const mat &B0 );
00109                 void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full )
00110                 {
00111                         it_assert_debug ( ( F.cols() ==A.cols() ) & ( F.rows() ==A.rows() ),"Allocated F is not compatible." );
00112                         if ( full ) F=A;        
00113                 }
00115                 void dfdu_cond ( const vec &x0, const vec &u0, mat &F,  bool full=true )
00116                 {
00117                         it_assert_debug ( ( F.cols() ==B.cols() ) & ( F.rows() ==B.rows() ),"Allocated F is not compatible." );
00118                         if ( full ) F=B;        
00119                 }
00120 };
00121 
00122 } 
00123 #endif // FN_H