Show
Ignore:
Timestamp:
06/09/10 14:00:40 (14 years ago)
Author:
mido
Message:

astyle applied all over the library

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/math/functions.h

    r800 r1064  
    2020//! class representing function \f$f(x) = a\f$, here \c rv is empty 
    2121class constfn : public fnc { 
    22         //! value of the function 
    23         vec val; 
     22    //! value of the function 
     23    vec val; 
    2424 
    2525public: 
    26         //vec eval() {return val;}; 
    27         //! inherited 
    28         vec eval ( const vec &cond ) { 
    29                 return val; 
    30         }; 
    31         //!Default constructor 
    32         constfn ( const vec &val0 ) : fnc(), val ( val0 ) { 
    33                 dimy = val.length(); 
    34                 dimc = 0; 
    35         }; 
     26    //vec eval() {return val;}; 
     27    //! inherited 
     28    vec eval ( const vec &cond ) { 
     29        return val; 
     30    }; 
     31    //!Default constructor 
     32    constfn ( const vec &val0 ) : fnc(), val ( val0 ) { 
     33        dimy = val.length(); 
     34        dimc = 0; 
     35    }; 
    3636}; 
    3737 
    3838//! Class representing function \f$f(x) = Ax+B\f$ 
    3939class linfn: public fnc { 
    40         //! Identification of \f$x\f$ 
    41         RV rv; 
    42         //! Matrix A 
    43         mat A; 
    44         //! vector B 
    45         vec B; 
     40    //! Identification of \f$x\f$ 
     41    RV rv; 
     42    //! Matrix A 
     43    mat A; 
     44    //! vector B 
     45    vec B; 
    4646public : 
    47         vec eval ( const vec &cond ) { 
    48                 bdm_assert_debug ( cond.length() == A.cols(), "linfn::eval Wrong cond." ); 
    49                 return A * cond + B; 
    50         } 
     47    vec eval ( const vec &cond ) { 
     48        bdm_assert_debug ( cond.length() == A.cols(), "linfn::eval Wrong cond." ); 
     49        return A * cond + B; 
     50    } 
    5151 
    5252//              linfn evalsome ( ivec &rvind ); 
    53         //!default constructor 
    54         linfn ( ) : fnc(), A ( ), B () { }; 
    55         //! Set values of \c A and \c B 
    56         void set_parameters ( const mat &A0 , const vec &B0 ) { 
    57                 A = A0; 
    58                 B = B0; 
    59         }; 
    60         void from_setting(const Setting &set){ 
    61                 UI::get(A,set,"A",UI::compulsory); 
    62                 UI::get(B,set,"B",UI::compulsory); 
    63         } 
    64         void validate(){ 
    65                 dimy = A.rows(); 
    66                 dimc = A.cols(); 
    67         } 
    68          
     53    //!default constructor 
     54    linfn ( ) : fnc(), A ( ), B () { }; 
     55    //! Set values of \c A and \c B 
     56    void set_parameters ( const mat &A0 , const vec &B0 ) { 
     57        A = A0; 
     58        B = B0; 
     59    }; 
     60    void from_setting(const Setting &set) { 
     61        UI::get(A,set,"A",UI::compulsory); 
     62        UI::get(B,set,"B",UI::compulsory); 
     63    } 
     64    void validate() { 
     65        dimy = A.rows(); 
     66        dimc = A.cols(); 
     67    } 
     68 
    6969}; 
    7070UIREGISTER(linfn); 
     
    8282class diffbifn: public fnc { 
    8383protected: 
    84         //! Indentifier of the first rv. 
    85         RV rvx; 
    86         //! Indentifier of the second rv. 
    87         RV rvu; 
    88         //! cache for rvx.count() 
    89         int dimx; 
    90         //! cache for rvu.count() 
    91         int dimu; 
     84    //! Indentifier of the first rv. 
     85    RV rvx; 
     86    //! Indentifier of the second rv. 
     87    RV rvu; 
     88    //! cache for rvx.count() 
     89    int dimx; 
     90    //! cache for rvu.count() 
     91    int dimu; 
    9292public: 
    93         //! Evaluates \f$f(x0,u0)\f$ (VS: Do we really need common eval? ) 
    94         vec eval ( const vec &cond ) { 
    95                 bdm_assert_debug ( cond.length() == ( dimx + dimu ), "linfn::eval Wrong cond." ); 
    96                 if ( dimu > 0 ) { 
    97                         return eval ( cond ( 0, dimx - 1 ), cond ( dimx, dimx + dimu - 1 ) );//-1 = end (in matlab) 
    98                 } else { 
    99                         return eval ( cond ( 0, dimx - 1 ), vec ( 0 ) );//-1 = end (in matlab) 
    100                 } 
     93    //! Evaluates \f$f(x0,u0)\f$ (VS: Do we really need common eval? ) 
     94    vec eval ( const vec &cond ) { 
     95        bdm_assert_debug ( cond.length() == ( dimx + dimu ), "linfn::eval Wrong cond." ); 
     96        if ( dimu > 0 ) { 
     97            return eval ( cond ( 0, dimx - 1 ), cond ( dimx, dimx + dimu - 1 ) );//-1 = end (in matlab) 
     98        } else { 
     99            return eval ( cond ( 0, dimx - 1 ), vec ( 0 ) );//-1 = end (in matlab) 
     100        } 
    101101 
    102         } 
     102    } 
    103103 
    104         //! Evaluates \f$f(x0,u0)\f$ 
    105         virtual vec eval ( const vec &x0, const vec &u0 ) { 
    106                 return zeros ( dimy ); 
    107         }; 
    108         //! Evaluates \f$A=\frac{d}{dx}f(x,u)|_{x0,u0}\f$ and writes result into \c A . @param full denotes that even unchanged entries are to be rewritten. When, false only the changed elements are computed. @param x0 numeric value of \f$x\f$, @param u0 numeric value of \f$u\f$ @param A a place where the result will be stored. 
    109         virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full = true ) {}; 
    110         //! Evaluates \f$A=\frac{d}{du}f(x,u)|_{x0,u0}\f$ and writes result into \c A . @param full denotes that even unchanged entries are to be rewritten. When, false only the changed elements are computed.        @param x0 numeric value of \f$x\f$, @param u0 numeric value of \f$u\f$ @param A a place where the result will be stored. 
    111         virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full = true ) {}; 
    112         //!Default constructor (dimy is not set!) 
    113         diffbifn () : fnc() {}; 
    114         //! access function 
    115         int _dimx() const { 
    116                 return dimx; 
    117         } 
    118         //! access function 
    119         int _dimu() const { 
    120                 return dimu; 
    121         } 
     104    //! Evaluates \f$f(x0,u0)\f$ 
     105    virtual vec eval ( const vec &x0, const vec &u0 ) { 
     106        return zeros ( dimy ); 
     107    }; 
     108    //! Evaluates \f$A=\frac{d}{dx}f(x,u)|_{x0,u0}\f$ and writes result into \c A . @param full denotes that even unchanged entries are to be rewritten. When, false only the changed elements are computed. @param x0 numeric value of \f$x\f$, @param u0 numeric value of \f$u\f$ @param A a place where the result will be stored. 
     109    virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full = true ) {}; 
     110    //! Evaluates \f$A=\frac{d}{du}f(x,u)|_{x0,u0}\f$ and writes result into \c A . @param full denotes that even unchanged entries are to be rewritten. When, false only the changed elements are computed.    @param x0 numeric value of \f$x\f$, @param u0 numeric value of \f$u\f$ @param A a place where the result will be stored. 
     111    virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full = true ) {}; 
     112    //!Default constructor (dimy is not set!) 
     113    diffbifn () : fnc() {}; 
     114    //! access function 
     115    int _dimx() const { 
     116        return dimx; 
     117    } 
     118    //! access function 
     119    int _dimu() const { 
     120        return dimu; 
     121    } 
    122122}; 
    123123 
     
    125125//TODO can be generalized into multilinear form! 
    126126class bilinfn: public diffbifn { 
    127         mat A; 
    128         mat B; 
     127    mat A; 
     128    mat B; 
    129129public : 
    130         //!\name Constructors 
    131         //!@{ 
     130    //!\name Constructors 
     131    //!@{ 
    132132 
    133         bilinfn () : diffbifn (), A(), B() { } 
     133    bilinfn () : diffbifn (), A(), B() { } 
    134134 
    135         bilinfn ( const mat &A0, const mat &B0 ) { 
    136                 set_parameters ( A0, B0 ); 
    137         } 
     135    bilinfn ( const mat &A0, const mat &B0 ) { 
     136        set_parameters ( A0, B0 ); 
     137    } 
    138138 
    139         //! Alternative initialization 
    140         void set_parameters ( const mat &A0, const mat &B0 ) { 
    141                 bdm_assert ( A0.rows() == B0.rows(), "bilinfn matrices must have the same number of rows" ); 
    142                 A = A0; 
    143                 B = B0; 
    144                 dimy = A.rows(); 
    145                 dimx = A.cols(); 
    146                 dimu = B.cols(); 
    147         } 
    148         //!@} 
     139    //! Alternative initialization 
     140    void set_parameters ( const mat &A0, const mat &B0 ) { 
     141        bdm_assert ( A0.rows() == B0.rows(), "bilinfn matrices must have the same number of rows" ); 
     142        A = A0; 
     143        B = B0; 
     144        dimy = A.rows(); 
     145        dimx = A.cols(); 
     146        dimu = B.cols(); 
     147    } 
     148    //!@} 
    149149 
    150         //!\name Mathematical operations 
    151         //!@{ 
    152         inline vec eval ( const  vec &x0, const vec &u0 ) { 
    153                 bdm_assert_debug ( x0.length() == dimx, "bilinfn::eval Wrong xcond." ); 
    154                 bdm_assert_debug ( u0.length() == dimu, "bilinfn::eval Wrong ucond." ); 
    155                 return A*x0 + B*u0; 
    156         } 
     150    //!\name Mathematical operations 
     151    //!@{ 
     152    inline vec eval ( const  vec &x0, const vec &u0 ) { 
     153        bdm_assert_debug ( x0.length() == dimx, "bilinfn::eval Wrong xcond." ); 
     154        bdm_assert_debug ( u0.length() == dimu, "bilinfn::eval Wrong ucond." ); 
     155        return A*x0 + B*u0; 
     156    } 
    157157 
    158         void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full ) { 
    159                 bdm_assert_debug ( ( F.cols() == A.cols() ) && ( F.rows() == A.rows() ), "Allocated F is not compatible." ); 
    160                 if ( full ) F = A;      //else : nothing has changed no need to regenerate 
    161         } 
     158    void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full ) { 
     159        bdm_assert_debug ( ( F.cols() == A.cols() ) && ( F.rows() == A.rows() ), "Allocated F is not compatible." ); 
     160        if ( full ) F = A;      //else : nothing has changed no need to regenerate 
     161    } 
    162162 
    163         void dfdu_cond ( const vec &x0, const vec &u0, mat &F,  bool full = true ) { 
    164                 bdm_assert_debug ( ( F.cols() == B.cols() ) && ( F.rows() == B.rows() ), "Allocated F is not compatible." ); 
    165                 if ( full ) F = B;      //else : nothing has changed no need to regenerate 
    166         } 
    167         //!@} 
     163    void dfdu_cond ( const vec &x0, const vec &u0, mat &F,  bool full = true ) { 
     164        bdm_assert_debug ( ( F.cols() == B.cols() ) && ( F.rows() == B.rows() ), "Allocated F is not compatible." ); 
     165        if ( full ) F = B;      //else : nothing has changed no need to regenerate 
     166    } 
     167    //!@} 
    168168}; 
    169169