cdetect.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __CDETECT_H
00028 #define __CDETECT_H
00029
00030 #include "cownedobject.h"
00031 #include "cstatistic.h"
00032
00033 NAMESPACE_BEGIN
00034
00035
00036 class cStatistic;
00037
00042 typedef void (*PostTDFunc)(cTransientDetection *, void *);
00043
00048 typedef void (*PostADFunc)(cAccuracyDetection *, void *);
00049
00050
00056 class SIM_API cTransientDetection : public cOwnedObject
00057 {
00058 protected:
00059 cStatistic *back;
00060 PostTDFunc pdf;
00061 void *pdfdata;
00062
00063 public:
00069 explicit cTransientDetection(const char *name=NULL) : cOwnedObject(name) {}
00070
00074 virtual ~cTransientDetection() {}
00075
00079 virtual cTransientDetection *dup() const {copyNotSupported(); return NULL;}
00081
00082
00083
00086
00090 virtual void collect(double val) = 0;
00091
00095 virtual bool detected() const = 0;
00096
00100 virtual void reset() = 0;
00101
00106 virtual void stop() = 0;
00107
00112 virtual void start() = 0;
00113
00118 void setPostDetectFunction(PostTDFunc f, void *p) {pdf = f; pdfdata = p;}
00120
00123
00128 virtual void setHostObject(cStatistic *ptr) {back = ptr;}
00129
00133 virtual cStatistic *getHostObject() const {return back;}
00135 };
00136
00137
00138
00139
00145 class SIM_API cAccuracyDetection : public cOwnedObject
00146 {
00147 protected:
00148 cStatistic *back;
00149 PostADFunc pdf;
00150 void *pdfdata;
00151
00152 public:
00158 explicit cAccuracyDetection(const char *name=NULL) : cOwnedObject(name) {}
00159
00163 virtual ~cAccuracyDetection() {}
00164
00168 virtual cAccuracyDetection *dup() const {copyNotSupported(); return NULL;}
00170
00173
00174
00176
00179
00183 virtual void collect(double val) = 0;
00184
00188 virtual bool detected() const = 0;
00189
00193 virtual void reset() = 0;
00194
00199 virtual void stop() = 0;
00200
00205 virtual void start() = 0;
00206
00211 void setPostDetectFunction(PostADFunc f, void *p) {pdf=f; pdfdata=p;}
00213
00216
00221 virtual void setHostObject(cStatistic *ptr) {back = ptr;}
00222
00226 virtual cStatistic *getHostObject() const {return back;}
00228 };
00229
00230
00231
00239 class SIM_API cTDExpandingWindows : public cTransientDetection
00240 {
00241 private:
00242 bool go;
00243 bool transval;
00244 double accuracy;
00245 int minwinds;
00246 double windexp;
00247 int repeats;
00248 int detreps;
00249 int size;
00250 struct xy {double x; double y; xy *next;};
00251 xy *func;
00252
00253 private:
00254
00255 void detectTransient();
00256
00257 void copy(const cTDExpandingWindows& other);
00258
00259 public:
00262
00266 cTDExpandingWindows(const cTDExpandingWindows& r);
00267
00271 explicit cTDExpandingWindows(const char *name=NULL,
00272 int reps=3, int minw=4, double wind=1.3, double acc=0.3,
00273 PostTDFunc f=NULL,void *p=NULL);
00274
00278 virtual ~cTDExpandingWindows();
00279
00284 cTDExpandingWindows& operator=(const cTDExpandingWindows& res);
00286
00289
00294 virtual cTDExpandingWindows *dup() const {return new cTDExpandingWindows(*this);}
00296
00299
00303 virtual void collect(double val);
00304
00308 virtual bool detected() const {return transval;}
00309
00313 virtual void reset();
00314
00318 virtual void stop() {go = false;}
00319
00324 virtual void start() {go = true;}
00326
00332 void setParameters(int reps=3, int minw=4,
00333 double wind=1.3, double acc=0.3);
00335 };
00336
00337
00338
00339
00347 class SIM_API cADByStddev : public cAccuracyDetection
00348 {
00349 private:
00350 bool go;
00351 bool resaccval;
00352 double accuracy;
00353 long int sctr;
00354 double ssum,sqrsum;
00355 int repeats, detreps;
00356
00357 private:
00358 void copy(const cADByStddev& other);
00359
00360
00361 void detectAccuracy();
00362
00363
00364 double getStddev() const;
00365
00366 public:
00369
00373 cADByStddev(const cADByStddev& r);
00374
00378 explicit cADByStddev(const char *name=NULL,
00379 double acc=0.01, int reps=3,
00380 PostADFunc f=NULL, void *p=NULL);
00381
00385 virtual ~cADByStddev() {}
00386
00391 cADByStddev& operator=(const cADByStddev& res);
00393
00396
00401 virtual cADByStddev *dup() const {return new cADByStddev(*this);}
00403
00406
00410 virtual void collect(double val);
00411
00415 virtual bool detected() const {return resaccval;}
00416
00420 virtual void reset();
00421
00425 virtual void stop() {go=false;}
00426
00431 virtual void start() {go=true;}
00433
00436
00440 void setParameters(double acc=0.1, int reps=3)
00441 {accuracy=acc; repeats=detreps=reps;}
00443 };
00444
00445 NAMESPACE_END
00446
00447
00448 #endif
00449