chistogram.h

00001 //==========================================================================
00002 //  CHISTOGRAM.H - part of
00003 //
00004 //                     OMNeT++/OMNEST
00005 //            Discrete System Simulation in C++
00006 //
00007 //
00008 //  Declaration of the following classes:
00009 //    cHistogramBase        : common base class for histogram classes
00010 //      cHistogram          : equi-distant histogram
00011 //        cLongHistogram    : long int distribution
00012 //        cDoubleHistogram  : double distribution
00013 //
00014 //==========================================================================
00015 
00016 /*--------------------------------------------------------------*
00017   Copyright (C) 1992-2008 Andras Varga
00018   Copyright (C) 2006-2008 OpenSim Ltd.
00019 
00020   This file is distributed WITHOUT ANY WARRANTY. See the file
00021   `license' for details on this and other legal matters.
00022 *--------------------------------------------------------------*/
00023 
00024 #ifndef __CHISTOGRAM_H
00025 #define __CHISTOGRAM_H
00026 
00027 #include "cdensityestbase.h"
00028 
00029 NAMESPACE_BEGIN
00030 
00031 
00038 class SIM_API cHistogramBase : public cDensityEstBase
00039 {
00040   protected:
00041     int num_cells;        // nr. of categories
00042     unsigned *cellv;      // array of counters
00043 
00044   private:
00045     void copy(const cHistogramBase& other);
00046 
00047   protected:
00048     // abstract method in cDensityEstBase
00049     virtual void doMergeCellValues(const cDensityEstBase *other);
00050 
00051   public:
00054 
00058     cHistogramBase(const cHistogramBase& r) : cDensityEstBase(r) {cellv=NULL;copy(r);}
00059 
00063     cHistogramBase(const char *name, int numcells);
00064 
00068     virtual ~cHistogramBase();
00069 
00073     cHistogramBase& operator=(const cHistogramBase& res);
00075 
00078 
00079     /* No dup() because this is an abstract class. */
00080 
00086     virtual void parsimPack(cCommBuffer *buffer);
00087 
00093     virtual void parsimUnpack(cCommBuffer *buffer);
00095 
00098 
00102     virtual void clearResult();
00103 
00108     virtual void transform();
00109 
00113     virtual int getNumCells() const;
00114 
00118     virtual void saveToFile(FILE *) const;
00119 
00123     virtual void loadFromFile(FILE *);
00125 
00132     virtual void setNumCells(int numcells);
00134 };
00135 
00136 
00192 class SIM_API cHistogram : public cHistogramBase
00193 {
00194   public:
00195     enum Mode {MODE_AUTO, MODE_INTEGERS, MODE_DOUBLES};
00196 
00197   protected:
00198     Mode mode;
00199     double cellsize;  // cell/category sizes; <=0 if unset
00200 
00201   private:
00202     void copy(const cHistogram& other);
00203 
00204   protected:
00205     virtual void setupRangeInteger();
00206     virtual void setupRangeDouble();
00207     virtual void getAttributesToRecord(opp_string_map& attributes);
00208 
00209   public:
00212 
00216     cHistogram(const cHistogram& r) : cHistogramBase(r) {copy(r);}
00217 
00221     explicit cHistogram(const char *name=NULL, int numcells=-1, Mode mode=MODE_AUTO);
00222 
00226     cHistogram& operator=(const cHistogram& res);
00228 
00231 
00232     /* No dup() because this is an abstract class. */
00233 
00239     virtual void parsimPack(cCommBuffer *buffer);
00240 
00246     virtual void parsimUnpack(cCommBuffer *buffer);
00248 
00249   protected:
00254     virtual void collectTransformed(double value);
00255 
00260     virtual void setupRange();
00261 
00262   public:
00265 
00269     virtual double getBasepoint(int k) const;
00270 
00274     virtual double getCellValue(int k) const;
00275 
00279     virtual double getPDF(double x) const;
00280 
00284     virtual double getCDF(double x) const;
00285 
00293     virtual double random() const;
00294 
00298     virtual void saveToFile(FILE *) const;
00299 
00303     virtual void loadFromFile(FILE *);
00305 
00312     virtual void setMode(Mode mode);
00313 
00318     virtual Mode getMode() const {return mode;}
00319 
00324     virtual void setCellSize(double d);
00325 
00330     virtual double getCellSize() const {return cellsize;}
00332 
00333 };
00334 
00335 
00342 class SIM_API cLongHistogram : public cHistogram
00343 {
00344   private:
00345     void copy(const cLongHistogram& other) {}
00346 
00347   public:
00353     cLongHistogram(const cLongHistogram& r) : cHistogram(r) {copy(r);}
00354 
00358     explicit cLongHistogram(const char *name=NULL, int numcells=-1) :
00359         cHistogram(name, numcells, MODE_INTEGERS) {}
00360 
00364     virtual ~cLongHistogram() {}
00365 
00369     cLongHistogram& operator=(const cLongHistogram& other);
00371 
00374 
00379     virtual cLongHistogram *dup() const  {return new cLongHistogram(*this);}
00381 
00382   public:
00385 
00390     virtual void collect(double value) {cHistogram::collect(floor(value));}
00391 
00395     virtual void collect(SimTime value) {collect(value.dbl());}
00396 };
00397 
00398 
00405 class SIM_API cDoubleHistogram : public cHistogram
00406 {
00407   private:
00408     void copy(const cDoubleHistogram& other) {}
00409 
00410   public:
00413 
00417     cDoubleHistogram(const cDoubleHistogram& r) : cHistogram(r) {copy(r);}
00418 
00422     explicit cDoubleHistogram(const char *name=NULL, int numcells=-1) :
00423         cHistogram(name, numcells, MODE_DOUBLES) {}
00424 
00428     virtual ~cDoubleHistogram() {}
00429 
00433     cDoubleHistogram& operator=(const cDoubleHistogram& other);
00435 
00438 
00443     virtual cDoubleHistogram *dup() const  {return new cDoubleHistogram(*this);}
00445 };
00446 
00447 NAMESPACE_END
00448 
00449 
00450 #endif
00451 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3