A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
data-calculator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 Drexel University
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Joe Kopena (tjkopena@cs.drexel.edu)
18 */
19
20#ifndef DATA_CALCULATOR_H
21#define DATA_CALCULATOR_H
22
23#include "ns3/nstime.h"
24#include "ns3/object.h"
25#include "ns3/simulator.h"
26
27namespace ns3
28{
29extern const double NaN; //!< Stored representation of NaN
30
31/**
32 * \brief true if x is NaN
33 * \param x
34 * \return whether x is NaN
35 */
36inline bool
37isNaN(double x)
38{
39 return x != x;
40}
41
42class DataOutputCallback;
43
44/**
45 * \ingroup stats
46 * \class StatisticalSummary
47 * \brief Abstract class for calculating statistical data
48 *
49 */
51{
52 public:
53 /**
54 * Destructor
55 */
57 {
58 }
59
60 /**
61 * Returns the number of observations.
62 * \return Number of observations
63 */
64 virtual long getCount() const = 0;
65
66 /**
67 * \return Sum of values
68 * @see getWeightedSum()
69 */
70 virtual double getSum() const = 0;
71
72 /**
73 * \return Sum of squared values
74 * @see getWeightedSqrSum()
75 */
76 virtual double getSqrSum() const = 0;
77
78 /**
79 * Returns the minimum of the values.
80 * \return Minimum of values
81 */
82 virtual double getMin() const = 0;
83
84 /**
85 * Returns the maximum of the values.
86 * \return Maximum of values
87 */
88 virtual double getMax() const = 0;
89
90 /**
91 * Returns the mean of the (weighted) observations.
92 * \return Mean of (weighted) observations
93 */
94 virtual double getMean() const = 0;
95
96 /**
97 * Returns the standard deviation of the (weighted) observations.
98 * \return Standard deviation of (weighted) observations
99 */
100 virtual double getStddev() const = 0;
101
102 /**
103 * Returns the variance of the (weighted) observations.
104 * \return Variance of (weighted) observations
105 */
106 virtual double getVariance() const = 0;
107};
108
109//------------------------------------------------------------
110//--------------------------------------------
111/**
112 * \ingroup stats
113 * \class DataCalculator
114 * \brief Calculates data during a simulation
115 *
116 */
117class DataCalculator : public Object
118{
119 public:
121 ~DataCalculator() override;
122
123 /**
124 * Register this type.
125 * \return The TypeId.
126 */
127 static TypeId GetTypeId();
128
129 /**
130 * Returns whether the DataCalculator is enabled
131 * \return true if DataCalculator is enabled
132 */
133 bool GetEnabled() const;
134 /**
135 * Enables DataCalculator when simulation starts
136 */
137 void Enable();
138 /**
139 * Disables DataCalculator when simulation stops
140 */
141 void Disable();
142 /**
143 * Sets the DataCalculator key to the provided key
144 * \param key Key value as a string
145 */
146 void SetKey(const std::string key);
147 /**
148 * Gets the DataCalculator key
149 * \return Key value as a string
150 */
151 std::string GetKey() const;
152
153 /**
154 * Sets the DataCalculator context to the provided context
155 * \param context Context value as a string
156 */
157 void SetContext(const std::string context);
158 /**
159 * Gets the DataCalculator context
160 * \return Context value as a string
161 */
162 std::string GetContext() const;
163
164 /**
165 * Starts DataCalculator at a given time in the simulation
166 * \param startTime
167 */
168 virtual void Start(const Time& startTime);
169 /**
170 * Stops DataCalculator at a given time in the simulation
171 * \param stopTime
172 */
173 virtual void Stop(const Time& stopTime);
174
175 /**
176 * Outputs data based on the provided callback
177 * \param callback
178 */
179 virtual void Output(DataOutputCallback& callback) const = 0;
180
181 protected:
182 bool m_enabled; //!< Descendant classes *must* check & respect m_enabled!
183
184 std::string m_key; //!< Key value
185 std::string m_context; //!< Context value
186
187 void DoDispose() override;
188
189 private:
190 EventId m_startEvent; //!< Start event
191 EventId m_stopEvent; //!< Stop event
192
193 // end class DataCalculator
194};
195
196// end namespace ns3
197}; // namespace ns3
198
199#endif /* DATA_CALCULATOR_H */
Calculates data during a simulation.
void SetContext(const std::string context)
Sets the DataCalculator context to the provided context.
virtual void Output(DataOutputCallback &callback) const =0
Outputs data based on the provided callback.
bool m_enabled
Descendant classes must check & respect m_enabled!
static TypeId GetTypeId()
Register this type.
virtual void Start(const Time &startTime)
Starts DataCalculator at a given time in the simulation.
~DataCalculator() override
virtual void Stop(const Time &stopTime)
Stops DataCalculator at a given time in the simulation.
bool GetEnabled() const
Returns whether the DataCalculator is enabled.
void Disable()
Disables DataCalculator when simulation stops.
std::string GetKey() const
Gets the DataCalculator key.
std::string m_context
Context value.
std::string m_key
Key value.
EventId m_stopEvent
Stop event.
void DoDispose() override
Destructor implementation.
void Enable()
Enables DataCalculator when simulation starts.
std::string GetContext() const
Gets the DataCalculator context.
void SetKey(const std::string key)
Sets the DataCalculator key to the provided key.
EventId m_startEvent
Start event.
Callback class for the DataOutput classes.
An identifier for simulation events.
Definition: event-id.h:55
A base class which provides memory management and object aggregation.
Definition: object.h:89
Abstract class for calculating statistical data.
virtual double getMax() const =0
Returns the maximum of the values.
virtual double getMean() const =0
Returns the mean of the (weighted) observations.
virtual double getStddev() const =0
Returns the standard deviation of the (weighted) observations.
virtual ~StatisticalSummary()
Destructor.
virtual double getVariance() const =0
Returns the variance of the (weighted) observations.
virtual long getCount() const =0
Returns the number of observations.
virtual double getMin() const =0
Returns the minimum of the values.
virtual double getSum() const =0
virtual double getSqrSum() const =0
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
Time stopTime
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const double NaN
Stored representation of NaN.
bool isNaN(double x)
true if x is NaN