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-2001 Andras Varga
00021   Technical University of Budapest, Dept. of Telecommunications,
00022   Stoczek u.2, H-1111 Budapest, Hungary.
00023 
00024   This file is distributed WITHOUT ANY WARRANTY. See the file
00025   `license' for details on this and other legal matters.
00026 *--------------------------------------------------------------*/
00027 
00028 #ifndef __CDETECT_H
00029 #define __CDETECT_H
00030 
00031 #include "cobject.h"
00032 #include "cstat.h"
00033 
00034 //=== classes declared here:
00035 class cTransientDetection;
00036 class cAccuracyDetection;
00037 class cTDExpandingWindows;
00038 class cADByStddev;
00039 
00040 //=== class mentioned here:
00041 class cStatistic;
00042 
00047 typedef void (*PostTDFunc)(cTransientDetection *, void *);
00048 
00053 typedef void (*PostADFunc)(cAccuracyDetection *, void *);
00054 
00055 //==========================================================================
00056 
00062 class SIM_API cTransientDetection : public cObject
00063 {
00064   private:
00065     cStatistic *back;    // ptr to cStatistic that uses this object
00066 
00067   public:
00070 
00074     cTransientDetection(const cTransientDetection& r) : cObject() {setName(r.name());operator=(r);}
00075 
00079     explicit cTransientDetection(const char *name=NULL) : cObject(name) {}
00080 
00084     virtual ~cTransientDetection()  {}
00085 
00089     cTransientDetection& operator=(const cTransientDetection&)  {copyNotSupported();return *this;}
00091 
00094 
00098     virtual const char *className() const  {return "cTransientDetection";}
00099 
00100     /* No dup() because this is an abstract class. */
00101 
00107     virtual int netPack();
00108 
00114     virtual int netUnpack();
00116 
00119 
00123     virtual void collect(double val) = 0;
00124 
00128     virtual bool detected() const = 0;
00129 
00133     virtual void reset() = 0;
00134 
00139     virtual void stop() = 0;
00140 
00145     virtual void start() = 0;
00147 
00150 
00155     virtual void setHostObject(cStatistic *ptr)  {back = ptr;}
00156 
00160     virtual cStatistic *hostObject() const  {return back;}
00162 };
00163 
00164 //==========================================================================
00165 
00171 class SIM_API cAccuracyDetection : public cObject
00172 {
00173   private:
00174     cStatistic *back;              // ptr to cStatistic that uses this object
00175 
00176   public:
00179 
00183     cAccuracyDetection(const cAccuracyDetection& r) : cObject() {setName(r.name());operator=(r);}
00184 
00188     explicit cAccuracyDetection(const char *name=NULL) : cObject(name)  {}
00189 
00193     virtual ~cAccuracyDetection()  {}
00194 
00198     cAccuracyDetection& operator=(const cAccuracyDetection&)  {copyNotSupported();return *this;}
00200 
00203 
00207     virtual const char *className() const {return "cAccuracyDetection";}
00208 
00209     /* No dup() because this is an abstract class. */
00210 
00216     virtual int netPack();
00217 
00223     virtual int netUnpack();
00225 
00228 
00232     virtual void collect(double val) = 0;
00233 
00237     virtual bool detected() const = 0;
00238 
00242     virtual void reset() = 0;
00243 
00248     virtual void stop() = 0;
00249 
00254     virtual void start() = 0;
00256 
00259 
00264     virtual void setHostObject(cStatistic *ptr)  {back = ptr;}
00265 
00269     virtual cStatistic *hostObject() const  {return back;}
00271 };
00272 
00273 //===========================================================================
00274 
00282 class SIM_API cTDExpandingWindows : public cTransientDetection
00283 {
00284   private:
00285     bool go;                  // collect & detect
00286     bool transval;            // value of the last detection
00287     double accuracy;          // accuracy for detection
00288     int minwinds;             // minimum windows size
00289     double windexp;           // window expansion factor
00290     int repeats;              // repetitions necessary for detection
00291     int detreps;              // number of detections in a row
00292     int size;                 // number of collected values
00293     struct xy {double x; double y; xy *next;};
00294     xy *func;                 // structure of collected values
00295     PostTDFunc pdf;           // function to call after detection
00296     void *pdfdata;            // data for PostDetectFunct
00297 
00298   private:
00299     // internal: computes new value of transval
00300     void detectTransient();
00301 
00302   public:
00305 
00309     cTDExpandingWindows(const cTDExpandingWindows& r);
00310 
00314     explicit cTDExpandingWindows(const char *name=NULL,
00315                         int reps=3, int minw=4, double wind=1.3, double acc=0.3,
00316                         PostTDFunc f=NULL,void *p=NULL);
00317 
00321     virtual ~cTDExpandingWindows();
00322 
00327     cTDExpandingWindows& operator=(const cTDExpandingWindows& res);
00329 
00332 
00336     virtual const char *className() const {return "cTDExpandingWindows";}
00337 
00342     virtual cObject *dup() const  {return new cTDExpandingWindows(*this);}
00344 
00347 
00351     virtual void collect(double val);
00352 
00356     virtual bool detected() const {return transval;}
00357 
00361     virtual void reset();
00362 
00366     virtual void stop()      {go = false;}
00367 
00372     virtual void start()     {go = true;}
00374 
00377 
00382     // FIXME: why not in base class?
00383     void setPostDetectFunction(PostTDFunc f, void *p) {pdf = f; pdfdata = p;}
00384 
00388     void setParameters(int reps=3, int minw=4,
00389                        double wind=1.3, double acc=0.3);
00391 };
00392 
00393 
00394 //===========================================================================
00395 
00403 class SIM_API cADByStddev : public cAccuracyDetection
00404 {
00405   private:
00406     bool go;                    // start collecting if true
00407     bool resaccval;             // value of the last detection
00408     double accuracy;            // minimum needed for detection
00409     long int sctr;              // counter
00410     double ssum,sqrsum;         // sum, square sum;
00411     int repeats, detreps;       // repetitions necessary for detection
00412     PostADFunc pdf;             // function to call after detection
00413     void *pdfdata;              // data for PostDetectFunc
00414 
00415   private:
00416     // internal: compute new value of transval
00417     void detectAccuracy();
00418 
00419     // internal: compute the standard deviation
00420     double stddev();
00421 
00422   public:
00425 
00429     cADByStddev(const cADByStddev& r);
00430 
00434     explicit cADByStddev(const char *name=NULL,
00435                          double acc=0.01, int reps=3,
00436                          PostADFunc f=NULL, void *p=NULL);
00437 
00441     virtual ~cADByStddev()  {}
00442 
00447     cADByStddev& operator=(const cADByStddev& res);
00449 
00452 
00456     virtual const char *className() const {return "cADByStddev";}
00457 
00462     virtual cObject *dup() const  {return new cADByStddev(*this);}
00464 
00467 
00471     virtual void collect(double val);
00472 
00476     virtual bool detected() const {return resaccval;}
00477 
00481     virtual void reset();
00482 
00486     virtual void stop()   {go=false;}
00487 
00492     virtual void start()  {go=true;}
00494 
00497 
00502     // FIXME: why not in base class?
00503     void setPostDetectFunction(PostADFunc f, void *p) {pdf=f; pdfdata=p;}
00504 
00508     void setParameters(double acc=0.1, int reps=3)
00509         {accuracy=acc; repeats=detreps=reps;}
00511 };
00512 
00513 #endif
00514 

Generated at Sat May 4 15:45:48 2002 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001