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

Revision 738, 3.6 kB (checked in by mido, 15 years ago)

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

  • 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                UI::get ( rv, set, "rv", UI::optional );
39                UI::get ( rvc, set, "rvc", UI::optional );
40        }
41        //! access function
42        const RV& _rv() {
43                return rv;
44        }
45        //! access function
46        const RV& _rvc() {
47                return rvc;
48        }
49        //! register this controller with given datasource under name "name"
50        virtual void log_register ( logger &L, const string &prefix ) { }
51        //! write requested values into the logger
52        virtual void log_write ( ) const { }
53
54};
55
56//! Linear Quadratic Gaussian designer for constant penalizations and constant target
57//! Its internals are very close to Kalman estimator
58class LQG : public Controller {
59protected:
60        //! StateSpace model from which we read data
61        shared_ptr<StateSpace<chmat> > S;
62        //! required value of the output y at time t (assumed constant)
63        vec y_req;
64        //! required value of the output y at time t (assumed constant)
65        vec u_req;
66
67        //! Control horizon, set to maxint for infinite horizons
68        int horizon;
69        //! penalization matrix Qy
70        chmat Qy;
71        //! penalization matrix Qu
72        chmat Qu;
73        //! time of the design step - from horizon->0
74        int td;
75        //! controller parameters
76        mat L;
77
78        //!@{ \name temporary storage for ricatti - use initialize
79        //! convenience parameters
80        int dimx;
81        //! convenience parameters
82        int dimy;
83        //! convenience parameters
84        int dimu;
85
86        //!  parameters
87        mat pr;
88        //! penalization
89        mat qux;
90        //! penalization
91        mat qyx;
92        //! internal quadratic form
93        mat s;
94        //! penalization
95        mat qy;
96        //! pre_qr part
97        mat hqy;
98        //! pre qr matrix
99        mat pre_qr;
100        //! post qr matrix
101        mat post_qr;
102        //!@}
103
104public:
105        //! set system parameters from given matrices
106        void set_system ( shared_ptr<StateSpace<chmat> > S0 );
107        //! update internal whan system has changed
108        void update_system();
109        //! set penalization matrices and control horizon
110        void set_control_parameters ( const mat &Qy0, const mat &Qu0, const vec &y_req0, int horizon0 );
111        //! set penalization matrices and control horizon
112        void set_control_Qy ( const mat &Qy0 ) {
113                Qy = Qy0;
114        }
115        //! refresh temporary storage - inefficient can be improved
116        void initial_belmann() {
117                s = 1e-5 * eye ( dimx + dimu + dimy );
118        };
119        //! validation procedure
120        void validate();
121        //! function for future use which is called at each time td; Should call initialize()!
122        //! redesign one step of the
123        void ricatti_step();
124       
125        void redesign();
126
127        //! compute control action
128        vec ctrlaction ( const vec &state, const vec &ukm ) const {
129                vec pom = concat ( state, ones ( dimy ), ukm );
130                return L*pom;
131        }
132        //! access function
133        mat _L() const {
134                return L;
135        }
136} ;
137
138
139} // namespace
Note: See TracBrowser for help on using the browser.