Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

cdetect.h

00001 //=========================================================================
00002 //
00003 //  CDETECT.H - part of
00004 //                          OMNeT++
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-2003 Andras Varga
00021 
00022   This file is distributed WITHOUT ANY WARRANTY. See the file
00023   `license' for details on this and other legal matters.
00024 *--------------------------------------------------------------*/
00025 
00026 #ifndef __CDETECT_H
00027 #define __CDETECT_H
00028 
00029 #include "cobject.h"
00030 #include "cstat.h"
00031 
00032 //=== classes declared here:
00033 class cTransientDetection;
00034 class cAccuracyDetection;
00035 class cTDExpandingWindows;
00036 class cADByStddev;
00037 
00038 //=== class mentioned here:
00039 class cStatistic;
00040 
00045 typedef void (*PostTDFunc)(cTransientDetection *, void *);
00046 
00051 typedef void (*PostADFunc)(cAccuracyDetection *, void *);
00052 
00053 //==========================================================================
00054 
00060 class SIM_API cTransientDetection : public cObject
00061 {
00062   private:
00063     cStatistic *back;    // ptr to cStatistic that uses this object
00064 
00065   public:
00068 
00072     cTransientDetection(const cTransientDetection& r) : cObject() {setName(r.name());operator=(r);}
00073 
00077     explicit cTransientDetection(const char *name=NULL) : cObject(name) {}
00078 
00082     virtual ~cTransientDetection()  {}
00083 
00087     cTransientDetection& operator=(const cTransientDetection&)  {copyNotSupported();return *this;}
00089 
00092 
00093     /* No dup() because this is an abstract class. */
00094 
00100     virtual int netPack();
00101 
00107     virtual int netUnpack();
00109 
00112 
00116     virtual void collect(double val) = 0;
00117 
00121     virtual bool detected() const = 0;
00122 
00126     virtual void reset() = 0;
00127 
00132     virtual void stop() = 0;
00133 
00138     virtual void start() = 0;
00140 
00143 
00148     virtual void setHostObject(cStatistic *ptr)  {back = ptr;}
00149 
00153     virtual cStatistic *hostObject() const  {return back;}
00155 };
00156 
00157 //==========================================================================
00158 
00164 class SIM_API cAccuracyDetection : public cObject
00165 {
00166   private:
00167     cStatistic *back;              // ptr to cStatistic that uses this object
00168 
00169   public:
00172 
00176     cAccuracyDetection(const cAccuracyDetection& r) : cObject() {setName(r.name());operator=(r);}
00177 
00181     explicit cAccuracyDetection(const char *name=NULL) : cObject(name)  {}
00182 
00186     virtual ~cAccuracyDetection()  {}
00187 
00191     cAccuracyDetection& operator=(const cAccuracyDetection&)  {copyNotSupported();return *this;}
00193 
00196 
00197     /* No dup() because this is an abstract class. */
00198 
00204     virtual int netPack();
00205 
00211     virtual int netUnpack();
00213 
00216 
00220     virtual void collect(double val) = 0;
00221 
00225     virtual bool detected() const = 0;
00226 
00230     virtual void reset() = 0;
00231 
00236     virtual void stop() = 0;
00237 
00242     virtual void start() = 0;
00244 
00247 
00252     virtual void setHostObject(cStatistic *ptr)  {back = ptr;}
00253 
00257     virtual cStatistic *hostObject() const  {return back;}
00259 };
00260 
00261 //===========================================================================
00262 
00270 class SIM_API cTDExpandingWindows : public cTransientDetection
00271 {
00272   private:
00273     bool go;                  // collect & detect
00274     bool transval;            // value of the last detection
00275     double accuracy;          // accuracy for detection
00276     int minwinds;             // minimum windows size
00277     double windexp;           // window expansion factor
00278     int repeats;              // repetitions necessary for detection
00279     int detreps;              // number of detections in a row
00280     int size;                 // number of collected values
00281     struct xy {double x; double y; xy *next;};
00282     xy *func;                 // structure of collected values
00283     PostTDFunc pdf;           // function to call after detection
00284     void *pdfdata;            // data for PostDetectFunct
00285 
00286   private:
00287     // internal: computes new value of transval
00288     void detectTransient();
00289 
00290   public:
00293 
00297     cTDExpandingWindows(const cTDExpandingWindows& r);
00298 
00302     explicit cTDExpandingWindows(const char *name=NULL,
00303                         int reps=3, int minw=4, double wind=1.3, double acc=0.3,
00304                         PostTDFunc f=NULL,void *p=NULL);
00305 
00309     virtual ~cTDExpandingWindows();
00310 
00315     cTDExpandingWindows& operator=(const cTDExpandingWindows& res);
00317 
00320 
00325     virtual cObject *dup() const  {return new cTDExpandingWindows(*this);}
00327 
00330 
00334     virtual void collect(double val);
00335 
00339     virtual bool detected() const {return transval;}
00340 
00344     virtual void reset();
00345 
00349     virtual void stop()      {go = false;}
00350 
00355     virtual void start()     {go = true;}
00357 
00360 
00365     // FIXME: why not in base class?
00366     void setPostDetectFunction(PostTDFunc f, void *p) {pdf = f; pdfdata = p;}
00367 
00371     void setParameters(int reps=3, int minw=4,
00372                        double wind=1.3, double acc=0.3);
00374 };
00375 
00376 
00377 //===========================================================================
00378 
00386 class SIM_API cADByStddev : public cAccuracyDetection
00387 {
00388   private:
00389     bool go;                    // start collecting if true
00390     bool resaccval;             // value of the last detection
00391     double accuracy;            // minimum needed for detection
00392     long int sctr;              // counter
00393     double ssum,sqrsum;         // sum, square sum;
00394     int repeats, detreps;       // repetitions necessary for detection
00395     PostADFunc pdf;             // function to call after detection
00396     void *pdfdata;              // data for PostDetectFunc
00397 
00398   private:
00399     // internal: compute new value of transval
00400     void detectAccuracy();
00401 
00402     // internal: compute the standard deviation
00403     double stddev();
00404 
00405   public:
00408 
00412     cADByStddev(const cADByStddev& r);
00413 
00417     explicit cADByStddev(const char *name=NULL,
00418                          double acc=0.01, int reps=3,
00419                          PostADFunc f=NULL, void *p=NULL);
00420 
00424     virtual ~cADByStddev()  {}
00425 
00430     cADByStddev& operator=(const cADByStddev& res);
00432 
00435 
00440     virtual cObject *dup() const  {return new cADByStddev(*this);}
00442 
00445 
00449     virtual void collect(double val);
00450 
00454     virtual bool detected() const {return resaccval;}
00455 
00459     virtual void reset();
00460 
00464     virtual void stop()   {go=false;}
00465 
00470     virtual void start()  {go=true;}
00472 
00475 
00480     // FIXME: why not in base class?
00481     void setPostDetectFunction(PostADFunc f, void *p) {pdf=f; pdfdata=p;}
00482 
00486     void setParameters(double acc=0.1, int reps=3)
00487         {accuracy=acc; repeats=detreps=reps;}
00489 };
00490 
00491 #endif
00492 

Generated at Mon Jun 16 23:37:31 2003 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001