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 <map>
33#include <stdint.h>
34
41namespace ns3
42{
43
74class RngStream;
75
100{
101 public:
106 static TypeId GetTypeId();
114 ~RandomVariableStream() override;
115
116 // Delete copy constructor and assignment operator to avoid misuse
119
125 void SetStream(int64_t stream);
126
132 int64_t GetStream() const;
133
138 void SetAntithetic(bool isAntithetic);
139
144 bool IsAntithetic() const;
145
150 virtual double GetValue() = 0;
151
153 // The base implementation returns `(uint32_t)GetValue()`
154 virtual uint32_t GetInteger();
155
156 protected:
161 RngStream* Peek() const;
162
163 private:
166
169
171 int64_t m_stream;
172
173}; // class RandomVariableStream
174
234{
235 public:
240 static TypeId GetTypeId();
241
246
251 double GetMin() const;
252
257 double GetMax() const;
258
265 double GetValue(double min, double max);
266
272
273 // Inherited
278 double GetValue() override;
279
284 uint32_t GetInteger() override;
285
286 private:
288 double m_min;
289
291 double m_max;
292
293}; // class UniformRandomVariable
294
308{
309 public:
314 static TypeId GetTypeId();
315
320
325 double GetConstant() const;
326
331 double GetValue(double constant);
333 uint32_t GetInteger(uint32_t constant);
334
335 // Inherited
336 /*
337 * \copydoc RandomVariableStream::GetValue()
338 * \note This RNG always returns the same value.
339 */
340 double GetValue() override;
341 /* \note This RNG always returns the same value. */
343
344 private:
347
348}; // class ConstantRandomVariable
349
412{
413 public:
418 static TypeId GetTypeId();
419
425
430 double GetMin() const;
431
437 double GetMax() const;
438
444
450 uint32_t GetConsecutive() const;
451
452 // Inherited
453 double GetValue() override;
455
456 private:
458 double m_min;
459
461 double m_max;
462
465
468
470 double m_current;
471
474
477
478}; // class SequentialRandomVariable
479
553{
554 public:
559 static TypeId GetTypeId();
560
566
574 double GetMean() const;
575
580 double GetBound() const;
581
587 double GetValue(double mean, double bound);
588
591
592 // Inherited
593 double GetValue() override;
595
596 private:
598 double m_mean;
599
601 double m_bound;
602
603}; // class ExponentialRandomVariable
604
685{
686 public:
691 static TypeId GetTypeId();
692
698
703 double GetScale() const;
704
709 double GetShape() const;
710
715 double GetBound() const;
716
723 double GetValue(double scale, double shape, double bound);
724
726 uint32_t GetInteger(uint32_t scale, uint32_t shape, uint32_t bound);
727
728 // Inherited
729 double GetValue() override;
731
732 private:
734 double m_scale;
735
737 double m_shape;
738
740 double m_bound;
741
742}; // class ParetoRandomVariable
743
832{
833 public:
838 static TypeId GetTypeId();
839
845
850 double GetScale() const;
851
856 double GetShape() const;
857
862 double GetBound() const;
863
870 double GetValue(double scale, double shape, double bound);
871
873 uint32_t GetInteger(uint32_t scale, uint32_t shape, uint32_t bound);
874
875 // Inherited
876 double GetValue() override;
878
879 private:
881 double m_scale;
882
884 double m_shape;
885
887 double m_bound;
888
889}; // class WeibullRandomVariable
890
969{
970 public:
972 static const double INFINITE_VALUE;
973
978 static TypeId GetTypeId();
979
985
990 double GetMean() const;
991
996 double GetVariance() const;
997
1002 double GetBound() const;
1003
1010 double GetValue(double mean,
1011 double variance,
1013
1015 uint32_t GetInteger(uint32_t mean, uint32_t variance, uint32_t bound);
1016
1017 // Inherited
1018 double GetValue() override;
1020
1021 private:
1023 double m_mean;
1024
1027
1029 double m_bound;
1030
1033
1035 double m_v2;
1037 double m_y;
1038
1039}; // class NormalRandomVariable
1040
1132{
1133 public:
1138 static TypeId GetTypeId();
1139
1145
1150 double GetMu() const;
1151
1156 double GetSigma() const;
1157
1163 double GetValue(double mu, double sigma);
1164
1167
1168 // Inherited
1169 double GetValue() override;
1171
1172 private:
1174 double m_mu;
1175
1177 double m_sigma;
1178
1181
1183 double m_v2;
1184
1186 double m_normal;
1187
1188}; // class LogNormalRandomVariable
1189
1245{
1246 public:
1251 static TypeId GetTypeId();
1252
1258
1263 double GetAlpha() const;
1264
1269 double GetBeta() const;
1270
1276 double GetValue(double alpha, double beta);
1277
1280
1281 // Inherited
1282 double GetValue() override;
1284
1285 private:
1294 double GetNormalValue(double mean, double variance, double bound);
1295
1297 double m_alpha;
1298
1300 double m_beta;
1301
1304
1306 double m_v2;
1308 double m_y;
1309
1310}; // class GammaRandomVariable
1311
1379{
1380 public:
1385 static TypeId GetTypeId();
1386
1392
1397 uint32_t GetK() const;
1398
1403 double GetLambda() const;
1404
1410 double GetValue(uint32_t k, double lambda);
1411
1414
1415 // Inherited
1416 double GetValue() override;
1418
1419 private:
1427 double GetExponentialValue(double mean, double bound);
1428
1431
1433 double m_lambda;
1434
1435}; // class ErlangRandomVariable
1436
1509{
1510 public:
1515 static TypeId GetTypeId();
1516
1522
1527 double GetMean() const;
1528
1533 double GetMin() const;
1534
1539 double GetMax() const;
1540
1547 double GetValue(double mean, double min, double max);
1548
1551
1552 // Inherited
1553 double GetValue() override;
1555
1556 private:
1558 double m_mean;
1559
1561 double m_min;
1562
1564 double m_max;
1565
1566}; // class TriangularRandomVariable
1567
1642{
1643 public:
1648 static TypeId GetTypeId();
1649
1655
1660 uint32_t GetN() const;
1661
1666 double GetAlpha() const;
1667
1674 double GetValue(uint32_t n, double alpha);
1675
1678
1679 // Inherited
1680 double GetValue() override;
1682
1683 private:
1686
1688 double m_alpha;
1689
1691 double m_c;
1692
1693}; // class ZipfRandomVariable
1694
1755{
1756 public:
1761 static TypeId GetTypeId();
1762
1768
1773 double GetAlpha() const;
1774
1779 double GetValue(double alpha);
1780
1783
1784 // Inherited
1785 double GetValue() override;
1787
1788 private:
1790 double m_alpha;
1791
1793 double m_b;
1794
1795}; // class ZetaRandomVariable
1796
1835{
1836 public:
1841 static TypeId GetTypeId();
1842
1849
1857 void SetValueArray(const std::vector<double>& values);
1866 void SetValueArray(const double* values, std::size_t length);
1867
1868 // Inherited
1869 double GetValue() override;
1871
1872 private:
1874 std::size_t m_count;
1875
1877 std::size_t m_next;
1878
1880 double* m_data;
1881
1882}; // class DeterministicRandomVariable
1883
1971{
1972 public:
1977 static TypeId GetTypeId();
1978
1984
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:
2031 void Validate();
2045 bool PreSample(double& value);
2051 double DoSampleCDF(double r);
2059 double DoInterpolate(double r);
2060
2068 std::map<double, double> m_empCdf;
2074
2075}; // class EmpiricalRandomVariable
2076
2077} // namespace ns3
2078
2079#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.
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: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.