00001 //========================================================================== 00002 // 00003 // CHIST.H - header for 00004 // OMNeT++ 00005 // Discrete System Simulation in C++ 00006 // 00007 // 00008 // Declaration of the following classes: 00009 // cHistogramBase : common base class for histogram classes 00010 // cEqdHistogramBase : Equi-distant histograms 00011 // cLongHistogram : long int distribution 00012 // cDoubleHistogram : double distribution 00013 // 00014 //========================================================================== 00015 00016 /*--------------------------------------------------------------* 00017 Copyright (C) 1992-2003 Andras Varga 00018 00019 This file is distributed WITHOUT ANY WARRANTY. See the file 00020 `license' for details on this and other legal matters. 00021 *--------------------------------------------------------------*/ 00022 00023 #ifndef __CHIST_H 00024 #define __CHIST_H 00025 00026 #include "cdensity.h" 00027 00028 //========================================================================== 00029 00036 class SIM_API cHistogramBase : public cDensityEstBase 00037 { 00038 protected: 00039 int num_cells; // nr. of categories 00040 unsigned *cellv; // array of counters 00041 00042 public: 00045 00049 cHistogramBase(const cHistogramBase& r) : cDensityEstBase(r) 00050 {setName(r.name());cellv=NULL;operator=(r);} 00051 00055 cHistogramBase(const char *name, int numcells); 00056 00060 virtual ~cHistogramBase(); 00061 00065 cHistogramBase& operator=(const cHistogramBase& res); 00067 00070 00071 /* No dup() because this is an abstract class. */ 00072 00078 virtual int netPack(); 00079 00085 virtual int netUnpack(); 00087 00090 00094 virtual void clearResult(); 00095 00100 virtual void transform(); 00101 00105 virtual int cells() const; 00106 00110 virtual void saveToFile(FILE *) const; //--LG 00111 00115 virtual void loadFromFile(FILE *); //--LG 00117 00120 00125 virtual void setNumCells(int numcells); 00127 }; 00128 00129 //========================================================================== 00130 00136 class SIM_API cEqdHistogramBase : public cHistogramBase //--LG 00137 { 00138 protected: 00139 double cellsize; // cell/category sizes 00140 00141 public: 00144 00148 cEqdHistogramBase(const cEqdHistogramBase& r) : cHistogramBase(r) 00149 {setName(r.name());operator=(r);} 00150 00154 explicit cEqdHistogramBase(const char *name=NULL, int numcells=10); 00155 00159 cEqdHistogramBase& operator=(const cEqdHistogramBase& res); 00161 00164 00165 /* No dup() because this is an abstract class. */ 00166 00172 virtual int netPack(); 00173 00179 virtual int netUnpack(); 00181 00182 protected: 00187 virtual void collectTransformed(double val); 00188 00193 virtual void setupRange(); 00194 00195 public: 00198 00202 virtual double basepoint(int k) const; 00203 00207 virtual double cell(int k) const; 00208 00212 virtual double pdf(double x) const; // --LG 00213 00217 virtual double cdf(double x) const; // --LG 00218 00222 virtual void saveToFile(FILE *) const; //--LG 00223 00227 virtual void loadFromFile(FILE *); //--LG 00229 }; 00230 00231 //========================================================================== 00232 00252 class SIM_API cLongHistogram : public cEqdHistogramBase 00253 { 00254 public: 00257 00261 cLongHistogram(const cLongHistogram& r) : cEqdHistogramBase(r) 00262 {setName(r.name());operator=(r);} 00263 00267 explicit cLongHistogram(const char *name=NULL, int numcells=10); 00268 00272 virtual ~cLongHistogram(); 00273 00277 cLongHistogram& operator=(const cLongHistogram&) {copyNotSupported();return *this;} 00279 00282 00287 virtual cObject *dup() const {return new cLongHistogram(*this);} 00288 00294 virtual int netPack(); 00295 00301 virtual int netUnpack(); 00303 00304 protected: 00309 virtual void setupRange(); 00310 00311 public: 00314 00318 virtual void collect(double val); 00319 00326 virtual double random() const; 00328 }; 00329 00330 //========================================================================== 00331 00338 class SIM_API cDoubleHistogram : public cEqdHistogramBase 00339 { 00340 public: 00343 00347 cDoubleHistogram(const cDoubleHistogram& r) : cEqdHistogramBase(r) 00348 {setName(r.name());operator=(r);} 00349 00353 explicit cDoubleHistogram(const char *name=NULL, int numcells=10); 00354 00358 virtual ~cDoubleHistogram(); 00359 00363 cDoubleHistogram& operator=(const cDoubleHistogram&) {copyNotSupported();return *this;} 00365 00368 00373 virtual cObject *dup() const {return new cDoubleHistogram(*this);} 00374 00380 virtual int netPack(); 00381 00387 virtual int netUnpack(); 00389 00392 00399 virtual double random() const; 00401 }; 00402 00403 #endif 00404