root/library/bdm/design/ctrlbase.h @ 1014

Revision 907, 3.7 kB (checked in by mido, 14 years ago)

LOG LEVEL improved and hopefully finished

  • Property svn:eol-style set to native
Line 
1/*!
2  \file
3  \brief Base classes for designers of control strategy
4  \author Vaclav Smidl.
5
6  -----------------------------------
7  BDM++ - C++ library for Bayesian Decision Making under Uncertainty
8
9  Using IT++ for numerical operations
10  -----------------------------------
11*/
12
13#include "../base/bdmbase.h"
14#include "../estim/kalman.h"
15
16namespace bdm {
17
18//! Base class for adaptive controllers
19//! The base class is, however, non-adaptive, method \c adapt() is empty.
20//! \note advanced Controllers will probably include estimator as their internal attribute (e.g. dual controllers)
21class Controller : public root {
22protected:
23        //! identifier of the designed action;
24        RV rv;
25        //! identifier of the conditioning variables - data needed ;
26        RV rvc;
27public:
28        //! function processing new observations and adapting control strategy accordingly
29        virtual void adapt ( const vec &data ) {};
30        //! function redesigning the control strategy
31        virtual void redesign() {};
32        //! returns designed control action
33        virtual vec ctrlaction ( const vec &cond ) const {
34                return vec ( 0 );
35        }
36
37        void from_setting ( const Setting &set ) {
38                shared_ptr<RV> rv_ptr = UI::build<RV>( set, "rv", UI::optional );
39                if( rv_ptr ) rv = *rv_ptr;
40                shared_ptr<RV> rvc_ptr = UI::build<RV>( set, "rvc", UI::optional );
41                if( rvc_ptr ) rvc = *rvc_ptr;
42        }
43        //! access function
44        const RV& _rv() {
45                return rv;
46        }
47        //! access function
48        const RV& _rvc() {
49                return rvc;
50        }
51        //! register this controller with given datasource under name "name"
52        virtual void log_register ( logger &L, const string &prefix ) { }
53        //! write requested values into the logger
54        virtual void log_write ( ) const { }
55
56};
57
58//! Linear Quadratic Gaussian designer for constant penalizations and constant target
59//! Its internals are very close to Kalman estimator
60class LQG : public Controller {
61protected:
62        //! StateSpace model from which we read data
63        shared_ptr<StateSpace<chmat> > S;
64        //! required value of the output y at time t (assumed constant)
65        vec y_req;
66        //! required value of the output y at time t (assumed constant)
67        vec u_req;
68
69        //! Control horizon, set to maxint for infinite horizons
70        int horizon;
71        //! penalization matrix Qy
72        chmat Qy;
73        //! penalization matrix Qu
74        chmat Qu;
75        //! time of the design step - from horizon->0
76        int td;
77        //! controller parameters
78        mat L;
79
80        //!@{ \name temporary storage for ricatti - use initialize
81        //! convenience parameters
82        int dimx;
83        //! convenience parameters
84        int dimy;
85        //! convenience parameters
86        int dimu;
87
88        //!  parameters
89        mat pr;
90        //! penalization
91        mat qux;
92        //! penalization
93        mat qyx;
94        //! internal quadratic form
95        mat s;
96        //! penalization
97        mat qy;
98        //! pre_qr part
99        mat hqy;
100        //! pre qr matrix
101        mat pre_qr;
102        //! post qr matrix
103        mat post_qr;
104        //!@}
105
106public:
107        //! set system parameters from given matrices
108        void set_system ( shared_ptr<StateSpace<chmat> > S0 );
109        //! update internal whan system has changed
110        void update_system();
111        //! set penalization matrices and control horizon
112        void set_control_parameters ( const mat &Qy0, const mat &Qu0, const vec &y_req0, int horizon0 );
113        //! set penalization matrices and control horizon
114        void set_control_Qy ( const mat &Qy0 ) {
115                Qy = Qy0;
116        }
117        //! refresh temporary storage - inefficient can be improved
118        void initial_belmann() {
119                s = 1e-5 * eye ( dimx + dimu + dimy );
120        };
121        //! validation procedure
122        void validate();
123        //! function for future use which is called at each time td; Should call initialize()!
124        //! redesign one step of the
125        void ricatti_step();
126       
127        void redesign();
128
129        //! compute control action
130        vec ctrlaction ( const vec &state, const vec &ukm ) const {
131                vec pom = concat ( state, ones ( dimy ), ukm );
132                return L*pom;
133        }
134        //! access function
135        mat _L() const {
136                return L;
137        }
138} ;
139
140
141} // namespace
Note: See TracBrowser for help on using the browser.