Changeset 738 for library/bdm/design

Show
Ignore:
Timestamp:
11/25/09 12:46:08 (15 years ago)
Author:
mido
Message:

a few moves of code from h to cpp, however, only part of the whole library is done

Location:
library/bdm/design
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/design/ctrlbase.cpp

    r737 r738  
    77} 
    88 
     9void LQG::update_system() { 
     10        pr.set_submatrix ( 0, 0, S->_B() ); 
     11        pr.set_submatrix ( 0, dimu, S->_A() ); 
     12 
     13        //penalization 
     14        qux.set_submatrix ( 0, 0, Qu._Ch() ); 
     15        qux.set_submatrix ( 0, dimx + dimu + dimy, Qu._Ch() ); 
     16 
     17        qyx.set_submatrix ( 0, 0, S->_C() ); 
     18        qyx.set_submatrix ( 0, dimx, -eye ( dimy ) ); 
     19 
     20        // parts of QR 
     21        hqy = Qy.to_mat() * qyx * pr; 
     22 
     23        // pre_qr 
     24        pre_qr = concat_vertical ( s * pr, concat_vertical ( hqy, qux ) ); 
     25} 
     26         
    927void LQG::set_control_parameters ( const mat &Qy0, const mat &Qu0, const vec &y_req0, int horizon0 ) { 
    1028        Qy = Qy0; 
     
    3856} 
    3957 
     58void LQG::ricatti_step() { 
     59        pre_qr.set_submatrix ( 0, 0, s*pr ); 
     60        pre_qr.set_submatrix ( dimx + dimu + dimy, dimu + dimx, -Qy.to_mat() *y_req ); 
     61        if ( !qr ( pre_qr, post_qr ) ) { 
     62                bdm_warning ( "QR in LQG unstable" ); 
     63        } 
     64        triu ( post_qr ); 
     65        // hn(m+1:2*m+n+r,m+1:2*m+n+r); 
     66        s = post_qr.get ( dimu, 2 * dimu + dimx + dimy - 1, dimu, 2 * dimu + dimx + dimy - 1 ); 
     67}; 
     68 
     69void LQG::redesign() { 
     70        for ( td = horizon; td > 0; td-- ) { 
     71                update_system(); 
     72                ricatti_step(); 
     73        } 
     74        /*                      ws=hn(1:m,m+1:2*m+n+r); 
     75                                wsd=hn(1:m,1:m); 
     76                                Lklq=-inv(wsd)*ws;*/ 
     77        L = -inv ( post_qr.get ( 0, dimu - 1, 0, dimu - 1 ) ) * post_qr.get ( 0, dimu - 1, dimu, 2 * dimu + dimx + dimy - 1 ); 
     78} 
     79 
    4080 
    4181} 
  • library/bdm/design/ctrlbase.h

    r737 r738  
    106106        void set_system ( shared_ptr<StateSpace<chmat> > S0 ); 
    107107        //! update internal whan system has changed 
    108         void update_system() { 
    109                 pr.set_submatrix ( 0, 0, S->_B() ); 
    110                 pr.set_submatrix ( 0, dimu, S->_A() ); 
    111  
    112                 //penalization 
    113                 qux.set_submatrix ( 0, 0, Qu._Ch() ); 
    114                 qux.set_submatrix ( 0, dimx + dimu + dimy, Qu._Ch() ); 
    115  
    116                 qyx.set_submatrix ( 0, 0, S->_C() ); 
    117                 qyx.set_submatrix ( 0, dimx, -eye ( dimy ) ); 
    118  
    119                 // parts of QR 
    120                 hqy = Qy.to_mat() * qyx * pr; 
    121  
    122                 // pre_qr 
    123                 pre_qr = concat_vertical ( s * pr, concat_vertical ( hqy, qux ) ); 
    124         } 
     108        void update_system(); 
    125109        //! set penalization matrices and control horizon 
    126110        void set_control_parameters ( const mat &Qy0, const mat &Qu0, const vec &y_req0, int horizon0 ); 
     
    137121        //! function for future use which is called at each time td; Should call initialize()! 
    138122        //! redesign one step of the 
    139         void ricatti_step() { 
    140                 pre_qr.set_submatrix ( 0, 0, s*pr ); 
    141                 pre_qr.set_submatrix ( dimx + dimu + dimy, dimu + dimx, -Qy.to_mat() *y_req ); 
    142                 if ( !qr ( pre_qr, post_qr ) ) { 
    143                         bdm_warning ( "QR in LQG unstable" ); 
    144                 } 
    145                 triu ( post_qr ); 
    146                 // hn(m+1:2*m+n+r,m+1:2*m+n+r); 
    147                 s = post_qr.get ( dimu, 2 * dimu + dimx + dimy - 1, dimu, 2 * dimu + dimx + dimy - 1 ); 
    148         }; 
    149         void redesign() { 
    150                 for ( td = horizon; td > 0; td-- ) { 
    151                         update_system(); 
    152                         ricatti_step(); 
    153                 } 
    154                 /*                      ws=hn(1:m,m+1:2*m+n+r); 
    155                                         wsd=hn(1:m,1:m); 
    156                                         Lklq=-inv(wsd)*ws;*/ 
    157                 L = -inv ( post_qr.get ( 0, dimu - 1, 0, dimu - 1 ) ) * post_qr.get ( 0, dimu - 1, dimu, 2 * dimu + dimx + dimy - 1 ); 
    158         } 
     123        void ricatti_step(); 
     124         
     125        void redesign(); 
     126 
    159127        //! compute control action 
    160128        vec ctrlaction ( const vec &state, const vec &ukm ) const {