Changeset 357

Show
Ignore:
Timestamp:
06/08/09 02:15:30 (16 years ago)
Author:
mido
Message:

mnoho zmen:
1) presun FindXXX modulu do \system
2) zalozeni dokumentace \doc\local\library_structure.dox
3) presun obsahu \tests\UI primo do \tests
4) namisto \INSTALL zalozen \install.html, je to vhodnejsi pro uzivatele WINDOWS, a snad i obecne
5) snaha o predelani veskerych UI podle nove koncepce, soubory pmsm_ui.h, arx_ui.h, KF_ui.h, libDS_ui.h, libEF_ui.h a loggers_ui.h ponechavam
jen zdokumentacnich duvodu, nic by na nich jiz nemelo zaviset, a po zkontrolovani spravnosti provedenych uprav by mely byt smazany
6) predelani estimatoru tak, aby fungoval s novym UI konceptem
7) vytazeni tridy bdmroot do samostatneho souboru \bdm\bdmroot.h
8) pridana dokumentace pro zacleneni programu ASTYLE do Visual studia, ASTYLE pridan do instalacniho balicku pro Windows

Files:
5 added
2 removed
31 modified
6 copied
1 moved

Legend:

Unmodified
Added
Removed
  • CMakeLists.txt

    r341 r357  
    1010# location of the FindXXX.cmake file must be added to the cmake modules  
    1111# list from within a CMakeLists.txt file as follows: 
    12 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}\\CMake_modules\\") 
     12set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}\\system\\") 
    1313 
    1414###################### 
     
    1818# THEN IT IS NECESSARY TO CREATE TEXT FILE "\system\WIN32\LOCAL_PATHS.TXT" WITH  
    1919# COPIES OF THE TWO FOLLOWING LINES AND THEN CORECT ALL THE INVOLVED PATHS 
    20         SET(ITPP_DIR "${BDM_SOURCE_DIR}\\system\\\\win32\\itpp-4.0.6") 
     20        SET(ITPP_DIR "${BDM_SOURCE_DIR}\\system\\win32\\itpp-4.0.6") 
    2121        SET(ACML_DIR "${BDM_SOURCE_DIR}\\system\\win32\\acml3.6.0") 
    2222 
  • applications/doprava/k1.cpp

    r341 r357  
    1313 
    1414#include <estim/ekf_templ.h> 
    15 #include <stat/loggers_ui.h> 
    16 #include <stat/libDS_ui.h> 
    1715 
    1816//include dopravni model 
    1917#include "model.h" 
     18#include "stat\libDS.h" 
     19#include "stat\loggers.h" 
    2020 
    2121using namespace bdm; 
  • applications/mpdm/CMakeLists.txt

    r299 r357  
    1 # Make sure the compiler can find include files from our Bdm library. 
    2 include_directories (${BDM_SOURCE_DIR}/bdm) 
    3 link_directories (${BDM_BINARY_DIR}/bdm) 
     1# Compulsory line 
     2cmake_minimum_required(VERSION 2.6) 
    43 
    5 EXEC(merg_pred) 
    6 EXEC(merg_giw) 
    7 EXEC(TR2244/merger_iter_cond) 
    8 EXEC(SYSID09/merg_2a) 
     4add_subdirectory (SYSID09) 
     5add_subdirectory (TR2244) 
     6 
  • applications/pmsm/CMakeLists.txt

    r284 r357  
    1313## Build simulator 
    1414add_subdirectory (simulator_zdenek) 
    15 add_subdirectory (simulator_zdenek/ekf_example) 
     15#add_subdirectory (simulator_zdenek/ekf_example) 
    1616 
    1717## Use it 
  • applications/pmsm/TR2245/pmsm_wishart.cpp

    r332 r357  
    1717#include <stat/libFN.h> 
    1818 
    19 #include <stat/loggers_ui.h> 
    20 #include <stat/libEF_ui.h> 
    21  
    22 #include "../pmsm_ui.h" 
     19#include "user_info.h" 
     20#include "../pmsmDS.h" 
    2321 
    2422using namespace bdm; 
     
    2826        if ( argc>1 ) {fname = argv[1]; } 
    2927        else { fname = "pmsm_wishart.cfg"; } 
    30         UIFile F ( fname ); 
     28        UI_File F ( fname ); 
     29 
     30        double h = 1e-6; 
     31        int Nsimstep = 125; 
     32 
     33        // Kalman filter 
     34        double k; 
     35        double l; 
     36        F.lookupValue ( "k",k); 
     37        F.lookupValue ( "l",l); 
    3138 
    3239        int Ndat; 
    3340        int Npart; 
    34         double h = 1e-6; 
    35         int Nsimstep = 125; 
     41        F.lookupValue ( "ndat", Ndat ); 
     42        F.lookupValue ( "Npart", Npart ); 
    3643 
    3744        vec Qdiag; 
    3845        vec Rdiag; 
     46        UI::get( Qdiag, F, "dQ" ); //( "1e-6 1e-6 0.001 0.0001" ); //zdenek: 0.01 0.01 0.0001 0.0001 
     47        UI::get( Rdiag, F, "dR" );// ( "1e-8 1e-8" ); //var(diff(xth)) = "0.034 0.034" 
     48                 
     49        pmsmDS* DS = UI::build<pmsmDS>(F,"system"); 
     50        //      mpdf* evolQ = UI::build<mpdf>( F, "Qrw" ); 
    3951 
    40         pmsmDS* DS; 
    41  
    42         double k; 
    43         double l; 
    44 //      mpdf* evolQ ; 
    45         try { 
    46                 // Kalman filter 
    47                 F.lookupValue ( "ndat", Ndat ); 
    48                 F.lookupValue ( "Npart",Npart ); 
    49                  
    50                 F.lookupValue ( "k", k); 
    51                 F.lookupValue ( "l",l); 
    52  
    53 //              UIbuild ( F.lookup ( "Qrw" ),evolQ ); 
    54                 Qdiag= getvec ( F.lookup ( "dQ" ) ); //( "1e-6 1e-6 0.001 0.0001" ); //zdenek: 0.01 0.01 0.0001 0.0001 
    55                 Rdiag=getvec ( F.lookup ( "dR" ) );// ( "1e-8 1e-8" ); //var(diff(xth)) = "0.034 0.034" 
    56                  
    57                 UIbuild(F.lookup("system"),DS); 
    58         } 
    59         catch UICATCH; 
    60 // internal model 
    61  
    62 IMpmsm fxu; 
    63 //                  Rs    Ls        dt       Fmag(Ypm)    kp   p    J     Bf(Mz) 
    64 fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989, 1.5 ,4.0, 0.04, 0.0 ); 
     52        // internal model 
     53        IMpmsm fxu; 
     54        //                  Rs    Ls        dt       Fmag(Ypm)    kp   p    J     Bf(Mz) 
     55        fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989, 1.5 ,4.0, 0.04, 0.0 ); 
    6556        // observation model 
    6657        OMpmsm hxu; 
     
    9182        M.set_rv ( concat ( rQ,rx ) ); 
    9283 
    93         dirfilelog *L; UIbuild ( F.lookup ( "logger" ), L );// ( "exp/mpf_test",100 ); 
     84        dirfilelog *L = UI::build<dirfilelog> ( F, "logger" );// ( "exp/mpf_test",100 ); 
    9485         
    9586        KFE.set_options ( "logbounds" ); 
  • applications/pmsm/TR2245/unitsteps.cpp

    r317 r357  
    1717#include <stat/libFN.h> 
    1818 
    19 #include <stat/loggers_ui.h> 
    20 #include <stat/libEF_ui.h> 
    2119 
    2220#include "../pmsm.h" 
    2321#include "simulator.h" 
    2422#include "../sim_profiles.h" 
     23#include "user_info.h" 
     24#include "stat/loggers.h" 
    2525 
    2626using namespace bdm; 
     
    3030        if ( argc>1 ) {fname = argv[1]; } 
    3131        else { fname = "unitsteps.cfg"; } 
    32         UIFile F ( fname ); 
     32        UI_File F ( fname ); 
    3333 
    34         int Ndat; 
    35         int Npart; 
    3634        double h = 1e-6; 
    3735        int Nsimstep = 125; 
    3836 
     37 
     38        // Kalman filter 
     39        int Ndat; 
     40        int Npart; 
     41        F.lookupValue ( "ndat", Ndat ); 
     42        F.lookupValue ( "Npart",Npart ); 
     43        mpdf* evolQ = UI::build<mpdf>( F, "Qrw" ); 
    3944        vec Qdiag; 
    4045        vec Rdiag; 
     46        UI::get( Qdiag, F, "dQ" ); //( "1e-6 1e-6 0.001 0.0001" ); //zdenek: 0.01 0.01 0.0001 0.0001 
     47        UI::get( Rdiag, F, "dR" );// ( "1e-8 1e-8" ); //var(diff(xth)) = "0.034 0.034" 
    4148 
    42         mpdf* evolQ ; 
    43         try { 
    44                 // Kalman filter 
    45                 F.lookupValue ( "ndat", Ndat ); 
    46                 F.lookupValue ( "Npart",Npart ); 
    47  
    48                 UIbuild ( F.lookup ( "Qrw" ),evolQ ); 
    49                 Qdiag= getvec ( F.lookup ( "dQ" ) ); //( "1e-6 1e-6 0.001 0.0001" ); //zdenek: 0.01 0.01 0.0001 0.0001 
    50                 Rdiag=getvec ( F.lookup ( "dR" ) );// ( "1e-8 1e-8" ); //var(diff(xth)) = "0.034 0.034" 
    51         } 
    52         catch UICATCH; 
    53 // internal model 
     49        // internal model 
    5450 
    5551IMpmsm fxu; 
     
    8177        M.set_rv ( concat ( rQ,rx ) ); 
    8278 
    83         dirfilelog *L; UIbuild ( F.lookup ( "logger" ), L );// ( "exp/mpf_test",100 ); 
     79        dirfilelog *L = UI::build<dirfilelog>( F, "logger" );// ( "exp/mpf_test",100 ); 
    8480        int l_X = L->add ( rx, "xt" ); 
    8581        int l_D = L->add ( concat ( ry,ru ), "" ); 
     
    9995        vec xtm=zeros ( 4 ); 
    10096        double Ww=0.0; 
    101         vec vecW=getvec ( F.lookup ( "profile" ) ); 
     97        vec vecW; 
     98        UI::get( vecW, F, "profile" ); 
    10299 
    103100        for ( int tK=1;tK<Ndat;tK++ ) { 
  • applications/pmsm/TR2245/wishart.cpp

    r317 r357  
    1717#include <stat/libFN.h> 
    1818 
    19 #include <stat/loggers_ui.h> 
    20 #include <stat/libEF_ui.h> 
    21  
    2219#include "../pmsm.h" 
    2320#include "simulator.h" 
    2421#include "../sim_profiles.h" 
     22#include "user_info.h" 
     23#include "stat/loggers.h" 
    2524 
    2625using namespace bdm; 
     
    3029        if ( argc>1 ) {fname = argv[1]; } 
    3130        else { fname = "unitsteps.cfg"; } 
    32         UIFile F ( fname ); 
     31        UI_File F ( fname ); 
    3332 
     33        double h = 1e-6; 
    3434        int Ndat; 
    3535        int Npart; 
    36         double h = 1e-6; 
     36        F.lookupValue ( "ndat", Ndat ); 
     37        F.lookupValue ( "Npart",Npart ); 
    3738        int Nsimstep = 125; 
    3839 
     40                // Kalman filter 
    3941        vec Qdiag; 
     42        UI::get( Qdiag, F, "dQ" ); //( "1e-6 1e-6 0.001 0.0001" ); //zdenek: 0.01 0.01 0.0001 0.0001 
     43                 
    4044        vec Rdiag; 
     45        UI::get( Rdiag, F, "dR" );// ( "1e-8 1e-8" ); //var(diff(xth)) = "0.034 0.034" 
    4146 
    42 //      mpdf* evolQ ; 
    43         try { 
    44                 // Kalman filter 
    45                 F.lookupValue ( "ndat", Ndat ); 
    46                 F.lookupValue ( "Npart",Npart ); 
    47  
    48 //              UIbuild ( F.lookup ( "Qrw" ),evolQ ); 
    49                 Qdiag= getvec ( F.lookup ( "dQ" ) ); //( "1e-6 1e-6 0.001 0.0001" ); //zdenek: 0.01 0.01 0.0001 0.0001 
    50                 Rdiag=getvec ( F.lookup ( "dR" ) );// ( "1e-8 1e-8" ); //var(diff(xth)) = "0.034 0.034" 
    51         } 
    52         catch UICATCH; 
    53 // internal model 
    54  
    55 IMpmsm fxu; 
    56 //                  Rs    Ls        dt       Fmag(Ypm)    kp   p    J     Bf(Mz) 
    57 fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989, 1.5 ,4.0, 0.04, 0.0 ); 
     47        // internal model 
     48        IMpmsm fxu; 
     49        //                  Rs    Ls        dt       Fmag(Ypm)    kp   p    J     Bf(Mz) 
     50        fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989, 1.5 ,4.0, 0.04, 0.0 ); 
    5851        // observation model 
    5952        OMpmsm hxu; 
     
    8477        M.set_rv ( concat ( rQ,rx ) ); 
    8578 
    86         dirfilelog *L; UIbuild ( F.lookup ( "logger" ), L );// ( "exp/mpf_test",100 ); 
     79        dirfilelog *L = UI::build<dirfilelog> ( F, "logger" );// ( "exp/mpf_test",100 ); 
    8780        int l_X = L->add ( rx, "xt" ); 
    8881        int l_D = L->add ( concat ( ry,ru ), "" ); 
     
    10396        vec xtm=zeros ( 4 ); 
    10497        double Ww=0.0; 
    105         vec vecW=getvec ( F.lookup ( "profile" ) ); 
     98        vec vecW; 
     99        UI::get( vecW, F ,"profile" ); 
    106100         
    107101        mat tQ=diag(Qdiag); 
  • applications/pmsm/pmsm.h

    r349 r357  
    33 
    44#include <stat/libFN.h> 
     5#include "user_info.h" 
    56 
    67/*! \defgroup PMSM  
     
    9495 
    9596        void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );}; 
    96 }; 
    97  
     97 
     98        void from_setting( const Setting &root ) 
     99        {        
     100                set_parameters ( root["params"]["Rs"], root["params"]["Ls"], 125e-6, root["params"]["Fmag"], \ 
     101                        root["params"]["kp"],  root["params"]["p"], root["params"]["J"], 0.0 ); 
     102        }; 
     103 
     104        // TODO dodelat void to_setting( Setting &root ) const; 
     105}; 
     106 
     107UIREGISTER ( IMpmsm ); 
    98108 
    99109//! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$ 
     
    182192}; 
    183193 
     194 
     195UIREGISTER ( IMpmsm2o ); 
     196 
    184197//! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$, equation for \f$\omega\f$ is omitted.$ 
    185198class IMpmsmStat : public IMpmsm { 
     
    234247}; 
    235248 
     249UIREGISTER ( IMpmsmStat ); 
     250 
     251 
    236252//! State for PMSM with unknown Mz 
    237253class IMpmsmMz: public IMpmsm{ 
     
    256272}; 
    257273 
     274UIREGISTER ( IMpmsmMz ); 
     275 
    258276//! State for PMSM with unknown Mz 
    259277class IMpmsmStatMz: public IMpmsmStat{ 
     
    278296}; 
    279297 
     298UIREGISTER ( IMpmsmStatMz ); 
     299 
    280300 
    281301//! Observation model for PMSM drive and its derivative with respect to \f$x\f$ 
     
    298318}; 
    299319 
     320UIREGISTER ( OMpmsm ); 
     321 
    300322//! Observation model for PMSM drive and its derivative with respect to \f$x\f$ for full vector of observations 
    301323class OMpmsm4: public diffbifn { 
     
    314336}; 
    315337 
     338UIREGISTER ( OMpmsm4 ); 
     339 
     340 
     341 
     342 
     343 
    316344/*!@}*/ 
    317345#endif //PMSM_H 
  • applications/pmsm/pmsmDS.h

    r349 r357  
    1717 
    1818//! Simulator of PMSM machine with predefined profile on omega 
    19 class pmsmDS : public DS { 
     19class pmsmDS : public DS 
     20{ 
    2021 
    2122protected: 
    22         //! indeces of logged variables 
    23         int L_x, L_ou, L_oy, L_iu, L_optu; 
    24         //! Setpoints of omega in timespans given by dt_prof 
    25         vec profileWw; 
    26         //! Setpoints of Mz in timespans given by dt_prof 
    27         vec profileMz; 
    28         //! time-step for profiles 
    29         double dt_prof; 
    30         //! Number of miliseconds per discrete time step 
    31         int Dt; 
    32         //! options for logging, - log predictions of 'true' voltage 
    33         bool opt_modu; 
    34         //! options for logging, -  
     23    //! indeces of logged variables 
     24    int L_x, L_ou, L_oy, L_iu, L_optu; 
     25    //! Setpoints of omega in timespans given by dt_prof 
     26    vec profileWw; 
     27    //! Setpoints of Mz in timespans given by dt_prof 
     28    vec profileMz; 
     29    //! time-step for profiles 
     30    double dt_prof; 
     31    //! Number of miliseconds per discrete time step 
     32    int Dt; 
     33    //! options for logging, - log predictions of 'true' voltage 
     34    bool opt_modu; 
     35    //! options for logging, - 
    3536public: 
    36         //! Constructor with fixed sampling period 
    37         pmsmDS ()   {Dt=125; Drv=RV ( "{o_ua o_ub o_ia o_ib t_ua t_ub o_om o_th Mz }" );} 
    38         void set_parameters ( double Rs0, double Ls0, double Fmag0, double Bf0, double p0, double kp0, double J0, double Uc0, double DT0, double dt0 ) { 
    39                 pmsmsim_set_parameters ( Rs0, Ls0, Fmag0, Bf0, p0, kp0, J0, Uc0, DT0, dt0 ); 
    40         } 
    41         //! parse options: "modelu" => opt_modu=true; 
    42         void set_options ( string &opt ) { 
    43                 opt_modu = ( opt.find ( "modelu" ) !=string::npos ); 
    44         } 
    45         void getdata ( vec &dt ) {dt.set_subvector(0,vec ( KalmanObs,6 ));dt(6)=x[2];dt(7)=x[3];dt(8)=x[8];} 
    46         void write ( vec &ut ) {} 
    47  
    48         void step() { 
    49                 static int ind=0; 
    50                 static double dW; // increase of W 
    51                 static double Ww; // W 
    52                 static double Mz; // W 
    53                 if ( t>=dt_prof*ind ) { 
    54                         ind++; 
    55                         // check omega profile and set dW 
    56                         if ( ind<profileWw.length() ) { 
    57                                 //linear increase 
    58                                 if ( profileWw.length() ==1 ) { 
    59                                         Ww=profileWw ( 0 ); dW=0.0; 
    60                                 } 
    61                                 else { 
    62                                         dW = profileWw ( ind )-profileWw ( ind-1 ); 
    63                                         dW *=125e-6/dt_prof; 
    64                                 } 
    65                         } 
    66                         else { 
    67                                 dW = 0; 
    68                         } 
    69                         // Check Mz profile and set Mz 
    70                         if ( ind<profileMz.length() ) { 
    71                                 //sudden increase 
    72                                 Mz = profileMz(ind); 
    73                         } 
    74                         else { 
    75                                 Mz = 0; 
    76                         } 
    77                 } 
    78                 Ww += dW; 
    79                 //Simulate Dt seconds! 
    80                 for ( int i=0;i<Dt;i++ ) {      pmsmsim_step ( Ww , Mz);} 
     37    //! Constructor with fixed sampling period 
     38    pmsmDS () 
     39    { 
     40        Dt=125; 
     41        Drv=RV ( "{o_ua o_ub o_ia o_ib t_ua t_ub o_om o_th Mz }" ); 
     42    } 
     43    void set_parameters ( double Rs0, double Ls0, double Fmag0, double Bf0, double p0, double kp0, double J0, double Uc0, double DT0, double dt0 ) 
     44    { 
     45        pmsmsim_set_parameters ( Rs0, Ls0, Fmag0, Bf0, p0, kp0, J0, Uc0, DT0, dt0 ); 
     46    } 
     47    //! parse options: "modelu" => opt_modu=true; 
     48    void set_options ( string &opt ) 
     49    { 
     50        opt_modu = ( opt.find ( "modelu" ) !=string::npos ); 
     51    } 
     52    void getdata ( vec &dt ) 
     53    { 
     54        dt.set_subvector(0,vec ( KalmanObs,6 )); 
     55        dt(6)=x[2]; 
     56        dt(7)=x[3]; 
     57        dt(8)=x[8]; 
     58    } 
     59    void write ( vec &ut ) {} 
     60 
     61    void step() 
     62    { 
     63        static int ind=0; 
     64        static double dW; // increase of W 
     65        static double Ww; // W 
     66        static double Mz; // W 
     67        if ( t>=dt_prof*ind ) 
     68        { 
     69            ind++; 
     70            // check omega profile and set dW 
     71            if ( ind<profileWw.length() ) 
     72            { 
     73                //linear increase 
     74                if ( profileWw.length() ==1 ) 
     75                { 
     76                    Ww=profileWw ( 0 ); 
     77                    dW=0.0; 
     78                } 
     79                else 
     80                { 
     81                    dW = profileWw ( ind )-profileWw ( ind-1 ); 
     82                    dW *=125e-6/dt_prof; 
     83                } 
     84            } 
     85            else 
     86            { 
     87                dW = 0; 
     88            } 
     89            // Check Mz profile and set Mz 
     90            if ( ind<profileMz.length() ) 
     91            { 
     92                //sudden increase 
     93                Mz = profileMz(ind); 
     94            } 
     95            else 
     96            { 
     97                Mz = 0; 
     98            } 
     99        } 
     100        Ww += dW; 
     101        //Simulate Dt seconds! 
     102        for ( int i=0; i<Dt; i++ ) 
     103        { 
     104            pmsmsim_step ( Ww , Mz); 
     105        } 
    81106//              for ( int i=0;i<Dt;i++ ) {      pmsmsim_noreg_step ( Ww , Mz);} 
    82                  
    83                 //discretization 
    84                 double ustep=1.2; 
    85                 KalmanObs [ 0 ] = ustep*itpp::round( KalmanObs [ 0 ]/ ustep) ; 
    86                 KalmanObs [ 1 ] = ustep*itpp::round(KalmanObs [ 1 ]/ ustep); 
    87                 double istep=0.085; 
    88                 KalmanObs [ 2 ] = istep*itpp::round( KalmanObs [ 2 ]/ istep) ; 
    89                 KalmanObs [ 3 ] = istep*itpp::round(KalmanObs [ 3 ]/ istep); 
    90  
    91         }; 
    92  
    93         void log_add ( logger &L ) { 
    94                 L_x = L.add ( rx, "x" ); 
    95                 L_oy = L.add ( ry, "o" ); 
    96                 L_ou = L.add ( ru, "o" ); 
    97                 L_iu = L.add ( ru, "t" ); 
    98                 // log differences 
    99                 if ( opt_modu ) { 
    100                         L_optu = L.add ( ru, "model" ); 
    101                 } 
    102         } 
    103  
    104         void logit ( logger &L ) { 
    105                 L.logit ( L_x, vec ( x,4 )      ); 
    106                 L.logit ( L_oy, vec_2 ( KalmanObs[2],KalmanObs[3] ) ); 
    107                 L.logit ( L_ou, vec_2 ( KalmanObs[0],KalmanObs[1] ) ); 
    108                 L.logit ( L_iu, vec_2 ( KalmanObs[4],KalmanObs[5] ) ); 
    109                 if ( opt_modu ) { 
    110                         double sq3=sqrt ( 3.0 ); 
    111                         double ua,ub; 
    112                         double i1=x[0]; 
    113                         double i2=0.5* ( -i1+sq3*x[1] ); 
    114                         double i3=0.5* ( -i1-sq3*x[1] ); 
    115                         double u1=KalmanObs[0]; 
    116                         double u2=0.5* ( -u1+sq3*KalmanObs[1] ); 
    117                         double u3=0.5* ( -u1-sq3*KalmanObs[1] ); 
    118  
    119                         double du1=1.4* ( double ( i1>0.3 ) - double ( i1<-0.3 ) ) +0.2*i1; 
    120                         double du2=1.4* ( double ( i2>0.3 ) - double ( i2<-0.3 ) ) +0.2*i2; 
    121                         double du3=1.4* ( double ( i3>0.3 ) - double ( i3<-0.3 ) ) +0.2*i3; 
    122                         ua = ( 2.0* ( u1-du1 )- ( u2-du2 )- ( u3-du3 ) ) /3.0; 
    123                         ub = ( ( u2-du2 )- ( u3-du3 ) ) /sq3; 
    124                         L.logit ( L_optu , vec_2 ( ua,ub ) ); 
    125                 } 
    126                  
    127         } 
    128  
    129         void set_profile ( double dt, const vec &Ww, const vec &Mz ) {dt_prof=dt; profileWw=Ww; profileMz=Mz;} 
     107 
     108        //discretization 
     109        double ustep=1.2; 
     110        KalmanObs [ 0 ] = ustep*itpp::round( KalmanObs [ 0 ]/ ustep) ; 
     111        KalmanObs [ 1 ] = ustep*itpp::round(KalmanObs [ 1 ]/ ustep); 
     112        double istep=0.085; 
     113        KalmanObs [ 2 ] = istep*itpp::round( KalmanObs [ 2 ]/ istep) ; 
     114        KalmanObs [ 3 ] = istep*itpp::round(KalmanObs [ 3 ]/ istep); 
     115 
     116    }; 
     117 
     118    void log_add ( logger &L ) 
     119    { 
     120        L_x = L.add ( rx, "x" ); 
     121        L_oy = L.add ( ry, "o" ); 
     122        L_ou = L.add ( ru, "o" ); 
     123        L_iu = L.add ( ru, "t" ); 
     124        // log differences 
     125        if ( opt_modu ) 
     126        { 
     127            L_optu = L.add ( ru, "model" ); 
     128        } 
     129    } 
     130 
     131    void logit ( logger &L ) 
     132    { 
     133        L.logit ( L_x, vec ( x,4 )      ); 
     134        L.logit ( L_oy, vec_2 ( KalmanObs[2],KalmanObs[3] ) ); 
     135        L.logit ( L_ou, vec_2 ( KalmanObs[0],KalmanObs[1] ) ); 
     136        L.logit ( L_iu, vec_2 ( KalmanObs[4],KalmanObs[5] ) ); 
     137        if ( opt_modu ) 
     138        { 
     139            double sq3=sqrt ( 3.0 ); 
     140            double ua,ub; 
     141            double i1=x[0]; 
     142            double i2=0.5* ( -i1+sq3*x[1] ); 
     143            double i3=0.5* ( -i1-sq3*x[1] ); 
     144            double u1=KalmanObs[0]; 
     145            double u2=0.5* ( -u1+sq3*KalmanObs[1] ); 
     146            double u3=0.5* ( -u1-sq3*KalmanObs[1] ); 
     147 
     148            double du1=1.4* ( double ( i1>0.3 ) - double ( i1<-0.3 ) ) +0.2*i1; 
     149            double du2=1.4* ( double ( i2>0.3 ) - double ( i2<-0.3 ) ) +0.2*i2; 
     150            double du3=1.4* ( double ( i3>0.3 ) - double ( i3<-0.3 ) ) +0.2*i3; 
     151            ua = ( 2.0* ( u1-du1 )- ( u2-du2 )- ( u3-du3 ) ) /3.0; 
     152            ub = ( ( u2-du2 )- ( u3-du3 ) ) /sq3; 
     153            L.logit ( L_optu , vec_2 ( ua,ub ) ); 
     154        } 
     155 
     156    } 
     157 
     158    void set_profile ( double dt, const vec &Ww, const vec &Mz ) 
     159    { 
     160        dt_prof=dt; 
     161        profileWw=Ww; 
     162        profileMz=Mz; 
     163    } 
     164 
     165    void from_setting( const Setting &root ) 
     166    { 
     167        set_parameters ( root["params"]["Rs"], root["params"]["Ls"], root["params"]["Fmag"], \ 
     168                         root["params"]["Bf"], root["params"]["p"], root["params"]["kp"], \ 
     169                         root["params"]["J"], root["params"]["Uc"], root["params"]["DT"], 1.0e-6 ); 
     170 
     171        // Default values of profiles for omega and Mz 
     172        vec profW=vec("1.0"); 
     173        vec profM=vec("0.0"); 
     174        double tstep=1.0; 
     175        root.lookupValue( "tstep", tstep ); 
     176        UI::get( profW, root, "profileW" ); 
     177        UI::get( profM, root, "profileM" ); 
     178        set_profile (tstep , profW, profM); 
     179 
     180        string opts; 
     181        if ( root.lookupValue( "options", opts ) ) 
     182            set_options(opts); 
     183    } 
     184 
     185    // TODO dodelat void to_setting( Setting &root ) const; 
    130186}; 
    131187 
     188UIREGISTER ( pmsmDS ); 
     189 
     190 
    132191//! This class behaves like BM but it is evaluating EKF 
    133 class pmsmCRB : public EKFfull{ 
    134         protected: 
    135                 vec interr; 
    136                 vec old_true; 
    137                 vec secder; 
    138                 int L_CRB; 
    139                 int L_err; 
    140                 int L_sec; 
    141         public: 
    142         //! constructor 
    143         pmsmCRB():EKFfull(){old_true=zeros(6);} 
    144  
    145         void bayes(const vec &dt){ 
    146                 static vec umin(2); 
    147                 vec u(2);  
    148                 //assume we know state exactly: 
    149                 vec true_state=vec(x,4); // read from pmsm 
    150                 E.set_mu(true_state); 
    151                 mu=true_state; 
    152                          
    153                 //integration error 
    154                 old_true(4)=KalmanObs[4]; 
    155                 old_true(5)=KalmanObs[5];// add U 
    156                 u(0) = KalmanObs[0]; // use the required value for derivatives 
    157                 u(1) = KalmanObs[1]; 
    158                 interr = (true_state - pfxu->eval(old_true)); 
    159                  
    160                 //second derivative 
    161                 IMpmsm2o* pf = dynamic_cast<IMpmsm2o*>(pfxu); 
    162                 if (pf) {secder=pf->eval2o(u-umin);} 
    163                                  
    164                 umin =u; 
    165                 EKFfull::bayes(dt); 
    166                 old_true.set_subvector(0,true_state); 
    167         } 
    168          
    169         void log_add(logger &L, const string &name="" ){ 
    170                 L_CRB=L.add(rx,"crb"); 
    171                 L_err=L.add(rx,"err"); 
    172                 L_sec=L.add(rx,"d2"); 
    173         } 
    174         void logit(logger &L){ 
    175                 L.logit(L_err, interr); 
    176                 L.logit(L_CRB,diag(_R())); 
    177                 L.logit(L_sec,secder); 
    178         } 
     192class pmsmCRB : public EKFfull 
     193{ 
     194protected: 
     195    vec interr; 
     196    vec old_true; 
     197    vec secder; 
     198    int L_CRB; 
     199    int L_err; 
     200    int L_sec; 
     201public: 
     202    //! constructor 
     203    pmsmCRB():EKFfull() 
     204    { 
     205        old_true=zeros(6); 
     206    } 
     207 
     208    void bayes(const vec &dt) 
     209    { 
     210        static vec umin(2); 
     211        vec u(2); 
     212        //assume we know state exactly: 
     213        vec true_state=vec(x,4); // read from pmsm 
     214        E.set_mu(true_state); 
     215        mu=true_state; 
     216 
     217        //integration error 
     218        old_true(4)=KalmanObs[4]; 
     219        old_true(5)=KalmanObs[5];// add U 
     220        u(0) = KalmanObs[0]; // use the required value for derivatives 
     221        u(1) = KalmanObs[1]; 
     222        interr = (true_state - pfxu->eval(old_true)); 
     223 
     224        //second derivative 
     225        IMpmsm2o* pf = dynamic_cast<IMpmsm2o*>(pfxu); 
     226        if (pf) 
     227        { 
     228            secder=pf->eval2o(u-umin); 
     229        } 
     230 
     231        umin =u; 
     232        EKFfull::bayes(dt); 
     233        old_true.set_subvector(0,true_state); 
     234    } 
     235 
     236    void log_add(logger &L, const string &name="" ) 
     237    { 
     238        L_CRB=L.add(rx,"crb"); 
     239        L_err=L.add(rx,"err"); 
     240        L_sec=L.add(rx,"d2"); 
     241    } 
     242    void logit(logger &L) 
     243    { 
     244        L.logit(L_err, interr); 
     245        L.logit(L_CRB,diag(_R())); 
     246        L.logit(L_sec,secder); 
     247    } 
     248 
     249    void from_setting( const Setting &root ) 
     250    { 
     251        diffbifn* IM = UI::build<diffbifn>(root, "IM"); 
     252        diffbifn* OM = UI::build<diffbifn>(root, "OM"); 
     253 
     254        //parameters 
     255 
     256        //statistics 
     257        int dim=IM->dimension(); 
     258        vec mu0; 
     259        if (!UI::get( mu0, root, "mu0") ) 
     260            mu0=zeros(dim); 
     261        mat P0; 
     262        vec dP0; 
     263 
     264        if (UI::get(dP0,root, "dP0") ) 
     265            P0=diag(dP0); 
     266        else if (!UI::get(P0,root, "P0") ) 
     267            P0=eye(dim); 
     268 
     269        set_statistics(mu0,P0); 
     270 
     271        vec dQ; 
     272        UI::get( dQ, root, "dQ"); 
     273        vec dR; 
     274        UI::get( dR, root, "dR"); 
     275        set_parameters(IM, OM, diag(dQ) , diag(dR)); 
     276 
     277        //connect 
     278        RV* drv = UI::build<RV>(root, "drv"); 
     279        set_drv(*drv); 
     280        RV* rv = UI::build<RV>(root, "rv"); 
     281        set_rv(*rv); 
     282    } 
     283 
     284    // TODO dodelat void to_setting( Setting &root ) const; 
    179285}; 
    180286 
     287UIREGISTER ( pmsmCRB ); 
     288 
     289 
    181290//! This class behaves like BM but it is evaluating EKF 
    182 class pmsmCRBMz : public EKFfull{ 
    183         protected: 
    184                 int L_CRB; 
    185         public: 
    186         //! constructor 
    187                 pmsmCRBMz():EKFfull(){} 
    188  
    189                 void bayes(const vec &dt){ 
     291class pmsmCRBMz : public EKFfull 
     292{ 
     293protected: 
     294    int L_CRB; 
     295public: 
     296    //! constructor 
     297    pmsmCRBMz():EKFfull() {} 
     298 
     299    void bayes(const vec &dt) 
     300    { 
    190301//assume we know state exactly: 
    191                         vec true_state(5); 
    192                         true_state.set_subvector(0,vec(x,4)); // read from pmsm 
    193                         true_state(4)=x[8]; 
    194                          
    195                         E.set_mu(true_state); 
    196                         mu = true_state; 
    197                         //hack for ut 
    198                         EKFfull::bayes(dt); 
    199                 } 
    200          
    201                 void log_add(logger &L, const string &name="" ){ 
    202                         L_CRB=L.add(concat(rx,RV("Mz",1,0)),"crbz"); 
    203                 } 
    204                 void logit(logger &L){ 
    205                         L.logit(L_CRB,diag(_R())); 
    206                 } 
     302        vec true_state(5); 
     303        true_state.set_subvector(0,vec(x,4)); // read from pmsm 
     304        true_state(4)=x[8]; 
     305 
     306        E.set_mu(true_state); 
     307        mu = true_state; 
     308        //hack for ut 
     309        EKFfull::bayes(dt); 
     310    } 
     311 
     312    void log_add(logger &L, const string &name="" ) 
     313    { 
     314        L_CRB=L.add(concat(rx,RV("Mz",1,0)),"crbz"); 
     315    } 
     316    void logit(logger &L) 
     317    { 
     318        L.logit(L_CRB,diag(_R())); 
     319    } 
     320 
     321    void from_setting( const Setting &root ) 
     322    { 
     323        diffbifn* IM = UI::build<diffbifn>(root,"IM"); 
     324        diffbifn* OM = UI::build<diffbifn>(root,"OM"); 
     325 
     326        //statistics 
     327        int dim=IM->dimension(); 
     328        vec mu0; 
     329        vec dP0; 
     330        mat P0; 
     331        if (!UI::get(mu0, root, "mu0")) 
     332            mu0=zeros(dim); 
     333        if (!UI::get( P0, root, "P0" )) 
     334            if (UI::get(dP0, root, "dP0")) 
     335                P0=diag(dP0); 
     336            else 
     337                P0=eye(dim); 
     338 
     339        set_statistics(mu0,P0); 
     340 
     341        vec dQ; 
     342        UI::get(dQ, root, "dQ"); 
     343        vec dR; 
     344        UI::get(dR, root, "dR"); 
     345        set_parameters(IM, OM, diag(dQ), diag(dR)); 
     346 
     347        //connect 
     348        RV* drv = UI::build<RV>(root, "drv"); 
     349        set_drv(*drv); 
     350        RV* rv = UI::build<RV>(root, "rv"); 
     351        set_rv(*rv); 
     352    } 
     353 
     354    // TODO dodelat void to_setting( Setting &root ) const; 
    207355}; 
     356 
     357UIREGISTER ( pmsmCRBMz ); 
  • applications/pmsm/pmsm_estim.cpp

    r342 r357  
    77 */ 
    88 
    9 #include "pmsm_ui.h" 
    10 #include "stat/loggers_ui.h" 
    11 #include "estim/KF_ui.h" 
    12 #include "stat/libDS_ui.h" 
     9#include "user_info.h" 
     10#include "stat/loggers.h" 
    1311 
    1412using namespace bdm; 
     
    1715        if ( argc>1 ) {fname = argv[1]; } 
    1816        else { cout << "Missing configuration file.\n Usage: \n $> estimator config_file.cfg"<<endl; abort(); } 
    19         UIFile F ( fname ); 
     17        UI_File F ( fname ); 
    2018 
    21         logger* L; 
    22         DS * DS; 
     19        logger* L = UI::build <logger>( F, "logger" ); 
     20        DS * pDS = UI::build<DS> ( F, "system" ); 
    2321        Array<BM*> Es;                  // array of estimators 
     22        UI::get( Es, F, "estimator" ); 
     23        int nE = Es.length();   //number of estimators 
    2424        int Ndat;                               //number of data records 
    25         int nE;                                 //number of estimators 
    26  
    27         try { 
    28                 UIbuild ( F.lookup ( "logger" ),L ); 
    29                 UIbuild ( F.lookup ( "system" ),DS ); 
    30                 F.lookupValue ( "experiment.ndat",Ndat ); 
    31                 Setting& S=F.lookup ( "estimator" ); 
    32                 nE = S.getLength(); 
    33                 Es.set_size(nE); 
    34                 for(int i=0;i<nE;i++){           
    35                         UIbuild (S[i] ,Es(i) ); 
    36                 } 
    37         } 
    38         catch UICATCH; 
    39  
    40         DS->log_add ( *L ); 
     25        F.lookupValue ( "experiment.ndat",Ndat ); 
     26                 
     27        pDS->log_add ( *L ); 
    4128        string nic=""; 
    4229        for (int i=0; i<nE; i++){ 
     
    4532        L->init(); 
    4633 
    47         vec dt=zeros ( DS->_drv()._dsize() );   //data variable 
     34        vec dt=zeros ( pDS->_drv()._dsize() );   //data variable 
    4835        Array<datalink*> Dls(nE);  
    4936        for (int i=0; i<nE; i++){ 
    50                 Dls(i)=new datalink( Es(i)->_drv(),DS->_drv() ); //datalink between a datasource and estimator 
     37                Dls(i)=new datalink( Es(i)->_drv(),pDS->_drv() ); //datalink between a datasource and estimator 
    5138        } 
    5239         
     
    5441        for ( int tK=1;tK<Ndat;tK++ ) { 
    5542                // Data Source 
    56                 DS->step();                                                     // simulator step 
    57                 DS->getdata ( dt );                                     // read data 
    58                 DS->logit ( *L ); 
     43                pDS->step();                                                    // simulator step 
     44                pDS->getdata ( dt );                                    // read data 
     45                pDS->logit ( *L ); 
    5946                 
    6047                // Estimators 
     
    7158 
    7259        delete L; 
    73         delete DS; 
     60        delete pDS; 
    7461        for (int i=0; i<nE; i++){ 
    7562                delete Dls(i); 
  • bdm/CMakeLists.txt

    r345 r357  
    77 
    88# Normal BDM library 
    9 add_library (bdm STATIC itpp_ext.cpp itpp_ext.h osutils.cpp osutils.h ${BdmMath} ${BdmStat} ${BdmEstim} ${BdmUI}) 
     9add_library (bdm STATIC bdmroot.cpp bdmroot.h itpp_ext.cpp itpp_ext.h osutils.cpp osutils.h ${BdmMath} ${BdmStat} ${BdmEstim} ${BdmUI}) 
  • bdm/estim/arx.cpp

    r286 r357  
    11#include "arx.h" 
     2#include "..\user_info.h" 
    23 
    34namespace bdm { 
     
    194195} 
    195196 
    196 } 
     197void ARX::from_setting( const Setting &root )  
     198{        
     199        RV *yrv = UI::build<RV>(root,"y"); 
     200        RV *rrv = UI::build<RV>(root,"rgr"); 
     201        int ylen = yrv->_dsize(); 
     202        int rgrlen = rrv->_dsize(); 
     203         
     204        //init 
     205        mat V0; 
     206        if( root.exists("dV0") ) 
     207        { 
     208                vec dV0; 
     209                UI::get( dV0, root, "dV0" ); 
     210                V0=diag ( dV0 ); 
     211        } 
     212        else 
     213                V0=concat ( 1e-3*ones ( ylen ), 1e-5*ones ( rgrlen ) ); 
     214         
     215        double nu0; 
     216        if ( !root.lookupValue( "nu0", nu0 ) )  
     217                nu0 = rgrlen+ylen+2; 
     218 
     219        double frg; 
     220        if ( !root.lookupValue( "frg", frg ) )  
     221                frg = 1.0; 
     222 
     223        set_parameters(frg); 
     224        set_statistics(ylen,V0, nu0); 
     225        set_drv(concat(*yrv,*rrv)); 
     226         
     227        //name results (for logging) 
     228        set_rv(RV("{theta r }", vec_2(ylen*rgrlen, ylen*ylen))); 
     229         
     230        delete yrv;  
     231        delete rrv; 
     232} 
     233 
     234/*void ARX::to_setting( Setting &root ) const 
     235{        
     236        Transport::to_setting( root ); 
     237 
     238        Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
     239        kilometers_setting = kilometers; 
     240 
     241        UI::save( passengers, root, "passengers" ); 
     242}*/ 
     243 
     244 
     245} 
  • bdm/estim/arx.h

    r286 r357  
    116116        } 
    117117        //!@} 
     118 
     119        // TODO dokumentace - aktualizovat 
     120        /*! UI for ARX estimator 
     121 
     122        The ARX is constructed from a structure with fields: 
     123        \code 
     124        estimator = { 
     125                type = "ARX"; 
     126                y = {type="rv", ...}   // description of output variables 
     127                rgr = {type="rv", ...} // description of regressor variables 
     128                constant = true;       // boolean switch if the constant term is modelled or not 
     129 
     130                //optional fields 
     131                dV0 = [1e-3, 1e-5, 1e-5, 1e-5];  
     132                                                           // default: 1e-3 for y, 1e-5 for rgr 
     133                nu0 = 6;               // default: rgrlen + 2 
     134                frg = 1.0;             // forgetting, default frg=1.0 
     135        }; 
     136        \endcode 
     137 
     138        The estimator will assign names of the posterior in the form ["theta_i" and "r_i"] 
     139        */ 
     140        void from_setting( const Setting &root ); 
     141 
     142        // TODO dodelat void to_setting( Setting &root ) const; 
    118143}; 
     144 
     145UIREGISTER(ARX); 
    119146 
    120147} 
  • bdm/estim/libKF.cpp

    r348 r357  
    11 
    22#include "libKF.h" 
     3#include "..\user_info.h" 
    34 
    45namespace bdm{ 
     
    250251} 
    251252 
    252 } 
     253void EKFCh::from_setting( const Setting &root )  
     254{        
     255        diffbifn* IM = UI::build<diffbifn>(root, "IM"); 
     256        diffbifn* OM = UI::build<diffbifn>(root, "OM"); 
     257         
     258        //statistics 
     259        int dim=IM->dimension(); 
     260        vec mu0; 
     261        if(root.exists("mu0")) 
     262                UI::get( mu0, root, "mu0"); 
     263        else 
     264                mu0=zeros(dim); 
     265 
     266        mat P0; 
     267        if(root.exists("dP0")) 
     268        { 
     269                vec dP0; 
     270                UI::get( dP0, root, "dP0"); 
     271                P0=diag(dP0); 
     272        } 
     273        else if ( root.exists( "P0" ) ) 
     274                UI::get(P0, root, "P0"); 
     275        else 
     276                P0=eye(dim); 
     277         
     278        set_statistics(mu0,P0); 
     279         
     280        //parameters 
     281        vec dQ, dR; 
     282        UI::get( dQ, root, "dQ"); 
     283        UI::get( dR, root, "dR"); 
     284        set_parameters(IM, OM, diag(dQ), diag(dR)); 
     285 
     286        //connect 
     287        RV* drv = UI::build<RV>(root, "drv"); 
     288        set_drv(*drv); 
     289        RV* rv = UI::build<RV>(root, "rv"); 
     290        set_rv(*rv); 
     291         
     292        string options; 
     293        if(root.lookupValue( "options", options )) 
     294                set_options(options);    
     295} 
     296 
     297/*void EKFCh::to_setting( Setting &root ) const 
     298{        
     299        Transport::to_setting( root ); 
     300 
     301        Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
     302        kilometers_setting = kilometers; 
     303 
     304        UI::save( passengers, root, "passengers" ); 
     305}*/ 
     306 
     307void MultiModel::from_setting( const Setting &root )  
     308{        
     309        Array<EKFCh*> A; 
     310        UI::get( A, root, "models"); 
     311         
     312        set_parameters(A); 
     313        set_drv(A(0)->_drv()); 
     314        //set_rv(A(0)->_rv()); 
     315 
     316        string options; 
     317        if(root.lookupValue( "options", options )) 
     318                set_options(options);    
     319} 
     320 
     321/*void MultiModel::to_setting( Setting &root ) const 
     322{        
     323        Transport::to_setting( root ); 
     324 
     325        Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
     326        kilometers_setting = kilometers; 
     327 
     328        UI::save( passengers, root, "passengers" ); 
     329}*/ 
     330 
     331 
     332} 
  • bdm/estim/libKF.h

    r338 r357  
    258258                        //! Here dt = [yt;ut] of appropriate dimensions 
    259259                        void bayes ( const vec &dt ); 
    260         }; 
     260 
     261                        void from_setting( const Setting &root ); 
     262 
     263                        // TODO dodelat void to_setting( Setting &root ) const; 
     264 
     265        }; 
     266 
     267        UIREGISTER(EKFCh); 
     268 
    261269 
    262270        /*! 
     
    447455                                //all posterior densities are equal => return the first one 
    448456                        const enorm<chmat>& posterior() const {return est;} 
    449         }; 
     457 
     458                        void from_setting( const Setting &root ); 
     459 
     460                        // TODO dodelat void to_setting( Setting &root ) const; 
     461 
     462        }; 
     463 
     464        UIREGISTER(MultiModel); 
     465 
    450466 
    451467 
  • bdm/stat/libBM.cpp

    r280 r357  
    11 
    22#include "libBM.h" 
    3 #include "../itpp_ext.h" 
    43 
    54//! Space of basic BDM structures 
     
    213212} 
    214213 
     214void RV::from_setting( const Setting &root )  
     215{        
     216        Array<string> A; 
     217        if( root.exists("names")) 
     218                UI::get( A, root, "names" ); 
     219        else 
     220                A.set_length(0); 
     221         
     222        ivec szs; 
     223        if( root.exists("sizes")) 
     224                UI::get(szs,root,"sizes"); 
     225        else 
     226                szs = ones_i(A.length()); 
     227         
     228        ivec tms; 
     229        if( root.exists( "times") ) 
     230                UI::get(tms,root,"times"); 
     231        else 
     232                tms = zeros_i(A.length()); 
     233         
     234        // TODO tady se bude plnit primo do jeho promennych, a pak se zavola validacnni metoda, takze cele prepsat, ano? 
     235        init( A, szs, tms ); 
     236} 
     237 
     238/*void RV::to_setting( Setting &root ) const 
     239{        
     240        Transport::to_setting( root ); 
     241 
     242        Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
     243        kilometers_setting = kilometers; 
     244 
     245        UI::save( passengers, root, "passengers" ); 
     246}*/ 
     247 
     248 
     249 
    215250RV concat ( const RV &rv1, const RV &rv2 ) { 
    216251        RV pom = rv1; 
  • bdm/stat/libBM.h

    r351 r357  
    1717 
    1818#include "../itpp_ext.h" 
    19 #include "../libconfig/libconfig.h++" 
     19#include "../bdmroot.h" 
     20#include "../user_info.h" 
    2021 
    2122 
    2223using namespace libconfig; 
    23  
    2424using namespace itpp; 
    2525using namespace std; 
    2626 
    2727namespace bdm { 
    28  
    29 //! Root class of BDM objects 
    30  
    31 class bdmroot { 
    32 public: 
    33         //! make sure this is a virtual object 
    34         virtual ~bdmroot()  
    35         { 
    36         } 
    37  
    38         //! This method returns a basic info about the current instance 
    39         virtual string ToString() 
    40         { 
    41                 return ""; 
    42         } 
    43  
    44         //! This method arrange instance properties according the data stored in the Setting structure 
    45         virtual void from_setting( const Setting &root ) 
    46         { 
    47         } 
    48  
    49         //! This method save all the instance properties into the Setting structure  
    50         virtual void to_setting( Setting &root ) const 
    51         {        
    52         } 
    53 }; 
    5428 
    5529typedef std::map<string, int> RVmap; 
     
    5731extern Array<string> RV_NAMES; 
    5832 
    59 //! Structure of RV (used internally), i.e. expanded RVs 
     33//! Structure of RV (used internally), i.e. expanded RVs - TODO tak proc je ve verejnem prostoru jmen? upravit 
    6034class str { 
    6135public: 
     
    189163        //!@{ 
    190164 
    191         //! generate \c str from rv, by expanding sizes 
     165        //! generate \c str from rv, by expanding sizes TODO to_string..  
    192166        str tostr() const; 
    193167        //! when this rv is a part of bigger rv, this function returns indeces of self in the data vector of the bigger crv. 
     
    201175        //!@} 
    202176 
    203 }; 
    204  
     177        // TODO aktualizovat dle soucasneho UI 
     178        /*! \brief UI for class RV (description of data vectors) 
     179 
     180        \code 
     181        rv = { 
     182                type = "rv"; //identifier of the description 
     183                // UNIQUE IDENTIFIER same names = same variable 
     184                names = ["a", "b", "c", ...];   // which will be used e.g. in loggers  
     185 
     186                //optional arguments 
     187                sizes = [1, 2, 3, ...];         // (optional) default = ones() 
     188                times = [-1, -2, 0, ...];       // time shifts with respect to current time (optional) default = zeros() 
     189        } 
     190        \endcode 
     191        */ 
     192        void from_setting( const Setting &root ); 
     193 
     194        // TODO dodelat void to_setting( Setting &root ) const; 
     195}; 
     196 
     197UIREGISTER(RV); 
    205198 
    206199//! Concat two random variables 
  • bdm/stat/libDS.cpp

    r313 r357  
    11 
    22#include "libDS.h" 
     3#include "..\user_info.h" 
     4 
    35using namespace bdm; 
    46 
     
    5355} 
    5456 
     57void ArxDS::from_setting( const Setting &root )  
     58{        
     59        RV *yrv = UI::build<RV>( root, "y" ); 
     60        RV *urv = UI::build<RV>( root, "u" ); 
     61        RV *rrv = UI::build<RV>( root, "rgr" );  
     62                                 
     63        mat Th; 
     64        UI::get( Th, root, "theta" ); 
     65 
     66        vec mu0; 
     67        if( root.exists( "offset" )) 
     68                UI::get( mu0, root, "offset" ); 
     69        else 
     70                mu0= zeros( yrv->_dsize() ); 
     71 
     72        mat sqR; 
     73        UI::get( sqR, root, "r" ); 
     74        set_parameters(Th,mu0,sqR); 
     75        set_drv(*yrv,*urv,*rrv); 
     76 
     77        if(root.exists("opt")) 
     78                set_options(root["opt"]); 
     79} 
     80 
     81/*void ArxDS::to_setting( Setting &root ) const 
     82{        
     83        Transport::to_setting( root ); 
     84 
     85        Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
     86        kilometers_setting = kilometers; 
     87 
     88        UI::save( passengers, root, "passengers" ); 
     89}*/ 
     90 
     91 
    5592CsvFileDS::CsvFileDS ( const string& fname, const string& orientation ) :FileDS() { 
    5693        time = 0; 
     
    87124} 
    88125 
     126void ITppFileDS::from_setting( const Setting &root )  
     127{        
     128        RV* rvtmp = UI::build<RV>(root, "rv" ); 
     129 
     130        it_file it ( root["filename"] ); 
     131        it << Name ( root["varname"] );  
     132        it >> Data; 
     133        time = 0; 
     134        //rowid and delays are ignored 
     135 
     136        set_drv(*rvtmp,RV()); 
     137} 
     138 
     139/*void ITppFileDS::to_setting( Setting &root ) const 
     140{        
     141        Transport::to_setting( root ); 
     142 
     143        Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
     144        kilometers_setting = kilometers; 
     145 
     146        UI::save( passengers, root, "passengers" ); 
     147}*/ 
     148 
     149void stateDS::from_setting( const Setting &root )  
     150{        
     151        IM = UI::build<mpdf>(root, "IM"); 
     152        OM = UI::build<mpdf>(root, "OM"); 
     153 
     154        dt.set_length( OM->dimension() ); 
     155        xt.set_length( IM->dimension() ); 
     156        ut.set_length(0); 
     157         
     158        RV* rvtmp = UI::build<RV>(root["IM"], "rvu");                    
     159        //set_drv(rvtmp); 
     160} 
     161 
     162/*void stateDS::to_setting( Setting &root ) const 
     163{        
     164        Transport::to_setting( root ); 
     165 
     166        Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
     167        kilometers_setting = kilometers; 
     168 
     169        UI::save( passengers, root, "passengers" ); 
     170}*/ 
     171 
     172 
  • bdm/stat/libDS.h

    r342 r357  
    9090                //rowid and delays are ignored 
    9191        }; 
    92 }; 
     92 
     93        ITppFileDS () :FileDS() { 
     94        }; 
     95 
     96        void from_setting( const Setting &root ); 
     97 
     98        // TODO dodelat void to_setting( Setting &root ) const; 
     99 
     100}; 
     101 
     102UIREGISTER(ITppFileDS); 
    93103 
    94104/*! 
     
    200210        } 
    201211 
    202 }; 
     212        // TODO dokumentace - aktualizovat 
     213        /*! UI for ArxDS using factorized description! 
     214 
     215        The ArxDS is constructed from a structure with fields: 
     216        \code 
     217        system = { 
     218                type = "ArxDS"; 
     219                // description of y variables 
     220                y = {type="rv"; names=["y", "u"];}; 
     221                // description of u variable 
     222                u = {type="rv"; names=[];} 
     223                // description of regressor 
     224                rgr = {type="rv"; 
     225                        names = ["y","y","y","u"]; 
     226                        times = [-1, -2, -3, -1]; 
     227                } 
     228 
     229                // theta 
     230                theta = [0.8, -0.3, 0.4, 1.0, 
     231                                 0.0, 0.0, 0.0, 0.0]; 
     232                // offset (optional) 
     233                offset = [0.0, 0.0]; 
     234                //variance 
     235                r = [0.1, 0.0, 
     236                         0.0, 1.0]; 
     237                //options: L_theta = log value of theta, 
     238                opt = "L_theta"; 
     239        }; 
     240        \endcode 
     241 
     242        Result is ARX data source offering with full history as Drv. 
     243        */ 
     244        void from_setting( const Setting &root ); 
     245 
     246        // TODO dodelat void to_setting( Setting &root ) const; 
     247}; 
     248 
     249UIREGISTER( ArxDS ); 
    203250 
    204251class stateDS : public DS { 
     
    222269        stateDS ( mpdf* IM0, mpdf* OM0, int usize ) :DS ( ),IM ( IM0 ),OM ( OM0 ), 
    223270                        dt ( OM0->dimension() ), xt ( IM0->dimension() ), ut ( usize ) {} 
     271 
     272        stateDS(){} 
     273 
    224274        ~stateDS() {delete IM; delete OM;} 
    225275        virtual void step() { 
     
    237287        } 
    238288 
    239 }; 
     289        /*! UI for stateDS  
     290 
     291        The DS is constructed from a structure with fields: 
     292        \code 
     293        system = { 
     294                type = "stateDS"; 
     295                //Internal model 
     296                IM = { type = "mpdf"; //<-- valid offspring! e.g. "mlnorm" 
     297                        rv = { //description of x_t  
     298                                names=["name1",...]; 
     299                                sizes=[2,1]; // optional default=[1,1...]; 
     300                                times=[0,0]; // optional default=[0,0...]; 
     301                                } 
     302                        rvu= { //description of  u_t  
     303                                //optional default=empty 
     304                                }        
     305 
     306                        // remaining fields depending on the chosen type 
     307                        }; 
     308                //Observation model 
     309                OM = { type = "mpdf-offspring"; 
     310                        rv = {}; //description of d_t  
     311                        rvu = {type="internal", path="system.IM.rvu"}; //description of u_t  
     312                 
     313                        //remaining fields 
     314                } 
     315        }; 
     316        \endcode 
     317        */ 
     318        void from_setting( const Setting &root ); 
     319 
     320        // TODO dodelat void to_setting( Setting &root ) const; 
     321 
     322}; 
     323 
     324UIREGISTER(stateDS); 
    240325 
    241326}; //namespace 
  • bdm/stat/libEF.cpp

    r330 r357  
     1#include <math.h> 
    12 
    23#include <itpp/base/bessel.h> 
    34#include "libEF.h" 
    4 #include <math.h> 
     5#include "..\user_info.h" 
    56 
    67namespace bdm{ 
     
    319320} 
    320321 
     322void migamma_ref::from_setting( const Setting &root )  
     323{                                
     324        vec ref; 
     325        UI::get( ref, root, "ref" ); 
     326        set_parameters(root["k"],ref,root["l"]); 
     327} 
     328 
     329/*void migamma_ref::to_setting( Setting &root ) const 
     330{        
     331        Transport::to_setting( root ); 
     332 
     333        Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
     334        kilometers_setting = kilometers; 
     335 
     336        UI::save( passengers, root, "passengers" ); 
     337}*/ 
     338 
     339 
     340void mlognorm::from_setting( const Setting &root )  
     341{        
     342        vec mu0; 
     343        UI::get( mu0, root, "mu0"); 
     344        set_parameters(mu0.length(),root["k"]); 
     345        condition(mu0); 
     346} 
     347 
     348/*void mlognorm::to_setting( Setting &root ) const 
     349{        
     350        Transport::to_setting( root ); 
     351 
     352        Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
     353        kilometers_setting = kilometers; 
     354 
     355        UI::save( passengers, root, "passengers" ); 
     356}*/ 
     357 
     358 
    321359}; 
  • bdm/stat/libEF.h

    r330 r357  
    1717#include "libBM.h" 
    1818#include "../math/chmat.h" 
    19 //#include <std> 
     19#include "../user_info.h" 
    2020 
    2121namespace bdm 
     
    515515                        void set_parameters ( fnc* g0, const sq_T &R0 ) {g=g0; epdf.set_parameters ( zeros ( g->dimension() ), R0 );} 
    516516                        void condition ( const vec &cond ) {mu=g->eval ( cond );}; 
    517         }; 
     517 
     518 
     519                        /*! UI for mgnorm 
     520 
     521                        The mgnorm is constructed from a structure with fields: 
     522                        \code 
     523                        system = { 
     524                                type = "mgnorm"; 
     525                                // function for mean value evolution 
     526                                g = {type="fnc"; ... } 
     527 
     528                                // variance 
     529                                R = [1, 0, 
     530                                         0, 1]; 
     531                                // --OR -- 
     532                                dR = [1, 1]; 
     533 
     534                                // == OPTIONAL == 
     535 
     536                                // description of y variables 
     537                                y = {type="rv"; names=["y", "u"];}; 
     538                                // description of u variable 
     539                                u = {type="rv"; names=[];} 
     540                        }; 
     541                        \endcode 
     542 
     543                        Result if 
     544                        */ 
     545 
     546                        void from_setting( const Setting &root )  
     547                        {        
     548                                fnc* g = UI::build<fnc>( root, "g" ); 
     549 
     550                                mat R; 
     551                                if ( root.exists( "dR" ) ) 
     552                                { 
     553                                        vec dR; 
     554                                        UI::get( dR, root, "dR" ); 
     555                                        R=diag(dR); 
     556                                } 
     557                                else  
     558                                        UI::get( R, root, "R");                                  
     559                 
     560                                set_parameters(g,R); 
     561                        } 
     562 
     563                        /*void mgnorm::to_setting( Setting &root ) const 
     564                        {        
     565                                Transport::to_setting( root ); 
     566 
     567                                Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
     568                                kilometers_setting = kilometers; 
     569 
     570                                UI::save( passengers, root, "passengers" ); 
     571                        }*/ 
     572 
     573        }; 
     574 
     575        UIREGISTER(mgnorm<chmat>); 
     576 
    518577 
    519578        /*! (Approximate) Student t density with linear function of mean value 
     
    630689        }; 
    631690 
     691 
    632692        /*! 
    633693        \brief  Gamma random walk around a fixed point 
     
    699759                                migamma::condition ( mean ); 
    700760                        }; 
    701         }; 
     761 
     762                        /*! UI for migamma_ref 
     763 
     764                        The migamma_ref is constructed from a structure with fields: 
     765                        \code 
     766                        system = { 
     767                                type = "migamma_ref"; 
     768                                ref = [1e-5; 1e-5; 1e-2 1e-3];            // reference vector 
     769                                l = 0.999;                                // constant l 
     770                                k = 0.1;                                  // constant k 
     771                                 
     772                                // == OPTIONAL == 
     773                                // description of y variables 
     774                                y = {type="rv"; names=["y", "u"];}; 
     775                                // description of u variable 
     776                                u = {type="rv"; names=[];} 
     777                        }; 
     778                        \endcode 
     779 
     780                        Result if 
     781                         */ 
     782                        void from_setting( const Setting &root ); 
     783 
     784                        // TODO dodelat void to_setting( Setting &root ) const; 
     785        }; 
     786 
     787 
     788        UIREGISTER(migamma_ref); 
    702789 
    703790        /*! Log-Normal probability density 
     
    753840                                mu=log ( val )-sig2;//elem_mult ( refl,pow ( val,l ) ); 
    754841                        }; 
    755         }; 
     842 
     843                        /*! UI for mlognorm 
     844 
     845                        The mlognorm is constructed from a structure with fields: 
     846                        \code 
     847                        system = { 
     848                                type = "mlognorm"; 
     849                                k = 0.1;                                  // constant k 
     850                                mu0 = [1., 1.]; 
     851                                 
     852                                // == OPTIONAL == 
     853                                // description of y variables 
     854                                y = {type="rv"; names=["y", "u"];}; 
     855                                // description of u variable 
     856                                u = {type="rv"; names=[];} 
     857                        }; 
     858                        \endcode 
     859 
     860                         */ 
     861                        void from_setting( const Setting &root ); 
     862 
     863                        // TODO dodelat void to_setting( Setting &root ) const; 
     864 
     865        }; 
     866         
     867        UIREGISTER(mlognorm); 
    756868 
    757869        /*! inverse Wishart density defined on Choleski decomposition 
  • bdm/stat/loggers.cpp

    r347 r357  
    2626        } 
    2727} 
     28 
     29void memlog::from_setting( const Setting &root )  
     30{        
     31        // TODO tady se natvrdo ocekava existence stringu, nejsou zadne defaulty.. je to tak OK? 
     32        string itfilename = (string)root["filename"]; 
     33        maxlen = root["maxlen"]; 
     34} 
     35 
     36/*void memlog::to_setting( Setting &root ) const 
     37{        
     38        Transport::to_setting( root ); 
     39 
     40        Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
     41        kilometers_setting = kilometers; 
     42 
     43        UI::save( passengers, root, "passengers" ); 
     44}*/ 
    2845 
    2946void dirfilelog::init() { 
     
    6279                                        ii++; 
    6380                                } 
    64                         } else { 
    65                         ii++;} 
     81                        }  
     82                        else { 
     83                                ii++;} 
    6684                } 
    6785        } 
     
    140158} 
    141159 
     160 
     161void dirfilelog::from_setting( const Setting &root )  
     162{        
     163        // TODO tady se natvrdo ocekava existence stringu, nejsou zadne defaulty.. je to tak OK? 
     164        dirname = (string)root["dirname"]; 
     165        maxlen = root["maxlen"]; 
     166        scalarnames.set_length(0); 
    142167} 
     168 
     169/*void dirfilelog::to_setting( Setting &root ) const 
     170{        
     171        Transport::to_setting( root ); 
     172 
     173        Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
     174        kilometers_setting = kilometers; 
     175 
     176        UI::save( passengers, root, "passengers" ); 
     177}*/ 
     178 
     179 
     180 
     181} 
  • bdm/stat/loggers.h

    r347 r357  
    1515 
    1616#include "libBM.h" 
     17#include "..\user_info.h" 
    1718 
    1819namespace bdm{ 
     
    3839public: 
    3940        //!Default constructor 
    40         memlog ( int maxlen0, string itf="" ) : logger(),maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ),itfilename(itf) {} 
     41        memlog ( int maxlen0, string itf="" ) : maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ),itfilename(itf) {} 
     42 
     43        memlog(): ind ( 0 ),vectors ( 0 ) {} 
     44 
    4145        //! Initialize storage 
    4246        void init() { 
     
    6064        void finalize() {if (itfilename.length()>0) itsave(itfilename.c_str());}; 
    6165 
     66 
     67        /*! \brief UI for memlog  
     68 
     69        TODO dat tam kam patri, a to celej blok 
     70 
     71        \code 
     72        logger = { 
     73                type = "itpplog"; 
     74                filename = "file_name.it"; // resulting filename with results in it format 
     75                maxlen = 100;          // size of memory buffer 
     76        } 
     77        \endcode 
     78         */ 
     79        void from_setting( const Setting &root ); 
     80 
     81        // TODO dodelat void to_setting( Setting &root ) const; 
    6282}; 
     83 
     84UIREGISTER(memlog); 
    6385 
    6486/*! 
     
    6991* This format is used to store scalars, hence multivariate RVs must be separated. 
    7092*/ 
    71  
    7293class dirfilelog : public memlog { 
    7394 
     
    81102        @param dirname0 name of the directory in which to store the results 
    82103        @param maxlen0 length of the memory buffers, when full the buffers will be dumped to HDD and returned to the beginning. */ 
    83         dirfilelog ( std::string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {} 
     104        dirfilelog ( string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {} 
     105 
     106        dirfilelog() {} 
     107 
    84108        //! Initialize storage 
    85109        void init(); 
     
    90114        */ 
    91115        void write_buffers ( int Len ); 
     116 
     117        // TODO dokumentace - aktualizovat 
     118        /*! \brief UI for dirfilelog (Kst file format)  
     119        \code 
     120        logger = { 
     121                type = "dirfilelog"; 
     122                dirmane = "directory_for_files"; // resulting files will be stored there 
     123                maxlen = 100;                    // size of memory buffer, when full results are written to disk 
     124        } 
     125        \endcode 
     126        */ 
     127        void from_setting( const Setting &root ); 
     128 
     129        // TODO dodelat void to_setting( Setting &root ) const; 
    92130}; 
     131 
     132UIREGISTER(dirfilelog); 
    93133 
    94134}; 
  • bdm/user_info.cpp

    r351 r357  
    1313#include "user_info.h" 
    1414 
    15 namespace bdm { 
     15namespace bdm 
     16{ 
    1617 
    1718 
     
    1920 
    2021 
    21 UI_File::UI_File ( const string &file_name ) : file_name( file_name ) 
    22 { 
    23         setAutoConvert( true ); 
     22UI_File::UI_File () 
     23{ 
     24    setAutoConvert( true ); 
    2425} 
    2526 
    2627//! loads root element from a file 
    27 void UI_File::load()  
    28 { 
    29         try 
    30         { 
    31                 readFile( file_name.c_str()  ); 
    32         } 
    33         catch ( FileIOException f )  
    34         { 
    35                 it_error ( "UI error: file " + file_name + " not found." ); 
    36         } 
    37         catch ( ParseException& P )  
    38         { 
    39                 stringstream msg; 
    40                 msg << "UI error: parsing ui_error """ << P.getError() << """ in file " << file_name << " on line " <<  P.getLine() << "."; 
    41                 it_error ( msg.str() ); 
    42         }        
     28UI_File::UI_File ( const string &file_name ) 
     29{ 
     30    setAutoConvert( true ); 
     31    try 
     32    { 
     33        readFile( file_name.c_str()  ); 
     34    } 
     35    catch ( FileIOException f ) 
     36    { 
     37        it_error ( "UI error: file " + file_name + " not found." ); 
     38    } 
     39    catch ( ParseException& P ) 
     40    { 
     41        stringstream msg; 
     42        msg << "UI error: parsing error """ << P.getError() << """ in file " << file_name << " on line " <<  P.getLine() << "."; 
     43        it_error ( msg.str() ); 
     44    } 
    4345} 
    4446 
    4547 
    4648//! save UserInfo to the file (typically with an XML extension) 
    47 void UI_File::save() 
    48 { 
    49         try 
    50         { 
    51                 writeFile ( file_name.c_str()  ); 
    52         } 
    53         catch ( FileIOException f )  
    54         { 
    55                 it_error( "UI error: file " + file_name + " is inacessible." ); 
    56         }                
    57 }        
     49void UI_File::save(  const string &file_name ) 
     50{ 
     51    try 
     52    { 
     53        writeFile ( file_name.c_str()  ); 
     54    } 
     55    catch ( FileIOException f ) 
     56    { 
     57        it_error( "UI error: file " + file_name + " is inacessible." ); 
     58    } 
     59} 
    5860 
    5961UI_File::operator Setting&() 
    6062{ 
    61         return getRoot(); 
     63    return getRoot(); 
    6264} 
    6365///////////////////////// INTERNAL MAPPED_UI ///////////////////////////////////////////// 
     
    6567UI::Mapped_UI::String_To_UI_Map& UI::Mapped_UI::mapped_strings() 
    6668{ 
    67         static String_To_UI_Map var; 
    68         return var; 
     69    static String_To_UI_Map var; 
     70    return var; 
    6971} 
    7072 
    7173UI::Mapped_UI::Type_Info_To_String_Map& UI::Mapped_UI::mapped_type_infos() 
    7274{ 
    73         static Type_Info_To_String_Map var; 
    74         return var; 
     75    static Type_Info_To_String_Map var; 
     76    return var; 
    7577} 
    7678 
    7779void UI::Mapped_UI::add_class( const string &class_name, const type_info * const class_type_info, const UI* const ui ) 
    7880{ 
    79         pair< const string, const UI* const > new_pair = make_pair( class_name, ui ); 
    80         mapped_strings().insert( new_pair ); 
    81         mapped_type_infos().insert( make_pair( class_type_info, new_pair.first ) ); 
     81    pair< const string, const UI* const > new_pair = make_pair( class_name, ui ); 
     82    mapped_strings().insert( new_pair ); 
     83    mapped_type_infos().insert( make_pair( class_type_info, new_pair.first ) ); 
    8284} 
    8385 
    8486const UI& UI::Mapped_UI::retrieve_ui( const string &class_name ) 
    8587{ 
    86         String_To_UI_Map::const_iterator iter = mapped_strings().find( class_name ); 
    87         if( iter == mapped_strings().end())  
    88                 it_error ( "UI error: class " + class_name + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); 
    89         return *iter->second; 
    90 }        
     88    String_To_UI_Map::const_iterator iter = mapped_strings().find( class_name ); 
     89    if ( iter == mapped_strings().end()) 
     90        it_error ( "UI error: class " + class_name + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); 
     91    return *iter->second; 
     92} 
    9193 
    9294const string& UI::Mapped_UI::retrieve_class_name( const type_info * const class_type_info ) 
    9395{ 
    94         Type_Info_To_String_Map::const_iterator iter = mapped_type_infos().find( class_type_info ); 
    95         if( iter == mapped_type_infos().end())  
    96                 it_error ( "UI error: class with RTTI name " + string(class_type_info->name()) + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); 
    97         return iter->second; 
    98 }        
     96    Type_Info_To_String_Map::const_iterator iter = mapped_type_infos().find( class_type_info ); 
     97    if ( iter == mapped_type_infos().end()) 
     98        it_error ( "UI error: class with RTTI name " + string(class_type_info->name()) + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); 
     99    return iter->second; 
     100} 
    99101 
    100102///////////////////////// INTERNAL LINK EXPANDER ///////////////////////////////////////////// 
     
    102104UI::Link_Expander::Link_Expander( const Setting &potential_link ) 
    103105{ 
    104         file = NULL; 
    105         result = &potential_link; 
    106  
    107         if( potential_link.getType() !=  Setting::TypeString ) 
    108                 return; 
    109  
    110         string link = (string) potential_link; 
    111         size_t aerobase = link.find('@'); 
    112         if( aerobase != string::npos ) 
    113         { 
    114                 string file_name = link.substr( aerobase + 1, link.length() ); 
    115                 file = new UI_File( file_name ); 
    116                 file->load(); 
    117                 result = &(Setting&)(*file); 
    118                 link = link.substr( 0, aerobase ); 
    119         } 
    120         else 
    121                 while ( !result->isRoot() )  
    122                         result = &result->getParent(); 
    123  
    124         if( !result->exists( link ) ) 
    125                 ui_error( "linked Setting was not found", potential_link ); 
    126  
    127         result = &(*result)[link]; 
     106    file = NULL; 
     107    result = &potential_link; 
     108 
     109    if ( potential_link.getType() !=  Setting::TypeString ) 
     110        return; 
     111 
     112    string link = (string) potential_link; 
     113    size_t aerobase = link.find('@'); 
     114    if ( aerobase != string::npos ) 
     115    { 
     116        string file_name = link.substr( aerobase + 1, link.length() ); 
     117        file = new UI_File( file_name ); 
     118        result = &(Setting&)(*file); 
     119        link = link.substr( 0, aerobase ); 
     120    } 
     121    else 
     122        while ( !result->isRoot() ) 
     123            result = &result->getParent(); 
     124 
     125    if ( !result->exists( link ) ) 
     126        ui_error( "linked Setting was not found", potential_link ); 
     127 
     128    result = &(*result)[link]; 
    128129} 
    129130 
    130131UI::Link_Expander::~Link_Expander() 
    131132{ 
    132         if( file ) delete file; 
     133    if ( file ) delete file; 
    133134} 
    134135 
    135136const Setting& UI::Link_Expander::root() const 
    136137{ 
    137         return *result; 
     138    return *result; 
    138139} 
    139140 
    140141///////////////////////// UI ///////////////////////////////////////////// 
    141142 
    142  
    143  
    144 //! This methods   - kvuli ukladani pole stringu, dat jen privatne? 
     143void UI::ui_error( string message, const Setting &element ) 
     144{ 
     145    stringstream error_message; 
     146    error_message << "UI error: " << message << "! Check path """ << element.getPath() << """, source line " << element.getSourceLine() << "."; 
     147    it_error ( error_message.str() ); 
     148} 
     149 
     150//! This methods - kvuli ukladani pole stringu, dat jen privatne? 
    145151void UI::save( const string &str, Setting &element ) 
    146152{ 
    147         Setting &root = element.add( Setting::TypeString ); 
    148         root = str; 
     153    Setting &root = element.add( Setting::TypeString ); 
     154    root = str; 
    149155} 
    150156 
    151157void UI::save( const mat &matrix, Setting &element, const string &name) 
    152158{ 
    153          
    154         Setting &root = (name == "") ? element.add( Setting::TypeList )                                                  
    155                                                                  : element.add( name, Setting::TypeList );               
    156  
    157         Setting &cols = root.add( Setting::TypeInt ); 
    158         cols = matrix.cols(); 
    159  
    160         Setting &rows = root.add( Setting::TypeInt ); 
    161         rows = matrix.rows(); 
    162  
    163         Setting &elements = root.add( Setting::TypeArray ); 
    164  
    165         // build matrix row-wise 
    166         for( int i=0; i<matrix.rows(); i++ )  
    167                 for( int j=0; j<matrix.cols(); j++) 
    168                 { 
    169                         Setting &new_field = elements.add(Setting::TypeFloat); 
    170                         new_field = matrix(i,j); 
    171                 } 
    172 } 
    173  
    174  
    175         //! This methods tries to save a double vec  
    176 void UI::save( const ivec &vec, Setting &element, const string &name) 
    177 { 
    178          
    179         Setting &root = (name == "") ? element.add( Setting::TypeArray )                                                         
    180                                                                  : element.add( name, Setting::TypeArray );              
    181         for( int i=0; i<vec.length(); i++ )  
    182         { 
    183                 Setting &new_field = root.add(Setting::TypeInt); 
    184                 new_field = vec(i); 
    185         } 
    186 } 
    187  
    188  
    189 //! This methods tries to build a new double matrix  
     159 
     160    Setting &root = (name == "") ? element.add( Setting::TypeList ) 
     161                    : element.add( name, Setting::TypeList ); 
     162 
     163    Setting &cols = root.add( Setting::TypeInt ); 
     164    cols = matrix.cols(); 
     165 
     166    Setting &rows = root.add( Setting::TypeInt ); 
     167    rows = matrix.rows(); 
     168 
     169    Setting &elements = root.add( Setting::TypeArray ); 
     170 
     171    // build matrix row-wise 
     172    for ( int i=0; i<matrix.rows(); i++ ) 
     173        for ( int j=0; j<matrix.cols(); j++) 
     174        { 
     175            Setting &new_field = elements.add(Setting::TypeFloat); 
     176            new_field = matrix(i,j); 
     177        } 
     178} 
     179 
     180 
     181//! This methods tries to save a integer vector 
     182void UI::save( const ivec &vector, Setting &element, const string &name) 
     183{ 
     184 
     185    Setting &root = (name == "") ? element.add( Setting::TypeArray ) 
     186                    : element.add( name, Setting::TypeArray ); 
     187    for ( int i=0; i<vector.length(); i++ ) 
     188    { 
     189        Setting &new_field = root.add(Setting::TypeInt); 
     190        new_field = vector(i); 
     191    } 
     192} 
     193 
     194 
     195//! This methods tries to save a double vector 
     196void UI::save( const vec &vector, Setting &element, const string &name) 
     197{ 
     198 
     199    Setting &root = (name == "") ? element.add( Setting::TypeArray ) 
     200                    : element.add( name, Setting::TypeArray ); 
     201    for ( int i=0; i<vector.length(); i++ ) 
     202    { 
     203                Setting &new_field = root.add(Setting::TypeFloat); 
     204        new_field = vector(i); 
     205    } 
     206} 
     207 
     208 
     209//! This methods tries to build a new double matrix 
    190210 
    191211void UI::from_setting( mat& matrix, const Setting &element ) 
    192212{ 
    193         const Link_Expander link_expander( element ); 
    194         const Setting &root = link_expander.root(); 
    195  
    196         if( root.isNumber() ) 
    197         { 
    198                 matrix.set_size( 1, 1 ); 
    199                 matrix(0,0) = root; 
    200                 return; 
    201         } 
    202  
    203         if( root.isList() ) 
    204         { 
    205                 if( root.getLength() != 3 ) 
    206                         ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 
    207  
    208                 Setting &cols_setting = root[0]; 
    209                 Setting &rows_setting = root[1]; 
    210                 Setting &elements = root[2]; 
    211  
    212                 ASSERT_UITYPE(cols_setting,TypeInt); 
    213                 ASSERT_UITYPE(rows_setting,TypeInt); 
    214                 ASSERT_UITYPE(elements,TypeArray); 
    215  
    216                 int cols = cols_setting; 
    217                 int rows = rows_setting; 
    218                                          
    219                 if( cols < 0 | rows < 0 ) 
    220                         ui_error( "the dimensions of a matrix has to be non-negative", root ); 
    221  
    222                 if( elements.getLength() != cols * rows ) 
    223                         ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
    224  
    225                 matrix.set_size( rows, cols ); 
    226  
    227                 if( cols == 0 || rows == 0 ) 
    228                         return; 
    229  
    230                 if( !elements[0].isNumber() ) 
    231                         ui_error( "matrix elements have to be numbers", elements[0] ); 
    232  
    233                 // build matrix row-wise 
    234                 int k = 0; 
    235                 for( int i=0;i<rows;i++ )  
    236                         for( int j=0; j<cols; j++) 
    237                                 matrix(i,j) = elements[k++]; 
    238                 return; 
    239         } 
    240  
    241         ui_error( "only numeric types or TypeList are supported as matrix values", root ); 
     213    const Link_Expander link_expander( element ); 
     214    const Setting &root = link_expander.root(); 
     215 
     216    if ( root.isNumber() ) 
     217    { 
     218        matrix.set_size( 1, 1 ); 
     219        matrix(0,0) = root; 
     220        return; 
     221    } 
     222 
     223    if ( root.isList() ) 
     224    { 
     225        if ( root.getLength() != 3 ) 
     226            ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 
     227 
     228        Setting &rows_setting = root[0]; 
     229        Setting &cols_setting = root[1]; 
     230        Setting &elements = root[2]; 
     231 
     232        ASSERT_UITYPE(cols_setting,TypeInt); 
     233        ASSERT_UITYPE(rows_setting,TypeInt); 
     234        ASSERT_UITYPE(elements,TypeArray); 
     235 
     236        int cols = cols_setting; 
     237        int rows = rows_setting; 
     238 
     239        if ( cols < 0 | rows < 0 ) 
     240            ui_error( "the dimensions of a matrix has to be non-negative", root ); 
     241 
     242        if ( elements.getLength() != cols * rows ) 
     243            ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
     244 
     245        matrix.set_size( rows, cols ); 
     246 
     247        if ( cols == 0 || rows == 0 ) 
     248            return; 
     249 
     250        if ( !elements[0].isNumber() ) 
     251            ui_error( "matrix elements have to be numbers", elements[0] ); 
     252 
     253        // build matrix row-wise 
     254        int k = 0; 
     255        for ( int i=0; i<rows; i++ ) 
     256            for ( int j=0; j<cols; j++) 
     257                matrix(i,j) = elements[k++]; 
     258        return; 
     259    } 
     260 
     261    ui_error( "only numeric types or TypeList are supported as matrix values", root ); 
    242262} 
    243263 
    244264//! This methods tries to build a new integer vector 
    245 void UI::from_setting( ivec &vec, const Setting &element ) 
    246 { 
    247         const Link_Expander link_expander( element ); 
    248         const Setting &root = link_expander.root(); 
    249  
    250         if( root.isNumber() ) 
    251         { 
    252                 ASSERT_UITYPE(root,TypeInt); 
    253                 vec.set_length( 1 ); 
    254                 vec(0) = root; 
    255                 return; 
    256         } 
    257  
    258         if( root.isList() ) 
    259         { 
    260                 if( root.getLength() != 3 ) 
    261                         ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 
    262  
    263                 Setting &cols_setting = root[0]; 
    264                 Setting &rows_setting = root[1]; 
    265                 Setting &elements = root[2]; 
    266  
    267                 ASSERT_UITYPE(cols_setting,TypeInt); 
    268                 ASSERT_UITYPE(rows_setting,TypeInt); 
    269                 ASSERT_UITYPE(elements,TypeArray); 
    270  
    271                 int cols = cols_setting; 
    272                 int rows = rows_setting; 
    273                  
    274                 if( cols < 0 | rows < 0) 
    275                         ui_error( "the dimensions of a matrix has to be non-negative", root ); 
    276  
    277                 if( elements.getLength() != cols * rows ) 
    278                         ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
    279  
    280                 if( cols != 1 & rows !=1) 
    281                         ui_error( "the vector length is invalid, it seems to be rather a matrix", elements ); 
    282                  
    283                 int len = rows * cols; 
    284                 vec.set_length ( len ); 
    285                 if( len == 0 ) return; 
    286  
    287                 ASSERT_UITYPE(elements[0],TypeInt); 
    288                 for( int i=0; i<len; i++ )  
    289                         vec(i) = elements[i]; 
    290                 return; 
    291         } 
    292  
    293         if( root.isArray() ) 
    294         {        
    295                 int len = root.getLength(); 
    296                 vec.set_length( len ); 
    297                 if( len == 0 ) return; 
    298  
    299                 ASSERT_UITYPE(root[0],TypeInt); 
    300                 for( int i=0; i < len; i++ )  
    301                         vec(i) = root[i]; 
    302                 return; 
    303         } 
    304  
    305         ui_error( "only numeric types, TypeArray or TypeList are supported as vector values", root ); 
     265void UI::from_setting( ivec &vector, const Setting &element ) 
     266{ 
     267    const Link_Expander link_expander( element ); 
     268    const Setting &root = link_expander.root(); 
     269 
     270    if ( root.isNumber() ) 
     271    { 
     272        ASSERT_UITYPE(root,TypeInt); 
     273        vector.set_length( 1 ); 
     274        vector(0) = root; 
     275        return; 
     276    } 
     277 
     278    if ( root.isList() ) 
     279    { 
     280        if ( root.getLength() != 3 ) 
     281            ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 
     282 
     283        Setting &cols_setting = root[0]; 
     284        Setting &rows_setting = root[1]; 
     285        Setting &elements = root[2]; 
     286 
     287        ASSERT_UITYPE(cols_setting,TypeInt); 
     288        ASSERT_UITYPE(rows_setting,TypeInt); 
     289        ASSERT_UITYPE(elements,TypeArray); 
     290 
     291        int cols = cols_setting; 
     292        int rows = rows_setting; 
     293 
     294        if ( cols < 0 | rows < 0) 
     295            ui_error( "the dimensions of a matrix has to be non-negative", root ); 
     296 
     297        if ( elements.getLength() != cols * rows ) 
     298            ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
     299 
     300        if ( cols != 1 & rows !=1) 
     301            ui_error( "the vector length is invalid, it seems to be rather a matrix", elements ); 
     302 
     303        int len = rows * cols; 
     304        vector.set_length ( len ); 
     305        if ( len == 0 ) return; 
     306 
     307        ASSERT_UITYPE(elements[0],TypeInt); 
     308        for ( int i=0; i<len; i++ ) 
     309            vector(i) = elements[i]; 
     310        return; 
     311    } 
     312 
     313    if ( root.isArray() ) 
     314    { 
     315        int len = root.getLength(); 
     316        vector.set_length( len ); 
     317        if ( len == 0 ) return; 
     318 
     319        ASSERT_UITYPE(root[0],TypeInt); 
     320        for ( int i=0; i < len; i++ ) 
     321            vector(i) = root[i]; 
     322        return; 
     323    } 
     324 
     325    ui_error( "only numeric types, TypeArray or TypeList are supported as vector values", root ); 
     326} 
     327 
     328//! This methods tries to build a new double vector 
     329void UI::from_setting( vec &vector, const Setting &element ) 
     330{ 
     331    const Link_Expander link_expander( element ); 
     332    const Setting &root = link_expander.root(); 
     333 
     334    if ( root.isNumber() ) 
     335    { 
     336        vector.set_length( 1 ); 
     337        vector(0) = root; 
     338        return; 
     339    } 
     340 
     341    if ( root.isList() ) 
     342    { 
     343        if ( root.getLength() != 3 ) 
     344            ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 
     345 
     346        Setting &cols_setting = root[0]; 
     347        Setting &rows_setting = root[1]; 
     348        Setting &elements = root[2]; 
     349 
     350        ASSERT_UITYPE(cols_setting,TypeInt); 
     351        ASSERT_UITYPE(rows_setting,TypeInt); 
     352        ASSERT_UITYPE(elements,TypeArray); 
     353 
     354        int cols = cols_setting; 
     355        int rows = rows_setting; 
     356 
     357        if ( cols < 0 | rows < 0) 
     358            ui_error( "the dimensions of a matrix has to be non-negative", root ); 
     359 
     360        if ( elements.getLength() != cols * rows ) 
     361            ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
     362 
     363        if ( cols != 1 & rows !=1) 
     364            ui_error( "the vector length is invalid, it seems to be rather a matrix", elements ); 
     365 
     366        int len = rows * cols; 
     367        vector.set_length ( len ); 
     368        if ( len == 0 ) return; 
     369 
     370        if ( !elements[0].isNumber()) 
     371            ui_error("a vector element has to be a number", elements[0]); 
     372 
     373        for ( int i=0; i<len; i++ ) 
     374            vector(i) = elements[i]; 
     375        return; 
     376    } 
     377 
     378    if ( root.isArray() ) 
     379    { 
     380        int len = root.getLength(); 
     381        vector.set_length( len ); 
     382        if ( len == 0 ) return; 
     383 
     384        if ( !root[0].isNumber()) 
     385            ui_error("a vector element has to be a number", root[0]); 
     386 
     387        for ( int i=0; i < len; i++ ) 
     388            vector(i) = root[i]; 
     389        return; 
     390    } 
     391 
     392    ui_error( "only numeric types, TypeArray or TypeList are supported as vector values", root ); 
    306393} 
    307394 
     
    309396void UI::from_setting( string &str, const Setting &element ) 
    310397{ 
    311         ASSERT_UITYPE(element,TypeString); 
    312         str = (string) element; 
     398    ASSERT_UITYPE(element,TypeString); 
     399    str = (string) element; 
    313400} 
    314401 
    315402 
    316403///////////////////////// UI FILE ///////////////////////////////////////////// 
    317         //! This methods tries to save an instance of type T (or some of its descendant types) 
    318         //! and build DOM tree accordingly. Then, it creates a new DOMNode named according class_name 
    319         //! and connecti it to the passed Setting as a new child node. 
    320 const Setting* UI::pointer_to_child_setting( const Setting &element, const int index ) 
    321 { 
    322         if( !element.isList()) 
    323                 return NULL; 
    324  
    325         if( element.getLength() <= index ) 
    326                 return NULL; 
    327  
    328         return &element[index]; 
    329 } 
    330  
    331 const Setting* UI::pointer_to_child_setting( const Setting &element, const string &name ) 
    332 { 
    333         if( !element.isGroup() ) 
    334                 return NULL; 
    335  
    336         if( !element.exists( name ) ) 
    337                 return NULL; 
    338  
    339         return &element[name]; 
    340 } 
    341  
    342 const Setting& UI::reference_to_child_setting( const Setting &element, const int index ) 
    343 { 
    344         if( !element.isList()) 
    345                 ui_error( "only TypeList elements could be indexed by integers", element ); 
    346  
    347         if( element.getLength() <= index ) 
    348                 ui_error( "there is not any child with index " + index, element ); 
    349  
    350         return element[index]; 
    351 } 
    352  
    353 const Setting& UI::reference_to_child_setting( const Setting &element, const string &name ) 
    354 { 
    355         ASSERT_UITYPE(element,TypeGroup); 
    356         if( !element.exists( name ) ) 
    357                 ui_error( "there is not any child named """ + name, element ); 
    358         return element[name]; 
    359 } 
    360  
    361  
    362 } 
    363  
     404//! This methods tries to save an instance of type T (or some of its descendant types) 
     405//! and build DOM tree accordingly. Then, it creates a new DOMNode named according class_name 
     406//! and connecti it to the passed Setting as a new child node. 
     407const Setting& UI::to_child_setting( const Setting &element, const int index ) 
     408{ 
     409    if ( !element.isList()) 
     410        ui_error( "only TypeList elements could be indexed by integers", element ); 
     411 
     412    if ( element.getLength() <= index ) 
     413        ui_error( "there is not any child with index " + index, element ); 
     414 
     415    return element[index]; 
     416} 
     417 
     418const Setting& UI::to_child_setting( const Setting &element, const string &name ) 
     419{ 
     420    ASSERT_UITYPE(element,TypeGroup); 
     421    if ( !element.exists( name ) ) 
     422        ui_error( "there is not any child named """ + name, element ); 
     423    return element[name]; 
     424} 
     425 
     426 
     427} 
     428 
  • bdm/user_info.h

    r351 r357  
    1 #ifndef UIBUILD 
    2 #define UIBUILD 
    3  
    4  
    5 #include <sstream> 
    6 #include <iostream> 
     1#ifndef USER_INFO_H 
     2#define USER_INFO_H 
     3 
    74#include <stdio.h> 
    85#include <string> 
    96#include <typeinfo> 
    107#include <map> 
    11 #include <utility> 
    12 #include <vector> 
    13 #include <iostream> 
    148 
    159#include "libconfig/libconfig.h++" 
    16  
    17 #include <itpp/itbase.h> 
    18  
    19 #include "stat/libBM.h" 
     10#include "bdmroot.h" 
     11#include "itpp/itbase.h" 
     12 
    2013 
    2114using std::string; 
     
    3528 
    3629public: 
    37         //! attach new RootElement instance to a file (typically with an XML extension) 
     30        //! create empty object prepared to store Settings 
     31        UI_File(); 
     32 
     33        //! creates object and fills it from a file 
    3834        UI_File( const string &file_name ); 
    3935 
    40         //! loads root element from a file 
    41         void load(); 
    42  
    43         //! save UserInfo to the file (typically with an XML extension) 
    44         void save(); 
     36        //! save UserInfo to the file  
     37        void save(const string &file_name); 
    4538 
    4639        operator Setting&(); 
     
    141134        //! and build DOM tree accordingly. Then, it creates a new DOMNode named according class_name 
    142135        //! and connecti it to the passed Setting as a new child node. 
    143         static const Setting* pointer_to_child_setting( const Setting &element, const int index ); 
    144  
    145         static const Setting* pointer_to_child_setting( const Setting &element, const string &name ); 
    146  
    147         static const Setting& reference_to_child_setting( const Setting &element, const int index ); 
    148  
    149         static const Setting& reference_to_child_setting( const Setting &element, const string &name ); 
     136        static const Setting& to_child_setting( const Setting &element, const int index ); 
     137 
     138        static const Setting& to_child_setting( const Setting &element, const string &name ); 
    150139 
    151140 
     
    153142        static void from_setting( mat& matrix, const Setting &element );         
    154143        //! This methods tries to build a new integer vector 
    155         static void from_setting( ivec &vec, const Setting &element ); 
     144        static void from_setting( ivec &vector, const Setting &element ); 
    156145        // jednak kvuli pretypovani, apak taky proto, ze na string nefunguje link_expander.. 
    157146        static void from_setting( string &str, const Setting &element ); 
    158147        //! This methods tries to build a new templated array  
     148 
     149        static void from_setting( vec &vector, const Setting &element ); 
    159150 
    160151        template<class T> static void from_setting( T* &instance, const Setting &element ) 
     
    213204        } 
    214205 
     206        static void ui_error( string message, const Setting &element ); 
     207 
    215208protected: 
    216209        //! default constructor  
     
    223216        virtual ~UI(){}; 
    224217 
    225  
    226218public:  
    227         static void ui_error( string message, const Setting &element ) 
    228         { 
    229                 stringstream error_message; 
    230                 error_message << "UI ui_error: " << message << "! Check path """ << element.getPath() << """, source line " << element.getSourceLine() << "."; 
    231                 it_error ( error_message.str() ); 
    232         } 
    233  
    234219        //! This methods tries to build a new instance of type T (or some of its descendant types) 
    235220        //! according to a data stored in a DOMNode named class_name within a child nodes of the passed element. 
    236         //! If an ui_error occurs, it returns a NULL pointer. 
     221        //! If an error occurs, it returns a NULL pointer. 
    237222 
    238223        //! Prototype of a UI builder. Return value is by the second argument since it type checking via \c dynamic_cast. 
     
    240225        { 
    241226                T* instance; 
    242                 from_setting<T>( reference_to_child_setting( element, index ) ); 
     227                from_setting<T>( to_child_setting( element, index ) ); 
    243228                return instance; 
    244229        } 
     
    247232        {                        
    248233                T* instance; 
    249                 from_setting<T>( instance, reference_to_child_setting( element, name ) ); 
     234                from_setting<T>( instance, to_child_setting( element, name ) ); 
    250235                return instance; 
    251236        } 
    252237 
    253238        //! This methods tries to build a new double matrix  
    254         template<class T> static bool get( T &instance, const Setting &element, const string &name ) 
    255         { 
    256                 const Setting *root = pointer_to_child_setting( element, name ); 
    257                 if( !root ) return false;                                
    258                 from_setting( instance, *root ); 
    259                 return true; 
    260         } 
    261  
    262         //! This methods tries to build a new double matrix  
    263         template<class T> static bool get( T &instance, const Setting &element, const int index ) 
    264         { 
    265                 const Setting *root = pointer_to_child_setting( element, index ); 
    266                 if( !root ) return false;                                
    267                 from_setting( instance, *root ); 
    268                 return true; 
    269         } 
    270  
    271         //! This methods tries to build a new double matrix  
    272         template<class T> static bool get( Array<T> &array_to_load, const Setting &element, const string &name ) 
    273         { 
    274                 const Setting *root = pointer_to_child_setting( element, name ); 
    275                 if( !root ) return false;                                
    276                 from_setting( array_to_load, *root ); 
    277                 return true; 
    278         } 
    279  
    280         //! This methods tries to build a new double matrix  
    281         template<class T> static bool get( Array<T> &array_to_load, const Setting &element, const int index ) 
    282         { 
    283                 const Setting *root = pointer_to_child_setting( element, index ); 
    284                 if( !root ) return false;                                
    285                 from_setting( array_to_load, *root ); 
    286                 return true; 
     239        template<class T> static void get( T &instance, const Setting &element, const string &name ) 
     240        { 
     241                from_setting( instance, to_child_setting( element, name ) ); 
     242        } 
     243 
     244        //! This methods tries to build a new double matrix  
     245        template<class T> static void get( T &instance, const Setting &element, const int index ) 
     246        { 
     247                from_setting( instance, to_child_setting( element, index ) ); 
     248        } 
     249 
     250        //! This methods tries to build a new double matrix  
     251        template<class T> static void get( Array<T> &array_to_load, const Setting &element, const string &name ) 
     252        { 
     253                from_setting( array_to_load, to_child_setting( element, name ) ); 
     254        } 
     255 
     256        //! This methods tries to build a new double matrix  
     257        template<class T> static void get( Array<T> &array_to_load, const Setting &element, const int index ) 
     258        { 
     259                from_setting( array_to_load, to_child_setting( element, index ) ); 
    287260        } 
    288261 
     
    325298        static void save( const ivec &vec, Setting &element, const string &name = "" ); 
    326299         
     300        static void save( const vec &vector, Setting &element, const string &name); 
     301 
    327302        private:  
    328303        //! This methods tries to save a double vec  
     
    385360*/ 
    386361 
    387 #endif // #ifndef UIBUILD 
     362#endif // #ifndef USER_INFO_H 
  • doc/local/codingrules.dox

    r33 r357  
    88\section cr_variables Default Naming Rules for Variables 
    99 
    10 Variables are named using lower-case letters and words are separated 
    11 using under-score. Abbreviations, when used in variable names, are also 
    12 written with lower-case letters. Examples: 
     10Generally, variables are named using lower-case letters and words are separated using 
     11under-score. But there are many exceptions, for instance abbreviations or classical  
     12matematical notations. Therefore, coding rules for variables are quite free. Examples: 
    1313 
    1414<ul> 
    15 <li> \c `fft_size' </li> 
    16 <li> \c `nrof_paths' </li> 
    17 <li> \c `my_variable_name' </li> 
     15<li> \c `FFT_size' </li> 
     16<li> \c `initial_RV' </li> 
     17<li> \c `my_variable' </li> 
    1818</ul> 
    19  
    20 Some variable names or parts of variable names are commonly used in 
    21 several different functions and files to denote the same thing. For 
    22 instance the following common names and prefixes should be used: 
    23  
    24 <ul> 
    25 <li> \c `rows' - number of rows in a matrix </li> 
    26 <li> \c `cols' - number of columns in a matrix </li> 
    27 <li> \c `nrof_' - number of ... </li> 
    28 </ul> 
    29  
    3019 
    3120\section cr_files Default Naming Rules for Files 
    3221 
    3322Files are named using lower-case letters and words are separated using 
    34 under-score. Abbreviations, when used in file names, are also written 
    35 with lower-case letters. 
     23under-score. If an abbreviation is inevitable within file name, it is written with  
     24lower-case letters.  
    3625 
    3726Source files are named using <tt>`.cpp'</tt> suffix, whereas header 
     
    4029<ul> 
    4130<li> <tt>`my_file.h'</tt> </li> 
    42 <li> <tt>`my_file.cpp'</tt> </li> 
     31<li> <tt>`user_info.cpp'</tt> </li> 
    4332</ul> 
    4433 
     34\section cr_file_templates Form of the source files 
     35 
     36For all the library classes, both header file `[filename].h' and source file  
     37`[filename].cpp' should be implemented. And the following few rules should be  
     38respected    
     39 
     40<ul> 
     41 
     42<li> if possible, each `#inline ... ' dircetive should be located within the `.h' 
     43file, one obvious exception is the case of `#inline [filename].h' written in  
     44`[filename].cpp' </li> 
     45 
     46<li> firstly, system headers should be included (i.e. those with brackets  
     47`#include <header_name>'), other headers (like `#include my_header_name.h')  
     48should follow (this rule leads to the faster search of an error on some  
     49compilators) </li> 
     50 
     51<li> source code itself should be placed in the `.cpp' file, `.h' should  
     52contains only class declarations and documentation (this rule has a few exceptions like 
     53 inline functions, templates and some extremely short function bodies)</li> 
     54 
     55</ul> 
     56 
     57Rules considering formatting of the source code itself are stored in the  
     58file \system\astylerc, which is a configuration file for code formating  
     59utility named ASTYLE. To apply them, download the proper version from  
     60its web page http://astyle.sourceforge.net/      
    4561 
    4662\section cr_functions Default Naming Rules for Functions 
     
    7187 
    7288Each new word in a class or structure name should always start with a 
    73 capital letter and the words should be separated with an 
    74 under-score. Abbreviations are written with capital letters. Examples: 
     89capital letter and the words should not be separated. Abbreviations are  
     90written with capital letters. Examples: 
    7591 
    7692<ul> 
    77 <li> \c `My_Class_Name' </li> 
    78 <li> \c `My_Struct_Name' </li> 
     93<li> \c `MyClassName' </li> 
     94<li> \c `MyStructName' </li> 
    7995<li> \c `OFDM' </li> 
    8096</ul> 
  • install.html

    r302 r357  
    1 Please see installation instructions in: 
    2 doc/html/install.html 
     1<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
    32 
    4 or online: 
    5 http://mys.utia.cas.cz:1800/trac/bdm/doxygen/install.html  
     3<html> 
     4<head> 
     5<META HTTP-EQUIV="Content-Type" content="text/html; charset=windows-1250">  
     6<title>Install notes</title> 
     7</head> 
     8 
     9<body> 
     10Please see installation instructions in:<br> 
     11doc/html/install.html<br> 
     12or online:<br> 
     13<a href=http://mys.utia.cas.cz:1800/trac/bdm/doxygen/install.html>http://mys.utia.cas.cz:1800/trac/bdm/doxygen/install.html</a> 
     14</body>  
     15 
  • library/estimator.cpp

    r281 r357  
    4848 */ 
    4949 
    50 #include <stat/libDS_ui.h> 
    51 #include <estim/arx_ui.h> 
     50#include "stat/libDS.h" 
     51#include "estim/arx.h" 
     52#include "user_info.h" 
     53#include "stat/loggers.h" 
    5254 
    5355using namespace bdm; 
     
    5961        else { 
    6062                cout << "Missing configuration file.\n Usage: \n $> estimator config_file.cfg"; 
    61                 abort(); 
     63                //abort(); 
    6264        } 
    63         UIFile F ( fname ); 
     65        fname = "arx_test.cfg"; 
     66        UI_File F ( fname ); 
    6467 
    65         logger* L; 
    66         ArxDS * DS; 
    67         BM* E; 
    68         int Ndat; 
    69  
    70         try { 
    71                 UIbuild ( F.lookup ( "logger" ),L ); 
    72                 UIbuild ( F.lookup ( "system" ),DS ); 
    73                 F.lookupValue ( "experiment.ndat",Ndat ); 
    74                 UIbuild ( F.lookup ( "estimator" ),E ); 
    75         } 
    76         catch UICATCH; 
     68        logger* L = UI::build<logger>( F, "logger"); 
     69        ArxDS * DS = UI::build<ArxDS>( F, "system" ); 
     70        BM* E = UI::build<BM>( F, "estimator" ); 
     71        int Ndat = F.lookupValue ( "experiment.ndat",Ndat ); 
    7772 
    7873        DS->log_add ( *L ); 
  • library/tutorial/arx_mex_test.cfg

    r278 r357  
    1111//estimation 
    1212estimator = { 
    13    type = "ARXest"; 
    14         y = {type="rv"; names=["y"]; }; 
    15         rgr = {type="rv"; 
    16                 names = ["y","y","y","u"]; 
     13   type = "ARX"; 
     14        y = {type="RV"; names=("y"); }; 
     15        rgr = {type="RV"; 
     16                names = ("y","y","y","u"); 
    1717                times = [-1, -2, -3, -1]; 
    1818        }; 
  • library/tutorial/arx_test.cfg

    r278 r357  
    11//Data generating system 
    22system = { 
    3         type = "ArxDS"; 
    4         y = {type="rv"; names=["y", "u"];}; 
    5         u = {type="rv"; names=[]; }; 
    6         rgr = {type="rv"; 
    7                 names = ["y","y","y","u"]; 
     3        class = "ArxDS"; 
     4        y = {class="RV"; names=("y", "u");}; 
     5        u = {class="RV"; names=(); }; 
     6        rgr = {class="RV"; 
     7                names = ("y","y","y","u"); 
    88                times = [-1, -2, -3, -1]; 
    99        }; 
    1010        //AR parameters 
    11         theta = [0.8, -0.3, 0.4, 1.0, 
    12                  0.0, 0.0, 0.0, 0.0]; 
     11        theta = (2,4,[0.8, -0.3, 0.4, 1.0, 
     12                      0.0, 0.0, 0.0, 0.0]); 
    1313        // offset 
    1414        offset = [0.0, 0.0]; 
    1515        //variance 
    16         r = [0.1, 0.0, 
    17              0.0, 1.0]; 
     16        r = (2,2,[0.1, 0.0, 
     17                 0.0, 1.0] ); 
    1818        // log also theta 
    1919        opt="L_theta"; 
     
    2222//store results 
    2323logger = { 
    24         type= "dirfilelog"; 
     24        class= "dirfilelog"; 
    2525        dirname = "exp/arx_ui"; 
    2626        maxlen = 1000; // 
     
    2929//estimation 
    3030estimator = { 
    31         type = "ARXest"; 
    32         y = {type="rv"; names=["y"]; }; 
    33         rgr = {type="rv"; 
    34                 names = ["y","y","y","u"]; 
     31        class = "ARX"; 
     32        y = {class="RV"; names=("y"); }; 
     33        rgr = {class="RV"; 
     34                names = ("y","y","y","u"); 
    3535                times = [-1, -2, -3, -1]; 
    3636        }; 
  • system/win32/INSTALL.txt

    r322 r357  
    99 * ACML 
    1010 * ITPP 
    11  * XSD 
     11 * ASTYLE  
    1212When these are available, please make sure that the  
    13 CMake_module/FindACML and CMake_module/FindITPP can find it. 
     13system/FindACML and system/FindITPP can find it. 
    1414 
    1515Convenience: 
     
    1818If you want to use them copy the content of the zip file to win32\ directory and 
    1919make sure to set your PATH environment variable: 
    20  Path = %PATH%; <mixpp_dir>\win32\dll 
     20 Path = %PATH%; <mixpp_dir>\system\win32\dll 
    2121Otherwise you will not be able to run any programs. 
    2222 
     
    2727* It should generate build files for your compiler in the main BDM  
    2828  directory 
     29* To include ASTYLE code formatting utility directly into Visual Studio, follow  
     30  these steps: 
     31    1) Go to Tools->External Tools. 
     32    2) Click Add 
     33    3) Make the title Astyle 
     34    4) Make the command: [bdmdir]\system\win32\astyle_1.23_windows\astyle\bin\astyle.exe  
     35    5) Make the arguments: --options=[bdmdir]\system\astylerc $(ItemPath)  
     36 
  • tests/CMakeLists.txt

    r322 r357  
    1212EXEC(datalink_test) 
    1313EXEC(loggers_test) 
     14EXEC(testUI) 
    1415 
    1516EXEC(chmat_test) 
     
    3940EXEC(blas_test) 
    4041 
    41 add_subdirectory(UI) 
    4242add_subdirectory(tutorial) 
  • tests/testUI.cpp

    r351 r357  
    11 
    22#include <string> 
    3  
    4 #include <user_info.h> 
     3#include "user_info.h" 
    54 
    65using std::string; 
     
    1211public: 
    1312 
    14         Passenger()      
    15         { 
    16         } 
     13  Passenger() { 
     14  } 
    1715}; 
    1816 
     
    2018{ 
    2119public: 
    22         string name; 
    23  
    24         Human()  
    25         { 
    26                 name = "none"; 
    27         } 
    28  
    29         virtual void from_setting( const Setting &root ) 
    30         { 
    31                 root.lookupValue( "name", name ); 
    32         } 
    33  
    34         virtual void to_setting( Setting &root ) const 
    35         {        
    36                 Setting &name_setting = root.add("name", Setting::TypeString ); 
    37                 name_setting = name; 
    38         } 
    39  
    40         string ToString() 
    41         { 
    42                 return name; 
    43         } 
     20  string name; 
     21 
     22  Human() { 
     23    name = "none"; 
     24  } 
     25 
     26  virtual void from_setting(const Setting &root) { 
     27    root.lookupValue("name", name); 
     28  } 
     29 
     30  virtual void to_setting(Setting &root) const { 
     31    Setting &name_setting = root.add("name", Setting::TypeString); 
     32    name_setting = name; 
     33  } 
     34 
     35  string to_string() { 
     36    return name; 
     37  } 
    4438}; 
    4539 
     
    4943{ 
    5044public: 
    51         int number; 
    52         Array<string> software; 
    53  
    54         Robot() : software() 
    55         { 
    56                 number = -1;             
    57         } 
    58  
    59         virtual void from_setting( const Setting &root ) 
    60         { 
    61                 root.lookupValue( "number", number ); 
    62  
    63                 UI::get( software, root, "software" ); 
    64         } 
    65  
    66         virtual void to_setting( Setting &root ) const 
    67         {        
    68                 Setting &number_setting = root.add("number", Setting::TypeInt ); 
    69                 number_setting = number; 
    70  
    71                 UI::save( software, root, "software" ); 
    72         } 
    73  
    74         string ToString() 
    75         { 
    76                 stringstream stream; 
    77                 stream << number; 
    78                 for( int i = 0; i<software.length(); i++) 
    79                         stream << "_" + software(i); 
    80                 return stream.str(); 
    81         } 
     45  int number; 
     46  Array<string> software; 
     47 
     48  Robot() : software() { 
     49    number = -1; 
     50  } 
     51 
     52  virtual void from_setting(const Setting &root) { 
     53    root.lookupValue("number", number); 
     54        if( root.exists( "software" ) ) 
     55                UI::get(software, root, "software"); 
     56  } 
     57 
     58  virtual void to_setting(Setting &root) const { 
     59    Setting &number_setting = root.add("number", Setting::TypeInt); 
     60    number_setting = number; 
     61 
     62    UI::save(software, root, "software"); 
     63  } 
     64 
     65  string to_string() { 
     66    stringstream stream; 
     67    stream << number; 
     68    for (int i = 0; i < software.length(); i++) 
     69      stream << "_" + software(i); 
     70    return stream.str(); 
     71  } 
    8272}; 
    8373 
     
    8777{ 
    8878public: 
    89         int year; 
    90         string manufacturer; 
    91  
    92         Transport() 
    93         { 
    94                 year = 1900; 
    95                 manufacturer = "unknown"; 
    96         } 
    97  
    98         Transport( int year, string manufacturer ) 
    99                 : year( year ), manufacturer( manufacturer ) 
    100         { 
    101         } 
    102  
    103         virtual void from_setting( const Setting &root ) 
    104         { 
    105                 root.lookupValue( "year", year ); 
    106                 root.lookupValue( "manufacturer", manufacturer ); 
    107         } 
    108  
    109         virtual void to_setting( Setting &root ) const 
    110         {        
    111                 Setting &year_setting = root.add("year", Setting::TypeInt ); 
    112                 year_setting = year; 
    113  
    114                 Setting &manufacturer_setting = root.add("manufacturer", Setting::TypeString ); 
    115                 manufacturer_setting = manufacturer;     
    116         } 
     79  int year; 
     80  string manufacturer; 
     81 
     82  Transport() { 
     83    year = 1900; 
     84    manufacturer = "unknown"; 
     85  } 
     86 
     87  Transport(int year, string manufacturer) 
     88      : year(year), manufacturer(manufacturer) { 
     89  } 
     90 
     91  virtual void from_setting(const Setting &root) { 
     92    root.lookupValue("year", year); 
     93    root.lookupValue("manufacturer", manufacturer); 
     94  } 
     95 
     96  virtual void to_setting(Setting &root) const { 
     97    Setting &year_setting = root.add("year", Setting::TypeInt); 
     98    year_setting = year; 
     99 
     100    Setting &manufacturer_setting = root.add("manufacturer", Setting::TypeString); 
     101    manufacturer_setting = manufacturer; 
     102  } 
    117103}; 
    118104 
     
    120106{ 
    121107public: 
    122         int kilometers; 
    123         Array<Passenger*> passengers; 
    124  
    125         Car() : Transport()                
    126         { 
    127                 kilometers = 0; 
    128         } 
    129  
    130  
    131         Car( int year, string manufacturer, int kilometers ) 
    132                 : Transport( year, manufacturer ), kilometers( kilometers ) 
    133         { 
    134         } 
    135  
    136         virtual void from_setting( const Setting &root )  
    137         {        
    138                 Transport::from_setting( root ); 
    139  
    140                 root.lookupValue( "kilometers", kilometers ); 
    141  
    142                 UI::get( passengers, root, "passengers" ); 
    143         } 
    144  
    145         virtual void to_setting( Setting &root ) const 
    146         {        
    147                 Transport::to_setting( root ); 
    148  
    149                 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 
    150                 kilometers_setting = kilometers; 
    151  
    152                 UI::save( passengers, root, "passengers" ); 
    153         } 
    154  
    155         string ToString() 
    156         { 
    157                 stringstream stream; 
    158                 stream << "A car made in " << year << " by " << manufacturer << ", having " << kilometers << " kilometers on the clock."; 
    159                 if( passengers.length() ) 
    160                 { 
    161                         stream << "The names of passengers are as follows: "; 
    162                         for( int i=0; i<passengers.length(); i++) 
    163                                 stream << passengers(i)->ToString() << " "; 
    164                 } 
    165                 return stream.str(); 
    166         } 
     108  int kilometers; 
     109  Array<Passenger*> passengers; 
     110 
     111  Car() : Transport() { 
     112    kilometers = 0; 
     113  } 
     114 
     115 
     116  Car(int year, string manufacturer, int kilometers) 
     117      : Transport(year, manufacturer), kilometers(kilometers) { 
     118  } 
     119 
     120  virtual void from_setting(const Setting &root) { 
     121    Transport::from_setting(root); 
     122 
     123    root.lookupValue("kilometers", kilometers); 
     124 
     125        if( root.exists( "passengers" ) ) 
     126            UI::get(passengers, root, "passengers"); 
     127  } 
     128 
     129  virtual void to_setting(Setting &root) const { 
     130    Transport::to_setting(root); 
     131 
     132    Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt); 
     133    kilometers_setting = kilometers; 
     134 
     135    UI::save(passengers, root, "passengers"); 
     136  } 
     137 
     138  string to_string() { 
     139    stringstream stream; 
     140    stream << "A car made in " << year << " by " << manufacturer << ", having " << kilometers << " kilometers on the clock."; 
     141    if (passengers.length()) { 
     142      stream << "The names of passengers are as follows: "; 
     143      for (int i = 0; i < passengers.length(); i++) 
     144        stream << passengers(i)->to_string() << " "; 
     145    } 
     146    return stream.str(); 
     147  } 
    167148}; 
    168149 
     
    172153{ 
    173154public: 
    174         bool electricLights; 
    175         mat matr; 
    176  
    177         Bike() : Transport(), matr("2,2;3,4") 
    178         { 
    179                 electricLights = false;          
    180         } 
    181  
    182         Bike( int year, string manufacturer, bool electricLights ) 
    183                 : Transport( year, manufacturer ), electricLights( electricLights ) 
    184         { 
    185         } 
    186  
    187         ~Bike() 
    188         { 
    189         } 
    190  
    191         void from_setting( const Setting &root )  
    192         {        
    193                 Transport::from_setting( root ); 
    194  
    195                 root.lookupValue( "electricLights", electricLights ); 
    196  
    197                 UI::get( matr, root, "matr" ); 
    198         } 
    199  
    200         void to_setting( Setting &root ) const 
    201         {        
    202                 Transport::to_setting( root ); 
    203  
    204                 Setting &electricLights_setting = root.add("electricLights", Setting::TypeBoolean ); 
    205                 electricLights_setting = electricLights; 
    206  
    207                 UI::save( matr, root, "matr" ); 
    208         } 
    209  
    210         string ToString() 
    211         { 
    212                 stringstream stream; 
    213                 stream << "a bike made in " << year << " by " << manufacturer; 
    214                 if( electricLights ) stream << " with electric lights included";                                                 
    215                 return stream.str(); 
    216         } 
     155  bool electricLights; 
     156  mat matr; 
     157 
     158  Bike() : Transport(), matr("2,2;3,4") { 
     159    electricLights = false; 
     160  } 
     161 
     162  Bike(int year, string manufacturer, bool electricLights) 
     163      : Transport(year, manufacturer), electricLights(electricLights) { 
     164  } 
     165 
     166  ~Bike() { 
     167  } 
     168 
     169  void from_setting(const Setting &root) { 
     170    Transport::from_setting(root); 
     171 
     172    root.lookupValue("electricLights", electricLights); 
     173 
     174        UI::get(matr, root, "matr"); 
     175  } 
     176 
     177  void to_setting(Setting &root) const { 
     178    Transport::to_setting(root); 
     179 
     180    Setting &electricLights_setting = root.add("electricLights", Setting::TypeBoolean); 
     181    electricLights_setting = electricLights; 
     182 
     183    UI::save(matr, root, "matr"); 
     184  } 
     185 
     186  string to_string() { 
     187    stringstream stream; 
     188    stream << "a bike made in " << year << " by " << manufacturer; 
     189    if (electricLights) stream << " with electric lights included"; 
     190    return stream.str(); 
     191  } 
    217192}; 
    218193 
     
    220195 
    221196int main() 
    222 {        
    223         //////////////////////////////////// LOADING //////////////////////////////// 
    224         UI_File in("testUI_in.cfg");     
    225         in.load(); 
    226         Transport *pepikovo = UI::build<Transport>( in, "pepikovo");     
    227         cout << "pepikovo: " << pepikovo->ToString() << endl;            
    228         Transport *jardovo = UI::build<Transport>( in, "jardovo");       
    229         cout << "jardovo: " << jardovo->ToString() << endl;              
    230         Transport *ondrejovo = UI::build<Transport>( in, "ondrejovo");   
    231         cout << "ondrejovo: " << ondrejovo->ToString() << endl;          
    232         Transport *elisky = UI::build<Transport>( in, "elisky");         
    233         cout << "elisky: " << elisky->ToString() << endl;                
    234         Transport *kati = UI::build<Transport>( in, "kati");     
    235         cout << "kati: " << kati->ToString() << endl;            
    236         getchar();  
    237  
    238         /////////////////////////////////// SAVING ////////////////////////// 
    239  
    240         Car audi( 1968, "zyl", 200); 
    241         Car liaz( 1989, "skoda", 1000); 
    242         Bike author( 2001, "noname", false ); 
    243         UI_File out("testUI_out.cfg");   
    244  
    245         UI::save( &audi, out, "marty"); 
    246         UI::save( &liaz, out, "bohousovo");  
    247         UI::save( &author, out, "karlovo"); 
    248         UI::save( pepikovo, out, "pepikovo"); 
    249         out.save(); 
    250  
    251         cout << "all the transport means were saved correctly" << endl;                          
    252         getchar(); 
    253         return 0; 
     197{ 
     198  //////////////////////////////////// LOADING //////////////////////////////// 
     199  UI_File in("testUI_in.cfg"); 
     200  Transport *pepikovo = UI::build<Transport>(in, "pepikovo"); 
     201  cout << "pepikovo: " << pepikovo->to_string() << endl; 
     202  Transport *jardovo = UI::build<Transport>(in, "jardovo"); 
     203  cout << "jardovo: " << jardovo->to_string() << endl; 
     204  Transport *ondrejovo = UI::build<Transport>(in, "ondrejovo"); 
     205  cout << "ondrejovo: " << ondrejovo->to_string() << endl; 
     206  Transport *elisky = UI::build<Transport>(in, "elisky"); 
     207  cout << "elisky: " << elisky->to_string() << endl; 
     208  Transport *kati = UI::build<Transport>(in, "kati"); 
     209  cout << "kati: " << kati->to_string() << endl; 
     210  getchar(); 
     211 
     212  /////////////////////////////////// SAVING ////////////////////////// 
     213 
     214  Car audi(1968, "zyl", 200); 
     215  Car liaz(1989, "skoda", 1000); 
     216  Bike author(2001, "noname", false); 
     217  UI_File out; 
     218 
     219  UI::save(&audi, out, "marty"); 
     220  UI::save(&liaz, out, "bohousovo"); 
     221  UI::save(&author, out, "karlovo"); 
     222  UI::save(pepikovo, out, "pepikovo"); 
     223  out.save("testUI_out.cfg"); 
     224 
     225  cout << "all the transport means were saved correctly" << endl; 
     226  getchar(); 
     227  return 0; 
    254228}