A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
random-variable-stream.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 Georgia Tech Research Corporation
3 * Copyright (c) 2011 Mathieu Lacage
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Authors: Rajib Bhattacharjea<raj.b@gatech.edu>
19 * Hadi Arbabi<marbabi@cs.odu.edu>
20 * Mathieu Lacage <mathieu.lacage@gmail.com>
21 * Alessio Bugetti <alessiobugetti98@gmail.com>
22 *
23 * Modified by Mitch Watrous <watrous@u.washington.edu>
24 *
25 */
26#ifndef RANDOM_VARIABLE_STREAM_H
27#define RANDOM_VARIABLE_STREAM_H
28
29#include "attribute-helper.h"
30#include "object.h"
31#include "type-id.h"
32
33#include <map>
34#include <stdint.h>
35
42namespace ns3
43{
44
75class RngStream;
76
101{
102 public:
107 static TypeId GetTypeId();
115 ~RandomVariableStream() override;
116
117 // Delete copy constructor and assignment operator to avoid misuse
120
126 void SetStream(int64_t stream);
127
133 int64_t GetStream() const;
134
139 void SetAntithetic(bool isAntithetic);
140
145 bool IsAntithetic() const;
146
151 virtual double GetValue() = 0;
152
154 // The base implementation returns `(uint32_t)GetValue()`
155 virtual uint32_t GetInteger();
156
157 protected:
162 RngStream* Peek() const;
163
164 private:
167
170
172 int64_t m_stream;
173
174}; // class RandomVariableStream
175
235{
236 public:
241 static TypeId GetTypeId();
242
247
252 double GetMin() const;
253
258 double GetMax() const;
259
266 double GetValue(double min, double max);
267
273
274 // Inherited
279 double GetValue() override;
280
285 uint32_t GetInteger() override;
286
287 private:
289 double m_min;
290
292 double m_max;
293
294}; // class UniformRandomVariable
295
309{
310 public:
315 static TypeId GetTypeId();
316
321
326 double GetConstant() const;
327
332 double GetValue(double constant);
334 uint32_t GetInteger(uint32_t constant);
335
336 // Inherited
337 /*
338 * \copydoc RandomVariableStream::GetValue()
339 * \note This RNG always returns the same value.
340 */
341 double GetValue() override;
342 /* \note This RNG always returns the same value. */
344
345 private:
348
349}; // class ConstantRandomVariable
350
413{
414 public:
419 static TypeId GetTypeId();
420
426
431 double GetMin() const;
432
438 double GetMax() const;
439
445
451 uint32_t GetConsecutive() const;
452
453 // Inherited
454 double GetValue() override;
456
457 private:
459 double m_min;
460
462 double m_max;
463
466
469
471 double m_current;
472
475
478
479}; // class SequentialRandomVariable
480
554{
555 public:
560 static TypeId GetTypeId();
561
567
575 double GetMean() const;
576
581 double GetBound() const;
582
588 double GetValue(double mean, double bound);
589
592
593 // Inherited
594 double GetValue() override;
596
597 private:
599 double m_mean;
600
602 double m_bound;
603
604}; // class ExponentialRandomVariable
605
686{
687 public:
692 static TypeId GetTypeId();
693
699
704 double GetScale() const;
705
710 double GetShape() const;
711
716 double GetBound() const;
717
724 double GetValue(double scale, double shape, double bound);
725
727 uint32_t GetInteger(uint32_t scale, uint32_t shape, uint32_t bound);
728
729 // Inherited
730 double GetValue() override;
732
733 private:
735 double m_scale;
736
738 double m_shape;
739
741 double m_bound;
742
743}; // class ParetoRandomVariable
744
833{
834 public:
839 static TypeId GetTypeId();
840
846
851 double GetScale() const;
852
857 double GetShape() const;
858
863 double GetBound() const;
864
871 double GetValue(double scale, double shape, double bound);
872
874 uint32_t GetInteger(uint32_t scale, uint32_t shape, uint32_t bound);
875
876 // Inherited
877 double GetValue() override;
879
880 private:
882 double m_scale;
883
885 double m_shape;
886
888 double m_bound;
889
890}; // class WeibullRandomVariable
891
970{
971 public:
973 static const double INFINITE_VALUE;
974
979 static TypeId GetTypeId();
980
986
991 double GetMean() const;
992
997 double GetVariance() const;
998
1003 double GetBound() const;
1004
1011 double GetValue(double mean,
1012 double variance,
1014
1016 uint32_t GetInteger(uint32_t mean, uint32_t variance, uint32_t bound);
1017
1018 // Inherited
1019 double GetValue() override;
1021
1022 private:
1024 double m_mean;
1025
1028
1030 double m_bound;
1031
1034
1036 double m_v2;
1038 double m_y;
1039
1040}; // class NormalRandomVariable
1041
1133{
1134 public:
1139 static TypeId GetTypeId();
1140
1146
1151 double GetMu() const;
1152
1157 double GetSigma() const;
1158
1164 double GetValue(double mu, double sigma);
1165
1168
1169 // Inherited
1170 double GetValue() override;
1172
1173 private:
1175 double m_mu;
1176
1178 double m_sigma;
1179
1182
1184 double m_v2;
1185
1187 double m_normal;
1188
1189}; // class LogNormalRandomVariable
1190
1246{
1247 public:
1252 static TypeId GetTypeId();
1253
1259
1264 double GetAlpha() const;
1265
1270 double GetBeta() const;
1271
1277 double GetValue(double alpha, double beta);
1278
1281
1282 // Inherited
1283 double GetValue() override;
1285
1286 private:
1295 double GetNormalValue(double mean, double variance, double bound);
1296
1298 double m_alpha;
1299
1301 double m_beta;
1302
1305
1307 double m_v2;
1309 double m_y;
1310
1311}; // class GammaRandomVariable
1312
1380{
1381 public:
1386 static TypeId GetTypeId();
1387
1393
1398 uint32_t GetK() const;
1399
1404 double GetLambda() const;
1405
1411 double GetValue(uint32_t k, double lambda);
1412
1415
1416 // Inherited
1417 double GetValue() override;
1419
1420 private:
1428 double GetExponentialValue(double mean, double bound);
1429
1432
1434 double m_lambda;
1435
1436}; // class ErlangRandomVariable
1437
1510{
1511 public:
1516 static TypeId GetTypeId();
1517
1523
1528 double GetMean() const;
1529
1534 double GetMin() const;
1535
1540 double GetMax() const;
1541
1548 double GetValue(double mean, double min, double max);
1549
1552
1553 // Inherited
1554 double GetValue() override;
1556
1557 private:
1559 double m_mean;
1560
1562 double m_min;
1563
1565 double m_max;
1566
1567}; // class TriangularRandomVariable
1568
1643{
1644 public:
1649 static TypeId GetTypeId();
1650
1656
1661 uint32_t GetN() const;
1662
1667 double GetAlpha() const;
1668
1675 double GetValue(uint32_t n, double alpha);
1676
1679
1680 // Inherited
1681 double GetValue() override;
1683
1684 private:
1687
1689 double m_alpha;
1690
1692 double m_c;
1693
1694}; // class ZipfRandomVariable
1695
1756{
1757 public:
1762 static TypeId GetTypeId();
1763
1769
1774 double GetAlpha() const;
1775
1780 double GetValue(double alpha);
1781
1784
1785 // Inherited
1786 double GetValue() override;
1788
1789 private:
1791 double m_alpha;
1792
1794 double m_b;
1795
1796}; // class ZetaRandomVariable
1797
1836{
1837 public:
1842 static TypeId GetTypeId();
1843
1850
1858 void SetValueArray(const std::vector<double>& values);
1867 void SetValueArray(const double* values, std::size_t length);
1868
1869 // Inherited
1870 double GetValue() override;
1872
1873 private:
1875 std::size_t m_count;
1876
1878 std::size_t m_next;
1879
1881 double* m_data;
1882
1883}; // class DeterministicRandomVariable
1884
1972{
1973 public:
1978 static TypeId GetTypeId();
1979
1985
1994 void CDF(double v, double c); // Value, prob <= Value
1995
1996 // Inherited
2002 double GetValue() override;
2004
2011 virtual double Interpolate();
2012
2019 bool SetInterpolate(bool interpolate);
2020
2021 private:
2032 void Validate();
2046 bool PreSample(double& value);
2052 double DoSampleCDF(double r);
2060 double DoInterpolate(double r);
2061
2069 std::map<double, double> m_empCdf;
2075
2076}; // class EmpiricalRandomVariable
2077
2143{
2144 public:
2149 static TypeId GetTypeId();
2150
2152
2160 double GetValue(uint32_t trials, double probability);
2161
2166 uint32_t GetInteger(uint32_t trials, uint32_t probability);
2167
2168 // Inherited
2169 double GetValue() override;
2171
2172 private:
2175
2178
2179}; // class BinomialRandomVariable
2180
2241{
2242 public:
2247 static TypeId GetTypeId();
2248
2250
2256 double GetValue(double probability);
2257
2262 uint32_t GetInteger(uint32_t probability);
2263
2264 // Inherited
2265 double GetValue() override;
2267
2268 private:
2271
2272}; // class BernoulliRandomVariable
2273
2274} // namespace ns3
2275
2276#endif /* RANDOM_VARIABLE_STREAM_H */
#define min(a, b)
Definition: 80211b.c:41
#define max(a, b)
Definition: 80211b.c:42
Attribute helper (ATTRIBUTE_ )macros definition.
The Bernoulli distribution Random Number Generator (RNG).
double GetValue() override
Get the next random value drawn from the distribution.
double m_probability
The probability of success.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
The binomial distribution Random Number Generator (RNG).
double m_probability
The probability of success in each trial.
double GetValue() override
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
uint32_t m_trials
The number of trials.
The Random Number Generator (RNG) that returns a constant.
static TypeId GetTypeId()
Register this type.
double GetValue() override
Get the next random value drawn from the distribution.
ConstantRandomVariable()
Creates a constant RNG with the default constant value.
double GetConstant() const
Get the constant value returned by this RNG stream.
double m_constant
The constant value returned by this RNG stream.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
The Random Number Generator (RNG) that returns a predetermined sequence.
double GetValue() override
Get the next random value drawn from the distribution.
std::size_t m_next
Position of the next value in the array of values.
void SetValueArray(const std::vector< double > &values)
Sets the array of values that holds the predetermined sequence.
static TypeId GetTypeId()
Register this type.
double * m_data
Array of values to return in sequence.
DeterministicRandomVariable()
Creates a deterministic RNG that will have a predetermined sequence of values.
std::size_t m_count
Size of the array of values.
The Random Number Generator (RNG) that has a specified empirical distribution.
bool SetInterpolate(bool interpolate)
Switch the mode between sampling the CDF and interpolating.
void CDF(double v, double c)
Specifies a point in the empirical distribution.
bool PreSample(double &value)
Do the initial rng draw and check against the extrema.
double DoSampleCDF(double r)
Sample the CDF as a histogram (without interpolation).
double GetValue() override
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
bool m_interpolate
If true GetValue will interpolate, otherwise treat CDF as normal histogram.
bool m_validated
true once the CDF has been validated.
double DoInterpolate(double r)
Linear interpolation between two points on the CDF to estimate the value at r.
virtual double Interpolate()
Returns the next value in the empirical distribution using linear interpolation.
EmpiricalRandomVariable()
Creates an empirical RNG that has a specified, empirical distribution, and configured for interpolati...
void Validate()
Check that the CDF is valid.
std::map< double, double > m_empCdf
The map of CDF points (x, F(x)).
The Erlang distribution Random Number Generator (RNG) that allows stream numbers to be set determinis...
double m_lambda
The lambda value for the Erlang distribution returned by this RNG stream.
double GetValue() override
Get the next random value drawn from the distribution.
double GetExponentialValue(double mean, double bound)
Returns a random double from an exponential distribution with the specified mean and upper bound.
static TypeId GetTypeId()
Register this type.
uint32_t GetK() const
Returns the k value for the Erlang distribution returned by this RNG stream.
double GetLambda() const
Returns the lambda value for the Erlang distribution returned by this RNG stream.
uint32_t m_k
The k value for the Erlang distribution returned by this RNG stream.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
ErlangRandomVariable()
Creates an Erlang distribution RNG with the default values for k and lambda.
The exponential distribution Random Number Generator (RNG).
ExponentialRandomVariable()
Creates an exponential distribution RNG with the default values for the mean and upper bound.
double GetBound() const
Get the configured upper bound of this RNG.
double m_mean
The mean value of the unbounded exponential distribution.
double GetMean() const
Get the configured mean value of this RNG.
double m_bound
The upper bound on values that can be returned by this RNG stream.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
double GetValue() override
Get the next random value drawn from the distribution.
The gamma distribution Random Number Generator (RNG) that allows stream numbers to be set determinist...
double GetValue() override
Get the next random value drawn from the distribution.
uint32_t GetInteger(uint32_t alpha, uint32_t beta)
Get the next random value drawn from the distribution.
GammaRandomVariable()
Creates a gamma distribution RNG with the default values for alpha and beta.
double m_alpha
The alpha value for the gamma distribution returned by this RNG stream.
double GetNormalValue(double mean, double variance, double bound)
Returns a random double from a normal distribution with the specified mean, variance,...
double m_y
The algorithm produces two values at a time.
double m_v2
The algorithm produces two values at a time.
bool m_nextValid
True if the next normal value is valid.
static TypeId GetTypeId()
Register this type.
double GetAlpha() const
Returns the alpha value for the gamma distribution returned by this RNG stream.
double GetBeta() const
Returns the beta value for the gamma distribution returned by this RNG stream.
double m_beta
The beta value for the gamma distribution returned by this RNG stream.
The log-normal distribution Random Number Generator (RNG) that allows stream numbers to be set determ...
double GetMu() const
Returns the mu value for the log-normal distribution returned by this RNG stream.
double m_v2
The algorithm produces two values at a time.
double GetSigma() const
Returns the sigma value for the log-normal distribution returned by this RNG stream.
double GetValue() override
Get the next random value drawn from the distribution.
bool m_nextValid
True if m_normal is valid.
double m_mu
The mu value for the log-normal distribution returned by this RNG stream.
double m_sigma
The sigma value for the log-normal distribution returned by this RNG stream.
LogNormalRandomVariable()
Creates a log-normal distribution RNG with the default values for mu and sigma.
double m_normal
The algorithm produces two values at a time.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
The normal (Gaussian) distribution Random Number Generator (RNG) that allows stream numbers to be set...
double m_y
The algorithm produces two values at a time.
double GetBound() const
Returns the bound on values that can be returned by this RNG stream.
double GetVariance() const
Returns the variance value for the normal distribution returned by this RNG stream.
double m_mean
The mean value for the normal distribution returned by this RNG stream.
static TypeId GetTypeId()
Register this type.
double GetMean() const
Returns the mean value for the normal distribution returned by this RNG stream.
static const double INFINITE_VALUE
Large constant to bound the range.
double m_variance
The variance value for the normal distribution returned by this RNG stream.
double GetValue() override
Get the next random value drawn from the distribution.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
double m_bound
The bound on values that can be returned by this RNG stream.
bool m_nextValid
True if the next value is valid.
NormalRandomVariable()
Creates a normal distribution RNG with the default values for the mean, variance, and bound.
double m_v2
The algorithm produces two values at a time.
A base class which provides memory management and object aggregation.
Definition: object.h:89
The Pareto distribution Random Number Generator (RNG).
double GetShape() const
Returns the shape parameter for the Pareto distribution returned by this RNG stream.
double m_scale
The scale parameter for the Pareto distribution returned by this RNG stream.
ParetoRandomVariable()
Creates a Pareto distribution RNG with the default values for the mean, the shape,...
static TypeId GetTypeId()
Register this type.
double m_shape
The shape parameter for the Pareto distribution returned by this RNG stream.
double GetScale() const
Returns the scale parameter for the Pareto distribution returned by this RNG stream.
double m_bound
The upper bound on values that can be returned by this RNG stream.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
double GetValue() override
Get the next random value drawn from the distribution.
double GetBound() const
Returns the upper bound on values that can be returned by this RNG stream.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
The basic uniform Random Number Generator (RNG).
static TypeId GetTypeId()
Register this type.
RngStream * Peek() const
Get the pointer to the underlying RngStream.
RandomVariableStream & operator=(const RandomVariableStream &)=delete
bool IsAntithetic() const
Check if antithetic values will be generated.
RandomVariableStream(const RandomVariableStream &)=delete
virtual double GetValue()=0
Get the next random value drawn from the distribution.
~RandomVariableStream() override
Destructor.
bool m_isAntithetic
Indicates if antithetic values should be generated by this RNG stream.
void SetAntithetic(bool isAntithetic)
Specify whether antithetic values should be generated.
int64_t m_stream
The stream number for the RngStream.
RandomVariableStream()
Default constructor.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
RngStream * m_rng
Pointer to the underlying RngStream.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
int64_t GetStream() const
Returns the stream number for the RngStream.
Combined Multiple-Recursive Generator MRG32k3a.
Definition: rng-stream.h:50
The Random Number Generator (RNG) that returns a pattern of sequential values.
uint32_t m_currentConsecutive
The number of times the current distinct value has been repeated.
double m_min
The first value of the sequence.
Ptr< RandomVariableStream > GetIncrement() const
Get the increment for the sequence.
uint32_t m_consecutive
The number of times each distinct value is repeated.
static TypeId GetTypeId()
Register this type.
double m_current
The current sequence value.
double m_max
Strict upper bound on the sequence.
Ptr< RandomVariableStream > m_increment
Increment between distinct values.
double GetValue() override
Get the next random value drawn from the distribution.
uint32_t GetConsecutive() const
Get the number of times each distinct value of the sequence is repeated before incrementing to the ne...
double GetMax() const
Get the limit of the sequence, which is (at least) one more than the last value of the sequence.
SequentialRandomVariable()
Creates a sequential RNG with the default values for the sequence parameters.
double GetMin() const
Get the first value of the sequence.
bool m_isCurrentSet
Indicates if the current sequence value has been properly initialized.
The triangular distribution Random Number Generator (RNG) that allows stream numbers to be set determ...
double GetValue() override
Get the next random value drawn from the distribution.
double GetMean() const
Returns the mean value for the triangular distribution returned by this RNG stream.
static TypeId GetTypeId()
Register this type.
double m_mean
The mean value for the triangular distribution returned by this RNG stream.
double m_max
The upper bound on values that can be returned by this RNG stream.
double GetMax() const
Returns the upper bound on values that can be returned by this RNG stream.
TriangularRandomVariable()
Creates a triangular distribution RNG with the default values for the mean, lower bound,...
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
double m_min
The lower bound on values that can be returned by this RNG stream.
double GetMin() const
Returns the lower bound for the triangular distribution returned by this RNG stream.
a unique identifier for an interface.
Definition: type-id.h:59
The uniform distribution Random Number Generator (RNG).
UniformRandomVariable()
Creates a uniform distribution RNG with the default range.
uint32_t GetInteger() override
Get the next random value drawn from the distribution.
double GetMax() const
Get the upper bound on values returned by GetValue().
double m_min
The lower bound on values that can be returned by this RNG stream.
double m_max
The upper bound on values that can be returned by this RNG stream.
static TypeId GetTypeId()
Register this type.
double GetValue() override
Get the next random value drawn from the distribution.
double GetMin() const
Get the lower bound on randoms returned by GetValue().
The Weibull distribution Random Number Generator (RNG) which allows stream numbers to be set determin...
double m_shape
The shape parameter for the Weibull distribution returned by this RNG stream.
double m_bound
The upper bound on values that can be returned by this RNG stream.
double m_scale
The scale parameter for the Weibull distribution returned by this RNG stream.
double GetBound() const
Returns the upper bound on values that can be returned by this RNG stream.
double GetValue() override
Get the next random value drawn from the distribution.
WeibullRandomVariable()
Creates a Weibull distribution RNG with the default values for the scale, shape, and upper bound.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
static TypeId GetTypeId()
Register this type.
double GetScale() const
Returns the scale parameter for the Weibull distribution returned by this RNG stream.
double GetShape() const
Returns the shape parameter for the Weibull distribution returned by this RNG stream.
The zeta distribution Random Number Generator (RNG) that allows stream numbers to be set deterministi...
static TypeId GetTypeId()
Register this type.
double m_alpha
The alpha value for the zeta distribution returned by this RNG stream.
double GetValue() override
Get the next random value drawn from the distribution.
ZetaRandomVariable()
Creates a zeta distribution RNG with the default value for alpha.
double GetAlpha() const
Returns the alpha value for the zeta distribution returned by this RNG stream.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
double m_b
Just for calculus simplifications.
The Zipf distribution Random Number Generator (RNG) that allows stream numbers to be set deterministi...
uint32_t GetN() const
Returns the n value for the Zipf distribution returned by this RNG stream.
static TypeId GetTypeId()
Register this type.
double m_c
The normalization constant.
double GetAlpha() const
Returns the alpha value for the Zipf distribution returned by this RNG stream.
ZipfRandomVariable()
Creates a Zipf distribution RNG with the default values for n and alpha.
double m_alpha
The alpha value for the Zipf distribution returned by this RNG stream.
uint32_t m_n
The n value for the Zipf distribution returned by this RNG stream.
virtual uint32_t GetInteger()
Get the next random value drawn from the distribution.
double GetValue() override
Get the next random value drawn from the distribution.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
ns3::TypeId declaration; inline and template implementations.