Changeset 737 for library/tests/testsuite
- Timestamp:
- 11/25/09 12:14:38 (15 years ago)
- Location:
- library/tests/testsuite
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/testsuite/LQG_test.cpp
r723 r737 5 5 using namespace bdm; 6 6 7 TEST (LQG_test) {7 TEST ( LQG_test ) { 8 8 LQG reg; 9 shared_ptr<StateSpace<chmat> > stsp =new StateSpace<chmat>;9 shared_ptr<StateSpace<chmat> > stsp = new StateSpace<chmat>; 10 10 // 2 x 1 x 1 11 stsp-> set_parameters (eye(2), ones(2,1), ones(1,2), ones(1,1), /* Q,R */ eye(2), eye(1));12 reg.set_system (stsp); // A, B, C13 reg.set_control_parameters (eye(1), eye(1), vec_1(1.0), 6); //Qy, Qu, horizon11 stsp-> set_parameters ( eye ( 2 ), ones ( 2, 1 ), ones ( 1, 2 ), ones ( 1, 1 ), /* Q,R */ eye ( 2 ), eye ( 1 ) ); 12 reg.set_system ( stsp ); // A, B, C 13 reg.set_control_parameters ( eye ( 1 ), eye ( 1 ), vec_1 ( 1.0 ), 6 ); //Qy, Qu, horizon 14 14 reg.validate(); 15 15 16 16 reg.redesign(); 17 double reg_apply =reg.ctrlaction("0.5, 1.1","0.0")(0); /*convert vec to double*/18 CHECK_CLOSE (reg_apply, -0.248528137234392, 0.0001);17 double reg_apply = reg.ctrlaction ( "0.5, 1.1", "0.0" ) ( 0 ); /*convert vec to double*/ 18 CHECK_CLOSE ( reg_apply, -0.248528137234392, 0.0001 ); 19 19 } 20 20 21 TEST (to_state_test) {21 TEST ( to_state_test ) { 22 22 mlnorm<fsqmat> ml; 23 mat A ="1.1, 2.3";24 ml.set_parameters (A, vec_1(1.3), eye(1));25 RV yr =RV("y",1);26 RV ur =RV("u",1);27 ml.set_rv (yr);28 yr.t_plus (-1);29 ml.set_rvc (concat(yr, ur));30 31 shared_ptr<StateCanonical > Stsp =new StateCanonical;32 Stsp->connect_mlnorm (ml);33 34 /* results from 23 mat A = "1.1, 2.3"; 24 ml.set_parameters ( A, vec_1 ( 1.3 ), eye ( 1 ) ); 25 RV yr = RV ( "y", 1 ); 26 RV ur = RV ( "u", 1 ); 27 ml.set_rv ( yr ); 28 yr.t_plus ( -1 ); 29 ml.set_rvc ( concat ( yr, ur ) ); 30 31 shared_ptr<StateCanonical > Stsp = new StateCanonical; 32 Stsp->connect_mlnorm ( ml ); 33 34 /* results from 35 35 [A,B,C,D]=tf2ss([2.3 0],[1 -1.1]) 36 36 */ 37 CHECK_CLOSE_EX (Stsp->_A().get_row(0), vec("1.1"), 0.0001);38 CHECK_CLOSE_EX (Stsp->_C().get_row(0), vec("2.53"), 0.0001);39 CHECK_CLOSE_EX (Stsp->_D().get_row(0), vec("2.30"), 0.0001);37 CHECK_CLOSE_EX ( Stsp->_A().get_row ( 0 ), vec ( "1.1" ), 0.0001 ); 38 CHECK_CLOSE_EX ( Stsp->_C().get_row ( 0 ), vec ( "2.53" ), 0.0001 ); 39 CHECK_CLOSE_EX ( Stsp->_D().get_row ( 0 ), vec ( "2.30" ), 0.0001 ); 40 40 } 41 41 42 TEST (to_state_arx_test) {42 TEST ( to_state_arx_test ) { 43 43 mlnorm<chmat> ml; 44 mat A="1.1, 2.3, 3.4"; 45 ml.set_parameters(A, vec_1(1.3), eye(1)); 46 RV yr=RV("y",1); 47 RV ur=RV("u",1); 48 ml.set_rv(yr); 49 ml.set_rvc(concat(yr.copy_t(-1), concat(ur, ur.copy_t(-1)))); 50 51 shared_ptr<StateFromARX> Stsp=new StateFromARX; 52 RV xrv; RV urv; 53 Stsp->connect_mlnorm(ml,xrv,urv); 54 55 /* results from 44 mat A = "1.1, 2.3, 3.4"; 45 ml.set_parameters ( A, vec_1 ( 1.3 ), eye ( 1 ) ); 46 RV yr = RV ( "y", 1 ); 47 RV ur = RV ( "u", 1 ); 48 ml.set_rv ( yr ); 49 ml.set_rvc ( concat ( yr.copy_t ( -1 ), concat ( ur, ur.copy_t ( -1 ) ) ) ); 50 51 shared_ptr<StateFromARX> Stsp = new StateFromARX; 52 RV xrv; 53 RV urv; 54 Stsp->connect_mlnorm ( ml, xrv, urv ); 55 56 /* results from 56 57 [A,B,C,D]=tf2ss([2.3 0],[1 -1.1]) 57 58 */ 58 CHECK_CLOSE_EX (Stsp->_A().get_row(0), vec("1.1, 3.4, 1.3"), 0.0001);59 CHECK_CLOSE_EX (Stsp->_B().get_row(0), vec("2.3"), 0.0001);60 CHECK_CLOSE_EX (Stsp->_C().get_row(0), vec("1, 0, 0"), 0.0001);59 CHECK_CLOSE_EX ( Stsp->_A().get_row ( 0 ), vec ( "1.1, 3.4, 1.3" ), 0.0001 ); 60 CHECK_CLOSE_EX ( Stsp->_B().get_row ( 0 ), vec ( "2.3" ), 0.0001 ); 61 CHECK_CLOSE_EX ( Stsp->_C().get_row ( 0 ), vec ( "1, 0, 0" ), 0.0001 ); 61 62 } 62 63 63 TEST (arx_LQG_test){64 TEST ( arx_LQG_test ) { 64 65 mlnorm<chmat> ml; 65 mat A ="1.81, -.81, .00468, .00438";66 ml.set_parameters (A, vec_1(0.0), 0.00001*eye(1));67 RV yr =RV("y",1);68 RV ur =RV("u",1);69 RV rgr = yr.copy_t (-1);70 rgr.add (yr.copy_t(-2));71 rgr.add (yr.copy_t(-2));72 rgr.add (ur.copy_t(-1));73 rgr.add (ur);74 75 ml.set_rv (yr);76 ml.set_rvc (rgr);66 mat A = "1.81, -.81, .00468, .00438"; 67 ml.set_parameters ( A, vec_1 ( 0.0 ), 0.00001*eye ( 1 ) ); 68 RV yr = RV ( "y", 1 ); 69 RV ur = RV ( "u", 1 ); 70 RV rgr = yr.copy_t ( -1 ); 71 rgr.add ( yr.copy_t ( -2 ) ); 72 rgr.add ( yr.copy_t ( -2 ) ); 73 rgr.add ( ur.copy_t ( -1 ) ); 74 rgr.add ( ur ); 75 76 ml.set_rv ( yr ); 77 ml.set_rvc ( rgr ); 77 78 ml.validate(); 78 79 shared_ptr<StateFromARX> Stsp=new StateFromARX; 80 RV xrv; RV urv; 81 Stsp->connect_mlnorm(ml,xrv,urv); 82 79 80 shared_ptr<StateFromARX> Stsp = new StateFromARX; 81 RV xrv; 82 RV urv; 83 Stsp->connect_mlnorm ( ml, xrv, urv ); 84 83 85 LQG L; 84 L.set_system (Stsp);85 L.set_control_parameters (eye(1), sqrt(1.0/1000)*eye(1), vec_1(0.0), 100);86 L.set_system ( Stsp ); 87 L.set_control_parameters ( eye ( 1 ), sqrt ( 1.0 / 1000 ) *eye ( 1 ), vec_1 ( 0.0 ), 100 ); 86 88 L.validate(); 87 89 88 90 L.redesign(); 89 cout << L.to_string() <<endl;91 cout << L.to_string() << endl; 90 92 } -
library/tests/testsuite/datalink_test.cpp
r723 r737 101 101 102 102 vec val_up ( "1 2" ); 103 dl.store_data (val_up);103 dl.store_data ( val_up ); 104 104 val_up = "3 4"; 105 105 -
library/tests/testsuite/logger_test.cpp
r728 r737 42 42 43 43 int pol = 11; 44 44 45 45 int rid = logger.add_vector ( r, "" ); 46 46 int thid = logger.add_vector ( th, "th" ); 47 int polid = logger.add_setting ("pols");47 int polid = logger.add_setting ( "pols" ); 48 48 49 49 logger.init(); … … 52 52 logger.log_vector ( rid, vec_2 ( ( double ) i, ( double ) ( i + 1 ) ) ); 53 53 logger.log_vector ( thid, vec_2 ( ( double ) ( 100 - i ), ( double ) ( i - 50 ) ) ); 54 UI::save (pol, logger.log_to_setting(polid), "polozka");54 UI::save ( pol, logger.log_to_setting ( polid ), "polozka" ); 55 55 logger.step(); 56 56 } … … 58 58 logger.finalize(); 59 59 60 CHECK_EQUAL ( get_file_size ( "logger_test.matrix" ), get_file_size ( ( ls+".it").c_str() ) );61 CHECK_EQUAL ( get_file_size ( ( ls+".cfg.check").c_str() ), get_file_size ( (ls+".cfg" ).c_str() ));60 CHECK_EQUAL ( get_file_size ( "logger_test.matrix" ), get_file_size ( ( ls + ".it" ).c_str() ) ); 61 CHECK_EQUAL ( get_file_size ( ( ls + ".cfg.check" ).c_str() ), get_file_size ( ( ls + ".cfg" ).c_str() ) ); 62 62 } 63 63