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(), val ( val0 ) {dimy=val.length();};
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 ( ) : fnc(), A ( ),B () { };
00049                 void set_parameters ( const mat &A0 , const vec &B0 ) {A=A0; B=B0; dimy=A.rows();};
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 () : fnc() {};
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 () : diffbifn () ,A() ,B()      {};
00107                 void set_parameters(const mat A0, const mat B0){
00108                         it_assert_debug(A0.rows()==B0.rows(),"");
00109                         A=A0;B=B0;
00110                         dimy=A.rows();
00111                         dimx=A.cols();
00112                         dimu=B.cols();
00113                 }
00115                 void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full )
00116                 {
00117                         it_assert_debug ( ( F.cols() ==A.cols() ) & ( F.rows() ==A.rows() ),"Allocated F is not compatible." );
00118                         if ( full ) F=A;        
00119                 }
00121                 void dfdu_cond ( const vec &x0, const vec &u0, mat &F,  bool full=true )
00122                 {
00123                         it_assert_debug ( ( F.cols() ==B.cols() ) & ( F.rows() ==B.rows() ),"Allocated F is not compatible." );
00124                         if ( full ) F=B;        
00125                 }
00126 };
00127 
00128 } 
00129 #endif // FN_H