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 virtual void DoStart() {
00024 CompareTrans<T>::DoStart();
00025 avg=*realmon;
00026 tests=0;
00027 }
00028
00029
00030 void setBurnIn(unsigned int i) {
00031 burnin=i;
00032 }
00033
00034
00035 unsigned int getBurnIn() {
00036 return burnin;
00037 }
00038
00039
00040 virtual void processEvent(const EventBase& e) {
00041 avg*=g;
00042 T x(*realmon);
00043 x*=(1-g);
00044 avg+=x;
00045 tests++;
00046 if(tests>burnin)
00047 CompareTrans<T>::processEvent(e);
00048 }
00049
00050 virtual std::string getName() const { return "SmoothCompareTrans"; }
00051
00052 protected:
00053 T avg;
00054 const T* realmon;
00055
00056 unsigned int burnin;
00057 unsigned int tests;
00058
00059
00060 float g;
00061
00062 private:
00063 SmoothCompareTrans(const SmoothCompareTrans& node);
00064 SmoothCompareTrans operator=(const SmoothCompareTrans& node);
00065 };
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 #endif