Project

General

Profile

Statistics
| Branch: | Revision:

root / src / envir / resultfilters.h @ 636cbdd5

History | View | Annotate | Download (7.17 KB)

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-2008 Andras Varga
12
  Copyright (C) 2006-2008 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 __ENVIR_RESULTFILTERS_H
19
#define __ENVIR_RESULTFILTERS_H
20

    
21
#include "envirdefs.h"
22
#include "resultfilter.h"
23
#include "csimulation.h"
24
#include "cstatistic.h"
25
#include "expression.h"
26

    
27

    
28
class ENVIR_API WarmupPeriodFilter : public ResultFilter
29
{
30
    private:
31
        simtime_t_cref getEndWarmupPeriod() {return simulation.getWarmupPeriod();}
32
    public:
33
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, long l);
34
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, unsigned long l);
35
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, double d);
36
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const SimTime& v);
37
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const char *s);
38
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, cObject *obj);
39
};
40

    
41
/**
42
 * Result filter for counting signals. Signal values do not need to be numeric
43
 * to be counted.
44
 */
45
class ENVIR_API CountFilter : public ResultFilter
46
{
47
    protected:
48
        long count;
49
    public:
50
        CountFilter() {count = 0;}
51
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, long l) {count++; fire(this,t,count);}
52
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, unsigned long l) {count++; fire(this,t,count);}
53
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, double d) {count++; fire(this,t,count);}
54
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const SimTime& v) {count++; fire(this,t,count);}
55
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const char *s) {count++; fire(this,t,count);}
56
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, cObject *obj) {count++; fire(this,t,count);}
57
};
58

    
59
/**
60
 * Result filter that replaces every value with a constant. Signal values
61
 * do not need to be numeric.
62
 */
63
class ENVIR_API ConstantFilter : public ResultFilter
64
{
65
    protected:
66
        double c;
67
    public:
68
        ConstantFilter(double c) {this->c = c;}
69
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, long l) {fire(this,t,c);}
70
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, unsigned long l) {fire(this,t,c);}
71
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, double d) {fire(this,t,c);}
72
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const SimTime& v) {fire(this,t,c);}
73
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const char *s) {fire(this,t,c);}
74
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, cObject *obj) {fire(this,t,c);}
75
};
76

    
77
/**
78
 * Result filter that replaces every value with zero.
79
 */
80
class ENVIR_API Constant0Filter : public ConstantFilter
81
{
82
    public:
83
        Constant0Filter() : ConstantFilter(0) {}
84
};
85

    
86
/**
87
 * Result filter that replaces every value with 1.0.
88
 */
89
class ENVIR_API Constant1Filter : public ConstantFilter
90
{
91
    public:
92
        Constant1Filter() : ConstantFilter(1) {}
93
};
94

    
95
/**
96
 * This class is actually a no-op; provided for symmetry with LastValueRecorder.
97
 */
98
class ENVIR_API LastValueFilter : public NumericResultFilter
99
{
100
    protected:
101
        virtual bool process(simtime_t& t, double& value) {return true;}
102
};
103

    
104
/**
105
 * Filter that outputs the sum of signal values.
106
 */
107
class ENVIR_API SumFilter : public NumericResultFilter
108
{
109
    protected:
110
        double sum;
111
    protected:
112
        virtual bool process(simtime_t& t, double& value) {sum += value; value = sum; return true;}
113
    public:
114
        SumFilter() {sum = 0;}
115
};
116

    
117
/**
118
 * Result filter that computes the mean of signal values
119
 */
120
class ENVIR_API MeanFilter : public NumericResultFilter
121
{
122
    protected:
123
        long count;
124
        double sum;
125
    protected:
126
        virtual bool process(simtime_t& t, double& value) {count++; sum += value; value = sum/count; return true;}
127
    public:
128
        MeanFilter() {count = 0; sum = 0;}
129
};
130

    
131
/**
132
 * Result filter that computes the minimum of signal values
133
 */
134
class ENVIR_API MinFilter : public NumericResultFilter
135
{
136
    protected:
137
        double min;
138
    protected:
139
        virtual bool process(simtime_t& t, double& value) {if (value < min) min = value; value = min; return true;}
140
    public:
141
        MinFilter() {min = POSITIVE_INFINITY;}
142
};
143

    
144
/**
145
 * Result filter that computes the maximum of signal values
146
 */
147
class ENVIR_API MaxFilter : public NumericResultFilter
148
{
149
    protected:
150
        double max;
151
    protected:
152
        virtual bool process(simtime_t& t, double& value) {if (value > max) max = value; value = max; return true;}
153
    public:
154
        MaxFilter() {max = NEGATIVE_INFINITY;}
155
};
156

    
157
/**
158
 * Result filter that computes the time average of signal values
159
 */
160
class ENVIR_API TimeAverageFilter : public NumericResultFilter
161
{
162
    protected:
163
        simtime_t startTime;
164
        simtime_t lastTime;
165
        double lastValue;
166
        double weightedSum;
167
    protected:
168
        virtual bool process(simtime_t& t, double& value);
169
    public:
170
        TimeAverageFilter() {startTime = lastTime = -1; lastValue = weightedSum = 0;}
171
};
172

    
173
/**
174
 * Result filter that computes an expression from signal values
175
 */
176
class ENVIR_API ExpressionFilter : public NumericResultFilter
177
{
178
    protected:
179
        Expression expr;
180
    public:
181
        // current values, valid inside process() only
182
        simtime_t currentTime;
183
        double currentValue;
184
    protected:
185
        virtual bool process(simtime_t& t, double& value);
186
    public:
187
        ExpressionFilter() {}
188
        virtual std::string str() const {return expr.str()+" (ExpressionFilter)";}
189
        Expression& getExpression() {return expr;}
190
        Expression::Functor *makeValueVariable();
191
        Expression::Functor *makeTimeVariable();
192
};
193

    
194
/**
195
 * Filter that expects a cPacket and outputs its length in bytes (getByteLength()).
196
 */
197
class ENVIR_API PacketBytesFilter : public ObjectResultFilter
198
{
199
    public:
200
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, cObject *object);
201
};
202

    
203
/**
204
 * Filter that expects a cPacket and outputs its length in bits (getBitLength()).
205
 */
206
class ENVIR_API PacketBitsFilter : public ObjectResultFilter
207
{
208
    public:
209
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, cObject *object);
210
};
211

    
212
/**
213
 * Filter that outputs the sum of signal values divided by the measurement
214
 * interval (simtime minus warmupPeriod)
215
 */
216
class ENVIR_API SumPerDurationFilter : public NumericResultFilter
217
{
218
    protected:
219
        double sum;
220
    protected:
221
        virtual bool process(simtime_t& t, double& value);
222
    public:
223
        SumPerDurationFilter() {sum = 0;}
224
};
225

    
226
#endif
227

    
228