OMNeT++ Simulation Library  6.0.3
resultfilters.h
1 //==========================================================================
2 // RESULTFILTERS.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_RESULTFILTERS_H
17 #define __OMNETPP_RESULTFILTERS_H
18 
19 #include <cmath> // INFINITY, NAN
20 #include "omnetpp/simkerneldefs.h"
21 #include "omnetpp/cresultfilter.h"
22 #include "omnetpp/csimulation.h"
23 #include "omnetpp/cstatistic.h"
24 
25 namespace omnetpp {
26 
39 class SIM_API WarmupPeriodFilter : public cResultFilter
40 {
41  protected:
42  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override;
43  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t, cObject *details) override;
44  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t, cObject *details) override;
45  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override;
46  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override;
47  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override;
48  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override;
49  public:
50  virtual simtime_t_cref getEndWarmupPeriod() const {return getSimulation()->getWarmupPeriod();}
51  virtual std::string str() const override;
52 };
53 
64 class SIM_API DemuxFilter : public cResultFilter
65 {
66  private:
67  int fanOut = -1; // number of initial outputs; #outputs is a multiple of fanOut
68  std::map<std::string, int> labelToDelegateStartIndexMap;
69  private:
70  int getDelegateStartIndexByLabel(cObject *details);
71  cResultListener *copyChain(cResultListener *templateChain, const char *label);
72  protected:
73  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override;
74  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t, cObject *details) override;
75  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t, cObject *details) override;
76  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override;
77  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override;
78  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override;
79  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override;
80  public:
81  virtual std::string str() const override;
82 };
83 
87 class SIM_API TotalCountFilter : public cResultFilter
88 {
89  protected:
90  intval_t count;
91  protected:
92  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override {count++; fire(this,t,count,details);}
93  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t l, cObject *details) override {count++; fire(this,t,count,details);}
94  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t l, cObject *details) override {count++; fire(this,t,count,details);}
95  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {count++; fire(this,t,count,details);}
96  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override {count++; fire(this,t,count,details);}
97  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {count++; fire(this,t,count,details);}
98  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {count++; fire(this,t,count,details);}
99  public:
100  TotalCountFilter() {count = 0;}
101  intval_t getCount() const {return count;}
102  virtual double getInitialDoubleValue() const override {return getCount();}
103  virtual std::string str() const override;
104 };
105 
110 class SIM_API CountFilter : public TotalCountFilter
111 {
112  protected:
113  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {if (!std::isnan(d)) count++; fire(this,t,count,details);}
114  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {if (s) count++; fire(this,t,count,details);}
115  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {if (obj) count++; fire(this,t,count,details);}
116  public:
117  CountFilter() {}
118 };
119 
124 class SIM_API ConstantFilter : public cResultFilter
125 {
126  protected:
127  double c;
128  protected:
129  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override {fire(this,t,c,details);}
130  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t l, cObject *details) override {fire(this,t,c,details);}
131  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t l, cObject *details) override {fire(this,t,c,details);}
132  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {fire(this,t,c,details);}
133  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override {fire(this,t,c,details);}
134  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {fire(this,t,c,details);}
135  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {fire(this,t,c,details);}
136  public:
137  ConstantFilter(double c) {this->c = c;}
138  double getConstant() const {return c;}
139  virtual double getInitialDoubleValue() const override {return c;}
140  virtual std::string str() const override;
141 };
142 
146 class SIM_API Constant0Filter : public ConstantFilter
147 {
148  public:
150 };
151 
155 class SIM_API Constant1Filter : public ConstantFilter
156 {
157  public:
159 };
160 
167 class SIM_API TimeFilter : public cResultFilter
168 {
169  protected:
170  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override {fire(this,t,t,details);}
171  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t l, cObject *details) override {fire(this,t,t,details);}
172  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t l, cObject *details) override {fire(this,t,t,details);}
173  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {fire(this,t,t,details);}
174  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override {fire(this,t,t,details);}
175  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {fire(this,t,t,details);}
176  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {fire(this,t,t,details);}
177  public:
178  TimeFilter() {}
179 };
180 
184 class SIM_API IdentityFilter : public cResultFilter
185 {
186  protected:
187  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override {fire(this,t,b,details);}
188  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t l, cObject *details) override {fire(this,t,l,details);}
189  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t l, cObject *details) override {fire(this,t,l,details);}
190  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {fire(this,t,d,details);}
191  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override {fire(this,t,v,details);}
192  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {fire(this,t,s,details);}
193  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {fire(this,t,obj,details);}
194  public:
195  IdentityFilter() {}
196 };
197 
201 class SIM_API MergeFilter : public IdentityFilter
202 {
203  protected:
204  virtual void subscribedTo(cResultFilter *prev) override {} // to allow subscription to multiple signals
205  public:
206  MergeFilter() {}
207 };
208 
209 
213 class SIM_API SkipNanFilter : public cNumericResultFilter
214 {
215  protected:
216  virtual bool process(simtime_t& t, double& value, cObject *details) override {return !std::isnan(value);}
217 };
218 
222 class SIM_API ErrorNanFilter : public cNumericResultFilter
223 {
224  protected:
225  virtual bool process(simtime_t& t, double& value, cObject *details) override;
226 };
227 
231 class SIM_API CountNanFilter : public cNumericResultFilter
232 {
233  protected:
234  intval_t count = 0;
235  protected:
236  virtual bool process(simtime_t& t, double& value, cObject *details) override;
237  public:
238  CountNanFilter() {}
239  intval_t getCount() const {return count;}
240  virtual double getInitialDoubleValue() const override {return getCount();}
241  virtual std::string str() const override;
242 };
243 
247 class SIM_API SumFilter : public cNumericResultFilter
248 {
249  protected:
250  double sum;
251  protected:
252  virtual bool process(simtime_t& t, double& value, cObject *details) override;
253  public:
254  SumFilter() {sum = 0;}
255  double getSum() const {return sum;}
256  virtual double getInitialDoubleValue() const override {return getSum();}
257  virtual std::string str() const override;
258 };
259 
265 class SIM_API MeanFilter : public cNumericResultFilter
266 {
267  protected:
268  bool timeWeighted = false;
269  intval_t count = 0;
270  double lastValue = NAN;
271  simtime_t lastTime = SIMTIME_ZERO;
272  double weightedSum = 0;
273  simtime_t totalTime = SIMTIME_ZERO;
274  protected:
275  virtual bool process(simtime_t& t, double& value, cObject *details) override;
276  public:
277  MeanFilter() {}
278  virtual void init(Context *ctx) override;
279  double getMean() const;
280  virtual std::string str() const override;
281 };
282 
287 class SIM_API MinFilter : public cNumericResultFilter
288 {
289  protected:
290  double min;
291  protected:
292  virtual bool process(simtime_t& t, double& value, cObject *details) override;
293  public:
294  MinFilter() {min = INFINITY;}
295  double getMin() const {return min;}
296  virtual std::string str() const override;
297 };
298 
303 class SIM_API MaxFilter : public cNumericResultFilter
304 {
305  protected:
306  double max;
307  protected:
308  virtual bool process(simtime_t& t, double& value, cObject *details) override;
309  public:
310  MaxFilter() {max = -INFINITY;}
311  double getMax() const {return max;}
312  virtual std::string str() const override;
313 };
314 
319 class SIM_API AverageFilter : public cNumericResultFilter
320 {
321  protected:
322  intval_t count;
323  double sum;
324  protected:
325  virtual bool process(simtime_t& t, double& value, cObject *details) override;
326  public:
327  AverageFilter() {count = 0; sum = 0;}
328  double getAverage() const {return sum/count;}
329  virtual std::string str() const override;
330 };
331 
337 {
338  protected:
339  double lastValue = NAN;
340  simtime_t lastTime = SIMTIME_ZERO;
341  double weightedSum = 0;
342  simtime_t totalTime = SIMTIME_ZERO;
343  protected:
344  virtual bool process(simtime_t& t, double& value, cObject *details) override;
345  public:
346  TimeAverageFilter() {}
347  double getTimeAverage() const;
348  virtual std::string str() const override;
349 };
350 
355 {
356  protected:
357  double prev;
358  protected:
359  virtual bool process(simtime_t& t, double& value, cObject *details) override;
360  public:
361  RemoveRepeatsFilter() {prev = NAN;}
362  double getLastValue() const {return prev;}
363  virtual std::string str() const override;
364 };
365 
371 {
372  protected:
373  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *object, cObject *details) override;
374  public:
375  using cObjectResultFilter::receiveSignal;
376 };
377 
382 class SIM_API PacketBitsFilter : public cObjectResultFilter
383 {
384  protected:
385  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *object, cObject *details) override;
386  public:
387  using cObjectResultFilter::receiveSignal;
388 };
389 
395 {
396  protected:
397  double sum;
398  protected:
399  virtual bool process(simtime_t& t, double& value, cObject *details) override;
400  public:
401  SumPerDurationFilter() {sum = 0;}
402  double getSumPerDuration() const;
403  virtual double getInitialDoubleValue() const override {return getSumPerDuration();}
404  virtual std::string str() const override;
405 };
406 
409 } // namespace omnetpp
410 
411 #endif
omnetpp::PacketBytesFilter
Filter that expects a cPacket and outputs its length in bytes (getByteLength()). Null (nullptr) value...
Definition: resultfilters.h:370
omnetpp::IdentityFilter
This class is a no-op filter.
Definition: resultfilters.h:184
omnetpp::simtime_t_cref
const typedef simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition: simtime_t.h:48
omnetpp::cObjectResultFilter
Base class for filters that expect to receive an object.
Definition: cresultfilter.h:146
omnetpp::Constant0Filter
Result filter that replaces every value with zero.
Definition: resultfilters.h:146
omnetpp::ErrorNanFilter
Filter that raises a runtime error if it sees a NaN in the input.
Definition: resultfilters.h:222
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::AverageFilter
Result filter that computes the arithmetic mean of signal values. NaN values in the input are ignored...
Definition: resultfilters.h:319
omnetpp::MeanFilter
Result filter that computes the (time-weighted or unweighted) mean of signal values....
Definition: resultfilters.h:265
omnetpp::DemuxFilter
Result filter that demultiplexes its input to several outputs. The selector (a.ka....
Definition: resultfilters.h:64
omnetpp::SumFilter
Filter that outputs the sum of signal values. NaN values in the input are ignored.
Definition: resultfilters.h:247
omnetpp::CountNanFilter
Filter that counts NaN values in the input.
Definition: resultfilters.h:231
omnetpp::TotalCountFilter
Result filter for counting the input values, including NaN and nullptr values.
Definition: resultfilters.h:87
omnetpp::SkipNanFilter
Filter that removes (filters out) NaNs, and lets through all other values.
Definition: resultfilters.h:213
omnetpp::SumPerDurationFilter
Filter that outputs the sum of signal values divided by the measurement interval (simtime minus warmu...
Definition: resultfilters.h:394
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::uintval_t
uint64_t uintval_t
Unsigned integer type which is guaranteed to be at least 64 bits wide. It is used throughout the libr...
Definition: simkerneldefs.h:109
omnetpp::WarmupPeriodFilter
Result filter that absorbs input values during the configured warm-up period (see warmup-period confi...
Definition: resultfilters.h:39
omnetpp::getSimulation
cSimulation * getSimulation()
Returns the currently active simulation, or nullptr if there is none.
Definition: csimulation.h:603
omnetpp::RemoveRepeatsFilter
Result filter that removes repeated values.
Definition: resultfilters.h:354
omnetpp::MinFilter
Result filter that computes the minimum of signal values. NaN values in the input are ignored.
Definition: resultfilters.h:287
omnetpp::cNumericResultFilter
Base class for filters that expect to receive an numeric value.
Definition: cresultfilter.h:122
omnetpp::TimeAverageFilter
Result filter that computes the time average of signal values. NaN values in the input denote interva...
Definition: resultfilters.h:336
omnetpp::PacketBitsFilter
Filter that expects a cPacket and outputs its length in bits (getBitLength()). Null (nullptr) values ...
Definition: resultfilters.h:382
omnetpp::MergeFilter
Filter that merges several inputs into one output.
Definition: resultfilters.h:201
omnetpp::cSimulation::getWarmupPeriod
simtime_t_cref getWarmupPeriod() const
Definition: csimulation.h:417
omnetpp::MaxFilter
Result filter that computes the maximum of signal values. NaN values in the input are ignored.
Definition: resultfilters.h:303
SIMTIME_ZERO
#define SIMTIME_ZERO
Zero simulation time.
Definition: simtime_t.h:70
omnetpp::intval_t
int64_t intval_t
Signed integer type which is guaranteed to be at least 64 bits wide. It is used throughout the librar...
Definition: simkerneldefs.h:101
omnetpp::cResultFilter::Context
Definition: cresultfilter.h:78
omnetpp::cResultFilter
Base class for result filters.
Definition: cresultfilter.h:72
omnetpp::TimeFilter
Result filter that yields the time of emitting the signal.
Definition: resultfilters.h:167
omnetpp::CountFilter
Result filter for counting signals. Signal values do not need to be numeric to be counted....
Definition: resultfilters.h:110
omnetpp::Constant1Filter
Result filter that replaces every value with 1.0.
Definition: resultfilters.h:155
omnetpp::cResultListener
Common abstract base class for result filters and result recorders.
Definition: cresultlistener.h:34
omnetpp::ConstantFilter
Result filter that replaces every value with a constant. Signal values do not need to be numeric.
Definition: resultfilters.h:124