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 *
22 * Modified by Mitch Watrous <watrous@u.washington.edu>
23 *
24 */
25#ifndef RANDOM_VARIABLE_STREAM_H
26#define RANDOM_VARIABLE_STREAM_H
27
28#include "attribute-helper.h"
29#include "object.h"
30#include "type-id.h"
31
32#include <stdint.h>
33
40namespace ns3
41{
42
73class RngStream;
74
99{
100 public:
105 static TypeId GetTypeId();
113 ~RandomVariableStream() override;
114
115 // Delete copy constructor and assignment operator to avoid misuse
118
124 void SetStream(int64_t stream);
125
131 int64_t GetStream() const;
132
137 void SetAntithetic(bool isAntithetic);
138
143 bool IsAntithetic() const;
144
149 virtual double GetValue() = 0;
150
152 // The base implementation returns `(uint32_t)GetValue()`
153 virtual uint32_t GetInteger();
154
155 protected:
160 RngStream* Peek() const;
161
162 private:
165
168
170 int64_t m_stream;
171
172}; // class RandomVariableStream
173
233{
234 public:
239 static TypeId GetTypeId();
240
245
250 double GetMin() const;
251
256 double GetMax() const;
257
264 double GetValue(double min, double max);
265
271
272 // Inherited
277 double GetValue() override;
278
283 uint32_t GetInteger() override;
284
285 private:
287 double m_min;
288
290 double m_max;
291
292}; // class UniformRandomVariable
293
307{
308 public:
313 static TypeId GetTypeId();
314
319
324 double GetConstant() const;
325
330 double GetValue(double constant);
332 uint32_t GetInteger(uint32_t constant);
333
334 // Inherited
335 /*
336 * \copydoc RandomVariableStream::GetValue()
337 * \note This RNG always returns the same value.
338 */
339 double GetValue() override;
340 /* \note This RNG always returns the same value. */
342
343 private:
346
347}; // class ConstantRandomVariable
348
411{
412 public:
417 static TypeId GetTypeId();
418
424
429 double GetMin() const;
430
436 double GetMax() const;
437
443
449 uint32_t GetConsecutive() const;
450
451 // Inherited
452 double GetValue() override;
454
455 private:
457 double m_min;
458
460 double m_max;
461
464
467
469 double m_current;
470
473
476
477}; // class SequentialRandomVariable
478
552{
553 public:
558 static TypeId GetTypeId();
559
565
573 double GetMean() const;
574
579 double GetBound() const;
580
586 double GetValue(double mean, double bound);
587
590
591 // Inherited
592 double GetValue() override;
594
595 private:
597 double m_mean;
598
600 double m_bound;
601
602}; // class ExponentialRandomVariable
603
684{
685 public:
690 static TypeId GetTypeId();
691
697
702 double GetScale() const;
703
708 double GetShape() const;
709
714 double GetBound() const;
715
722 double GetValue(double scale, double shape, double bound);
723
725 uint32_t GetInteger(uint32_t scale, uint32_t shape, uint32_t bound);
726
727 // Inherited
728 double GetValue() override;
730
731 private:
733 double m_scale;
734
736 double m_shape;
737
739 double m_bound;
740
741}; // class ParetoRandomVariable
742
831{
832 public:
837 static TypeId GetTypeId();
838
844
849 double GetScale() const;
850
855 double GetShape() const;
856
861 double GetBound() const;
862
869 double GetValue(double scale, double shape, double bound);
870
872 uint32_t GetInteger(uint32_t scale, uint32_t shape, uint32_t bound);
873
874 // Inherited
875 double GetValue() override;
877
878 private:
880 double m_scale;
881
883 double m_shape;
884
886 double m_bound;
887
888}; // class WeibullRandomVariable
889
968{
969 public:
971 static const double INFINITE_VALUE;
972
977 static TypeId GetTypeId();
978
984
989 double GetMean() const;
990
995 double GetVariance() const;
996
1001 double GetBound() const;
1002
1009 double GetValue(double mean,
1010 double variance,
1012
1014 uint32_t GetInteger(uint32_t mean, uint32_t variance, uint32_t bound);
1015
1016 // Inherited
1017 double GetValue() override;
1019
1020 private:
1022 double m_mean;
1023
1026
1028 double m_bound;
1029
1032
1034 double m_v2;
1036 double m_y;
1037
1038}; // class NormalRandomVariable
1039
1131{
1132 public:
1137 static TypeId GetTypeId();
1138
1144
1149 double GetMu() const;
1150
1155 double GetSigma() const;
1156
1162 double GetValue(double mu, double sigma);
1163
1166
1167 // Inherited
1168 double GetValue() override;
1170
1171 private:
1173 double m_mu;
1174
1176 double m_sigma;
1177
1180
1182 double m_v2;
1183
1185 double m_normal;
1186
1187}; // class LogNormalRandomVariable
1188
1244{
1245 public:
1250 static TypeId GetTypeId();
1251
1257
1262 double GetAlpha() const;
1263
1268 double GetBeta() const;
1269
1275 double GetValue(double alpha, double beta);
1276
1279
1280 // Inherited
1281 double GetValue() override;
1283
1284 private:
1293 double GetNormalValue(double mean, double variance, double bound);
1294
1296 double m_alpha;
1297
1299 double m_beta;
1300
1303
1305 double m_v2;
1307 double m_y;
1308
1309}; // class GammaRandomVariable
1310
1378{
1379 public:
1384 static TypeId GetTypeId();
1385
1391
1396 uint32_t GetK() const;
1397
1402 double GetLambda() const;
1403
1409 double GetValue(uint32_t k, double lambda);
1410
1413
1414 // Inherited
1415 double GetValue() override;
1417
1418 private:
1426 double GetExponentialValue(double mean, double bound);
1427
1430
1432 double m_lambda;
1433
1434}; // class ErlangRandomVariable
1435
1508{
1509 public:
1514 static TypeId GetTypeId();
1515
1521
1526 double GetMean() const;
1527
1532 double GetMin() const;
1533
1538 double GetMax() const;
1539
1546 double GetValue(double mean, double min, double max);
1547
1550
1551 // Inherited
1552 double GetValue() override;
1554
1555 private:
1557 double m_mean;
1558
1560 double m_min;
1561
1563 double m_max;
1564
1565}; // class TriangularRandomVariable
1566
1641{
1642 public:
1647 static TypeId GetTypeId();
1648
1654
1659 uint32_t GetN() const;
1660
1665 double GetAlpha() const;
1666
1673 double GetValue(uint32_t n, double alpha);
1674
1677
1678 // Inherited
1679 double GetValue() override;
1681
1682 private:
1685
1687 double m_alpha;
1688
1690 double m_c;
1691
1692}; // class ZipfRandomVariable
1693
1754{
1755 public:
1760 static TypeId GetTypeId();
1761
1767
1772 double GetAlpha() const;
1773
1778 double GetValue(double alpha);
1779
1782
1783 // Inherited
1784 double GetValue() override;
1786
1787 private:
1789 double m_alpha;
1790
1792 double m_b;
1793
1794}; // class ZetaRandomVariable
1795
1834{
1835 public:
1840 static TypeId GetTypeId();
1841
1848
1856 void SetValueArray(const std::vector<double>& values);
1865 void SetValueArray(const double* values, std::size_t length);
1866
1867 // Inherited
1868 double GetValue() override;
1870
1871 private:
1873 std::size_t m_count;
1874
1876 std::size_t m_next;
1877
1879 double* m_data;
1880
1881}; // class DeterministicRandomVariable
1882
1970{
1971 public:
1976 static TypeId GetTypeId();
1977
1983
1993 void CDF(double v, double c); // Value, prob <= Value
1994
1995 // Inherited
2001 double GetValue() override;
2003
2010 virtual double Interpolate();
2011
2018 bool SetInterpolate(bool interpolate);
2019
2020 private:
2023 {
2024 public:
2026 ValueCDF();
2033 ValueCDF(double v, double c);
2034
2036 double value;
2038 double cdf;
2039 }; // class ValueCDF
2040
2051 void Validate();
2065 bool PreSample(double& value);
2071 double DoSampleCDF(double r);
2079 double DoInterpolate(double r);
2080
2087 friend bool operator<(ValueCDF a, ValueCDF b);
2088
2092 std::vector<ValueCDF> m_emp;
2098
2099}; // class EmpiricalRandomVariable
2100
2101} // namespace ns3
2102
2103#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 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.
Helper to hold one point of the CDF.
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...
std::vector< ValueCDF > m_emp
The vector of CDF points.
void Validate()
Check that the CDF is valid.
friend bool operator<(ValueCDF a, ValueCDF b)
Comparison operator, for use by std::upper_bound.
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:78
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.