OMNeT++ Simulation Library  5.6.1
resultfilters.h
1 //==========================================================================
2 // RESULTFILTERS.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 // Author: Andras Varga
7 //
8 //==========================================================================
9 
10 /*--------------------------------------------------------------*
11  Copyright (C) 1992-2017 Andras Varga
12  Copyright (C) 2006-2017 OpenSim Ltd.
13 
14  This file is distributed WITHOUT ANY WARRANTY. See the file
15  `license' for details on this and other legal matters.
16 *--------------------------------------------------------------*/
17 
18 #ifndef __OMNETPP_RESULTFILTERS_H
19 #define __OMNETPP_RESULTFILTERS_H
20 
21 #include <cmath> // INFINITY, NAN
22 #include "omnetpp/simkerneldefs.h"
23 #include "omnetpp/cresultfilter.h"
24 #include "omnetpp/csimulation.h"
25 #include "omnetpp/cstatistic.h"
26 
27 namespace omnetpp {
28 
29 class SIM_API WarmupPeriodFilter : public cResultFilter
30 {
31  protected:
32  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override;
33  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l, cObject *details) override;
34  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details) override;
35  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override;
36  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override;
37  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override;
38  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override;
39  public:
40  virtual simtime_t_cref getEndWarmupPeriod() const {return getSimulation()->getWarmupPeriod();}
41  virtual std::string str() const override;
42 };
43 
47 class SIM_API TotalCountFilter : public cResultFilter
48 {
49  protected:
50  long count;
51  protected:
52  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override {count++; fire(this,t,count,details);}
53  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l, cObject *details) override {count++; fire(this,t,count,details);}
54  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details) override {count++; fire(this,t,count,details);}
55  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {count++; fire(this,t,count,details);}
56  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override {count++; fire(this,t,count,details);}
57  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {count++; fire(this,t,count,details);}
58  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {count++; fire(this,t,count,details);}
59  public:
60  TotalCountFilter() {count = 0;}
61  long getCount() const {return count;}
62  virtual double getInitialDoubleValue() const override {return getCount();}
63  virtual std::string str() const override;
64 };
65 
70 class SIM_API CountFilter : public TotalCountFilter
71 {
72  protected:
73  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {if (!std::isnan(d)) count++; fire(this,t,count,details);}
74  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {if (s) count++; fire(this,t,count,details);}
75  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {if (obj) count++; fire(this,t,count,details);}
76  public:
77  CountFilter() {}
78 };
79 
84 class SIM_API ConstantFilter : public cResultFilter
85 {
86  protected:
87  double c;
88  protected:
89  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override {fire(this,t,c,details);}
90  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l, cObject *details) override {fire(this,t,c,details);}
91  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details) override {fire(this,t,c,details);}
92  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {fire(this,t,c,details);}
93  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override {fire(this,t,c,details);}
94  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {fire(this,t,c,details);}
95  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {fire(this,t,c,details);}
96  public:
97  ConstantFilter(double c) {this->c = c;}
98  double getConstant() const {return c;}
99  virtual std::string str() const override;
100 };
101 
105 class SIM_API Constant0Filter : public ConstantFilter
106 {
107  public:
109 };
110 
114 class SIM_API Constant1Filter : public ConstantFilter
115 {
116  public:
118 };
119 
126 class SIM_API TimeFilter : public cResultFilter
127 {
128  protected:
129  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override {fire(this,t,t,details);}
130  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l, cObject *details) override {fire(this,t,t,details);}
131  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details) override {fire(this,t,t,details);}
132  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {fire(this,t,t,details);}
133  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override {fire(this,t,t,details);}
134  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {fire(this,t,t,details);}
135  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {fire(this,t,t,details);}
136  public:
137  TimeFilter() {}
138 };
139 
143 class SIM_API IdentityFilter : public cNumericResultFilter
144 {
145  protected:
146  virtual bool process(simtime_t& t, double& value, cObject *details) override {return true;}
147 };
148 
152 class SIM_API SkipNanFilter : public cNumericResultFilter
153 {
154  protected:
155  virtual bool process(simtime_t& t, double& value, cObject *details) override {return !std::isnan(value);}
156 };
157 
161 class SIM_API ErrorNanFilter : public cNumericResultFilter
162 {
163  protected:
164  virtual bool process(simtime_t& t, double& value, cObject *details) override;
165 };
166 
170 class SIM_API CountNanFilter : public cNumericResultFilter
171 {
172  protected:
173  long count = 0;
174  protected:
175  virtual bool process(simtime_t& t, double& value, cObject *details) override;
176  public:
177  CountNanFilter() {}
178  long getCount() const {return count;}
179  virtual double getInitialDoubleValue() const override {return getCount();}
180  virtual std::string str() const override;
181 };
182 
186 class SIM_API SumFilter : public cNumericResultFilter
187 {
188  protected:
189  double sum;
190  protected:
191  virtual bool process(simtime_t& t, double& value, cObject *details) override;
192  public:
193  SumFilter() {sum = 0;}
194  double getSum() const {return sum;}
195  virtual double getInitialDoubleValue() const override {return getSum();}
196  virtual std::string str() const override;
197 };
198 
204 class SIM_API MeanFilter : public cNumericResultFilter
205 {
206  protected:
207  bool timeWeighted = false;
208  long count = 0;
209  double lastValue = NAN;
210  simtime_t lastTime = SIMTIME_ZERO;
211  double weightedSum = 0;
212  simtime_t totalTime = SIMTIME_ZERO;
213  protected:
214  virtual bool process(simtime_t& t, double& value, cObject *details) override;
215  public:
216  MeanFilter() {}
217  virtual void init(cComponent *component, cProperty *attrsProperty) override;
218  double getMean() const;
219  virtual std::string str() const override;
220 };
221 
226 class SIM_API MinFilter : public cNumericResultFilter
227 {
228  protected:
229  double min;
230  protected:
231  virtual bool process(simtime_t& t, double& value, cObject *details) override;
232  public:
233  MinFilter() {min = INFINITY;}
234  double getMin() const {return min;}
235  virtual std::string str() const override;
236 };
237 
242 class SIM_API MaxFilter : public cNumericResultFilter
243 {
244  protected:
245  double max;
246  protected:
247  virtual bool process(simtime_t& t, double& value, cObject *details) override;
248  public:
249  MaxFilter() {max = -INFINITY;}
250  double getMax() const {return max;}
251  virtual std::string str() const override;
252 };
253 
258 class SIM_API AverageFilter : public cNumericResultFilter
259 {
260  protected:
261  long count;
262  double sum;
263  protected:
264  virtual bool process(simtime_t& t, double& value, cObject *details) override;
265  public:
266  AverageFilter() {count = 0; sum = 0;}
267  double getAverage() const {return sum/count;}
268  virtual std::string str() const override;
269 };
270 
276 {
277  protected:
278  double lastValue = NAN;
279  simtime_t lastTime = SIMTIME_ZERO;
280  double weightedSum = 0;
281  simtime_t totalTime = SIMTIME_ZERO;
282  protected:
283  virtual bool process(simtime_t& t, double& value, cObject *details) override;
284  public:
285  TimeAverageFilter() {}
286  double getTimeAverage() const;
287  virtual std::string str() const override;
288 };
289 
294 {
295  protected:
296  double prev;
297  protected:
298  virtual bool process(simtime_t& t, double& value, cObject *details) override;
299  public:
300  RemoveRepeatsFilter() {prev = NAN;}
301  double getLastValue() const {return prev;}
302  virtual std::string str() const override;
303 };
304 
310 {
311  protected:
312  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *object, cObject *details) override;
313  public:
314  using cObjectResultFilter::receiveSignal;
315 };
316 
321 class SIM_API PacketBitsFilter : public cObjectResultFilter
322 {
323  protected:
324  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *object, cObject *details) override;
325  public:
326  using cObjectResultFilter::receiveSignal;
327 };
328 
334 {
335  protected:
336  double sum;
337  protected:
338  virtual bool process(simtime_t& t, double& value, cObject *details) override;
339  public:
340  SumPerDurationFilter() {sum = 0;}
341  double getSumPerDuration() const;
342  virtual double getInitialDoubleValue() const override {return getSumPerDuration();}
343  virtual std::string str() const override;
344 };
345 
346 } // namespace omnetpp
347 
348 #endif
Common base for module and channel classes.
Definition: ccomponent.h:48
Filter that expects a cPacket and outputs its length in bytes (getByteLength()). Null (nullptr) value...
Definition: resultfilters.h:309
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
Base class for filters that expect to receive an numeric value.
Definition: cresultfilter.h:107
Result filter that replaces every value with 1.0.
Definition: resultfilters.h:114
Result filter that computes the maximum of signal values. NaN values in the input are ignored...
Definition: resultfilters.h:242
Result filter for counting the input values, including NaN and nullptr values.
Definition: resultfilters.h:47
Result filter that computes the arithmetic mean of signal values. NaN values in the input are ignored...
Definition: resultfilters.h:258
simtime_t_cref getWarmupPeriod() const
Definition: csimulation.h:394
Filter that expects a cPacket and outputs its length in bits (getBitLength()). Null (nullptr) values ...
Definition: resultfilters.h:321
Result filter that replaces every value with a constant. Signal values do not need to be numeric...
Definition: resultfilters.h:84
Result filter that computes the time average of signal values. NaN values in the input denote interva...
Definition: resultfilters.h:275
Filter that removes (filters out) NaNs, and lets through all other values.
Definition: resultfilters.h:152
Filter that counts NaN values in the input.
Definition: resultfilters.h:170
Result filter for counting signals. Signal values do not need to be numeric to be counted...
Definition: resultfilters.h:70
Result filter that replaces every value with zero.
Definition: resultfilters.h:105
#define SIMTIME_ZERO
Zero simulation time.
Definition: simtime_t.h:73
Filter that outputs the sum of signal values divided by the measurement interval (simtime minus warmu...
Definition: resultfilters.h:333
Result filter that yields the time of emitting the signal.
Definition: resultfilters.h:126
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38
Base class for result filters.
Definition: cresultfilter.h:72
Result filter that removes repeated values.
Definition: resultfilters.h:293
Result filter that computes the (time-weighted or unweighted) mean of signal values. NaN values in the input are ignored, or in the time-weighted case, they denote intervals to be ignored.
Definition: resultfilters.h:204
const simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition: simtime_t.h:46
This class is a no-op filter.
Definition: resultfilters.h:143
Definition: cabstracthistogram.h:21
Result filter that computes the minimum of signal values. NaN values in the input are ignored...
Definition: resultfilters.h:226
Filter that raises a runtime error if it sees a NaN in the input.
Definition: resultfilters.h:161
Filter that outputs the sum of signal values. NaN values in the input are ignored.
Definition: resultfilters.h:186
Base class for filters that expect to receive an object.
Definition: cresultfilter.h:131
cSimulation * getSimulation()
Returns the currently active simulation, or nullptr if there is none.
Definition: csimulation.h:575