cdetect.h

00001 //=========================================================================
00002 //  CDETECT.H - part of
00003 //
00004 //                  OMNeT++/OMNEST
00005 //           Discrete System Simulation in C++
00006 //
00007 //         File designed and written by the Hollandiaba Team
00008 //
00009 //   Class declarations:
00010 //     cTransientDetection :  virtual base class for transient detection
00011 //     cAccuracyDetection  :  virtual base class for result accuracy detection
00012 //
00013 //     cTDExpandingWindows :  an algorithm for transient detection
00014 //     cADByStddev         :  an algorithm for result accuracy detection
00015 //
00016 //   Bugfixes: Andras Varga, Oct.1996
00017 //=========================================================================
00018 
00019 /*--------------------------------------------------------------*
00020   Copyright (C) 1992-2008 Andras Varga
00021   Copyright (C) 2006-2008 OpenSim Ltd.
00022 
00023   This file is distributed WITHOUT ANY WARRANTY. See the file
00024   `license' for details on this and other legal matters.
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;    // ptr to cStatistic that uses this object
00060     PostTDFunc pdf;      // function to call after detection
00061     void *pdfdata;       // data for PostDetectFunct
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     /* Note: no dup() because this is an abstract class. */
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;           // ptr to cStatistic that uses this object
00149     PostADFunc pdf;             // function to call after detection
00150     void *pdfdata;              // data for PostDetectFunc
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     /* No dup() because this is an abstract class. */
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;                  // collect & detect
00243     bool transval;            // value of the last detection
00244     double accuracy;          // accuracy for detection
00245     int minwinds;             // minimum windows size
00246     double windexp;           // window expansion factor
00247     int repeats;              // repetitions necessary for detection
00248     int detreps;              // number of detections in a row
00249     int size;                 // number of collected values
00250     struct xy {double x; double y; xy *next;};
00251     xy *func;                 // structure of collected values
00252 
00253   private:
00254     // internal: computes new value of transval
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;                    // start collecting if true
00351     bool resaccval;             // value of the last detection
00352     double accuracy;            // minimum needed for detection
00353     long int sctr;              // counter
00354     double ssum,sqrsum;         // sum, square sum;
00355     int repeats, detreps;       // repetitions necessary for detection
00356 
00357   private:
00358     void copy(const cADByStddev& other);
00359 
00360     // internal: compute new value of transval
00361     void detectAccuracy();
00362 
00363     // internal: compute the standard deviation
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 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3