- Main Page
- Modules
- Classes
- Files
- Directories
- Related Pages

# 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-2005 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   protected:
    00063     cStatistic *back;    // ptr to cStatistic that uses this object
    00064     PostTDFunc pdf;      // function to call after detection
    00065     void *pdfdata;       // data for PostDetectFunct
    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
    00095     /* No dup() because this is an abstract class. */
    00097
    00100
    00104     virtual void collect(double val) = 0;
    00105
    00109     virtual bool detected() const = 0;
    00110
    00114     virtual void reset() = 0;
    00115
    00120     virtual void stop() = 0;
    00121
    00126     virtual void start() = 0;
    00127
    00132     void setPostDetectFunction(PostTDFunc f, void *p) {pdf = f; pdfdata = p;}
    00134
    00137
    00142     virtual void setHostObject(cStatistic *ptr)  {back = ptr;}
    00143
    00147     virtual cStatistic *hostObject() const  {return back;}
    00149 };
    00150
    00151 //==========================================================================
    00152
    00158 class SIM_API cAccuracyDetection : public cObject
    00159 {
    00160   protected:
    00161     cStatistic *back;           // ptr to cStatistic that uses this object
    00162     PostADFunc pdf;             // function to call after detection
    00163     void *pdfdata;              // data for PostDetectFunc
    00164
    00165   public:
    00168
    00172     cAccuracyDetection(const cAccuracyDetection& r) : cObject() {setName(r.name());operator=(r);}
    00173
    00177     explicit cAccuracyDetection(const char *name=NULL) : cObject(name)  {}
    00178
    00182     virtual ~cAccuracyDetection()  {}
    00183
    00187     cAccuracyDetection& operator=(const cAccuracyDetection&)  {copyNotSupported();return *this;}
    00189
    00192
    00193     /* No dup() because this is an abstract class. */
    00195
    00198
    00202     virtual void collect(double val) = 0;
    00203
    00207     virtual bool detected() const = 0;
    00208
    00212     virtual void reset() = 0;
    00213
    00218     virtual void stop() = 0;
    00219
    00224     virtual void start() = 0;
    00225
    00230     void setPostDetectFunction(PostADFunc f, void *p) {pdf=f; pdfdata=p;}
    00232
    00235
    00240     virtual void setHostObject(cStatistic *ptr)  {back = ptr;}
    00241
    00245     virtual cStatistic *hostObject() const  {return back;}
    00247 };
    00248
    00249 //===========================================================================
    00250
    00258 class SIM_API cTDExpandingWindows : public cTransientDetection
    00259 {
    00260   private:
    00261     bool go;                  // collect & detect
    00262     bool transval;            // value of the last detection
    00263     double accuracy;          // accuracy for detection
    00264     int minwinds;             // minimum windows size
    00265     double windexp;           // window expansion factor
    00266     int repeats;              // repetitions necessary for detection
    00267     int detreps;              // number of detections in a row
    00268     int size;                 // number of collected values
    00269     struct xy {double x; double y; xy *next;};
    00270     xy *func;                 // structure of collected values
    00271
    00272   private:
    00273     // internal: computes new value of transval
    00274     void detectTransient();
    00275
    00276   public:
    00279
    00283     cTDExpandingWindows(const cTDExpandingWindows& r);
    00284
    00288     explicit cTDExpandingWindows(const char *name=NULL,
    00289                         int reps=3, int minw=4, double wind=1.3, double acc=0.3,
    00290                         PostTDFunc f=NULL,void *p=NULL);
    00291
    00295     virtual ~cTDExpandingWindows();
    00296
    00301     cTDExpandingWindows& operator=(const cTDExpandingWindows& res);
    00303
    00306
    00311     virtual cPolymorphic *dup() const  {return new cTDExpandingWindows(*this);}
    00313
    00316
    00320     virtual void collect(double val);
    00321
    00325     virtual bool detected() const {return transval;}
    00326
    00330     virtual void reset();
    00331
    00335     virtual void stop()      {go = false;}
    00336
    00341     virtual void start()     {go = true;}
    00343
    00349     void setParameters(int reps=3, int minw=4,
    00350                        double wind=1.3, double acc=0.3);
    00352 };
    00353
    00354
    00355 //===========================================================================
    00356
    00364 class SIM_API cADByStddev : public cAccuracyDetection
    00365 {
    00366   private:
    00367     bool go;                    // start collecting if true
    00368     bool resaccval;             // value of the last detection
    00369     double accuracy;            // minimum needed for detection
    00370     long int sctr;              // counter
    00371     double ssum,sqrsum;         // sum, square sum;
    00372     int repeats, detreps;       // repetitions necessary for detection
    00373
    00374   private:
    00375     // internal: compute new value of transval
    00376     void detectAccuracy();
    00377
    00378     // internal: compute the standard deviation
    00379     double stddev();
    00380
    00381   public:
    00384
    00388     cADByStddev(const cADByStddev& r);
    00389
    00393     explicit cADByStddev(const char *name=NULL,
    00394                          double acc=0.01, int reps=3,
    00395                          PostADFunc f=NULL, void *p=NULL);
    00396
    00400     virtual ~cADByStddev()  {}
    00401
    00406     cADByStddev& operator=(const cADByStddev& res);
    00408
    00411
    00416     virtual cPolymorphic *dup() const  {return new cADByStddev(*this);}
    00418
    00421
    00425     virtual void collect(double val);
    00426
    00430     virtual bool detected() const {return resaccval;}
    00431
    00435     virtual void reset();
    00436
    00440     virtual void stop()   {go=false;}
    00441
    00446     virtual void start()  {go=true;}
    00448
    00451
    00455     void setParameters(double acc=0.1, int reps=3)
    00456         {accuracy=acc; repeats=detreps=reps;}
    00458 };
    00459
    00460 #endif
    00461