OMNeT++ API 6.1
Discrete Event Simulation Library
chistogram.h
1 //==========================================================================
2 // CHISTOGRAM.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CHISTOGRAM_H
17 #define __OMNETPP_CHISTOGRAM_H
18 
19 #include <climits>
20 #include "cabstracthistogram.h"
21 
22 namespace omnetpp {
23 
24 class cIHistogramStrategy;
25 class cAutoRangeHistogramStrategy;
26 
88 class SIM_API cHistogram : public cAbstractHistogram
89 {
90  public:
95  enum Mode {MODE_AUTO, MODE_INTEGERS, MODE_REALS, MODE_DOUBLES /*deprecated*/ = MODE_REALS};
96 
97  protected:
98  cIHistogramStrategy *strategy = nullptr; // owned
99 
100  std::vector<double> binEdges;
101  std::vector<double> binValues; // one less than bin edges
102  double finiteUnderflowSumWeights = 0, finiteOverflowSumWeights = 0;
103  double posInfSumWeights = 0, negInfSumWeights = 0;
104 
105  public:
106  // INTERNAL, only for cIHistogramSetupStrategy implementations.
107  // Directly collects the value into the existing bins, without delegating to the strategy object
108  virtual void collectIntoHistogram(double value, double weight=1);
109  void dump() const; // for debugging
110  void assertSanity();
111 
112  private:
113  void copy(const cHistogram& other);
114  cAutoRangeHistogramStrategy *getOrCreateAutoRangeStrategy() const;
115 
116  public:
119 
125  explicit cHistogram(const char *name=nullptr, bool weighted=false);
126 
131  explicit cHistogram(const char *name, int numBinsHint, bool weighted=false);
132 
137  explicit cHistogram(const char *name, cIHistogramStrategy *strategy, bool weighted=false);
138 
142  cHistogram(const cHistogram& other): cAbstractHistogram(other) {copy(other);}
143 
148  cHistogram& operator=(const cHistogram& other);
149 
153  virtual ~cHistogram();
155 
158 
163  virtual cHistogram *dup() const override {return new cHistogram(*this);}
164 
170  virtual void parsimPack(cCommBuffer *buffer) const override;
171 
177  virtual void parsimUnpack(cCommBuffer *buffer) override;
179 
182 
187  virtual void collect(double value) override;
189 
196  virtual void collectWeighted(double value, double weight) override;
198 
202  virtual void clear() override;
203 
207  virtual void saveToFile(FILE *f) const override;
208 
212  virtual void loadFromFile(FILE *f) override;
213 
217  virtual void merge(const cStatistic *other) override;
219 
222 
227  void setStrategy(cIHistogramStrategy *strategy);
228 
232  cIHistogramStrategy *getStrategy() const {return strategy;}
233 
238  virtual bool binsAlreadySetUp() const override;
239 
245  virtual void setUpBins() override;
246 
252  virtual void setBinEdges(const std::vector<double>& edges);
253 
260  virtual void createUniformBins(double lo, double hi, double step);
261 
268  virtual void prependBins(const std::vector<double>& edges);
269 
276  virtual void appendBins(const std::vector<double>& edges);
277 
287  virtual void extendBinsTo(double value, double step, int maxNumBins=INT_MAX); // TODO: remove default value for maxNumBins
288 
295  virtual void mergeBins(int groupSize);
296 
301  virtual std::vector<double> getBinEdges() const override {return binEdges;}
302 
307  virtual std::vector<double> getBinValues() const override {return binValues;}
308 
312  virtual int getNumBins() const override {return binValues.size();}
313 
317  virtual double getBinEdge(int k) const override {return binEdges.at(k);}
318 
323  virtual double getBinValue(int k) const override {return binValues.at(k);}
324 
328  virtual double getUnderflowSumWeights() const override {return finiteUnderflowSumWeights + negInfSumWeights;}
329 
333  virtual double getOverflowSumWeights() const override {return finiteOverflowSumWeights + posInfSumWeights;}
334 
340  virtual int64_t getNumUnderflows() const override;
341 
347  virtual int64_t getNumOverflows() const override;
348 
354  virtual int64_t getNumNegInfs() const override;
355 
361  virtual int64_t getNumPosInfs() const override;
362 
366  virtual double getNegInfSumWeights() const override {return negInfSumWeights;}
367 
371  virtual double getPosInfSumWeights() const override {return posInfSumWeights;}
373 
382  virtual void setMode(Mode mode);
383 
390  virtual void setRange(double lower, double upper);
391 
397  virtual void setNumPrecollectedValues(int numPrecollect);
398 
405  virtual void setRangeExtensionFactor(double rangeExtensionFactor);
406 
414  virtual void setAutoExtend(bool autoExtend);
415 
421  virtual void setNumBinsHint(int numCells);
422 
428  virtual void setBinSizeHint(double d);
430 };
431 
432 } // namespace omnetpp
433 
434 #endif
omnetpp::cHistogram::getStrategy
cIHistogramStrategy * getStrategy() const
Definition: chistogram.h:232
omnetpp::cHistogram::getNumBins
virtual int getNumBins() const override
Definition: chistogram.h:312
omnetpp::cHistogram::getBinValue
virtual double getBinValue(int k) const override
Definition: chistogram.h:323
omnetpp::cHistogram::getBinEdges
virtual std::vector< double > getBinEdges() const override
Definition: chistogram.h:301
omnetpp::cHistogram::getBinEdge
virtual double getBinEdge(int k) const override
Definition: chistogram.h:317
omnetpp::cStdDev::collect
virtual void collect(double value) override
omnetpp::cHistogram::getBinValues
virtual std::vector< double > getBinValues() const override
Definition: chistogram.h:307
omnetpp::cHistogram::cHistogram
cHistogram(const cHistogram &other)
Definition: chistogram.h:142
omnetpp::cHistogram::getUnderflowSumWeights
virtual double getUnderflowSumWeights() const override
Definition: chistogram.h:328
omnetpp::cHistogram::getPosInfSumWeights
virtual double getPosInfSumWeights() const override
Definition: chistogram.h:371
omnetpp::cAutoRangeHistogramStrategy
A generic, very configurable histogram strategy that is meant to provide a good quality histogram for...
Definition: chistogramstrategy.h:304
omnetpp::cHistogram::getNegInfSumWeights
virtual double getNegInfSumWeights() const override
Definition: chistogram.h:366
omnetpp::cHistogram
Generic histogram class, capable of representing both unweighted and weighted distributions....
Definition: chistogram.h:88
omnetpp::cHistogram::dup
virtual cHistogram * dup() const override
Definition: chistogram.h:163
omnetpp::cIHistogramStrategy
Interface for histogram strategy classes. Histogram strategies encapsulate the task of setting up and...
Definition: chistogramstrategy.h:29
omnetpp::cAbstractHistogram
Interface and base class for histogram-like density estimation classes.
Definition: cabstracthistogram.h:26
omnetpp::cStdDev::collectWeighted
virtual void collectWeighted(double value, double weight) override
omnetpp::cStatistic
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
omnetpp::cHistogram::Mode
Mode
Definition: chistogram.h:95
omnetpp::cHistogram::getOverflowSumWeights
virtual double getOverflowSumWeights() const override
Definition: chistogram.h:333
omnetpp::cCommBuffer
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41