SmoothCompareTrans.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_SmoothCompareTrans_h_
00003 #define INCLUDED_SmoothCompareTrans_h_
00004
00005 #include "Behaviors/Transitions/CompareTrans.h"
00006
00007
00008
00009
00010
00011
00012
00013
00014 template<class T>
00015 class SmoothCompareTrans : public CompareTrans<T> {
00016 public:
00017
00018 SmoothCompareTrans(StateNode* destination, const T* monitor, typename SmoothCompareTrans<T>::Test_t test, const T& value, const EventBase& poll, float gammap=0)
00019 : CompareTrans<T>(destination,&avg,test,value,poll), avg(*monitor), realmon(monitor),
00020 burnin((unsigned int)(1/(1-gammap))), tests(0), g(gammap)
00021 { }
00022
00023
00024 SmoothCompareTrans(const std::string& name, StateNode* destination, const T* monitor, typename SmoothCompareTrans<T>::Test_t test, const T& value, const EventBase& poll, float gammap=0)
00025 : CompareTrans<T>(name,destination,&avg,test,value,poll), avg(*monitor), realmon(monitor),
00026 burnin((unsigned int)(1/(1-gammap))), tests(0), g(gammap)
00027 { }
00028
00029 virtual void postStart() {
00030 avg=*realmon;
00031 tests=0;
00032 CompareTrans<T>::postStart();
00033 }
00034
00035
00036 void setBurnIn(unsigned int i) {
00037 burnin=i;
00038 }
00039
00040
00041 unsigned int getBurnIn() {
00042 return burnin;
00043 }
00044
00045
00046 virtual void doEvent() {
00047 avg*=g;
00048 T x(*realmon);
00049 x*=(1-g);
00050 avg+=x;
00051 tests++;
00052 if(tests>burnin)
00053 CompareTrans<T>::doEvent();
00054 }
00055
00056 protected:
00057 T avg;
00058 const T* realmon;
00059
00060 unsigned int burnin;
00061 unsigned int tests;
00062
00063
00064 float g;
00065
00066 private:
00067 SmoothCompareTrans(const SmoothCompareTrans& node);
00068 SmoothCompareTrans operator=(const SmoothCompareTrans& node);
00069 };
00070
00071
00072
00073
00074
00075
00076 #endif