A Discrete-Event Network Simulator
API
random-variable-stream.h
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2006 Georgia Tech Research Corporation
4 * Copyright (c) 2011 Mathieu Lacage
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Authors: Rajib Bhattacharjea<raj.b@gatech.edu>
20 * Hadi Arbabi<marbabi@cs.odu.edu>
21 * Mathieu Lacage <mathieu.lacage@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 "type-id.h"
30#include "object.h"
31#include "attribute-helper.h"
32#include <stdint.h>
33
40namespace ns3 {
41
72class RngStream;
73
98{
99public:
104 static TypeId GetTypeId (void);
112 virtual ~RandomVariableStream ();
113
114 // Delete copy constructor and assignment operator to avoid misuse
117
123 void SetStream (int64_t stream);
124
130 int64_t GetStream (void) const;
131
136 void SetAntithetic (bool isAntithetic);
137
142 bool IsAntithetic (void) const;
143
148 virtual double GetValue (void) = 0;
149
154 virtual uint32_t GetInteger (void) = 0;
155
156protected:
161 RngStream * Peek (void) const;
162
163private:
166
169
171 int64_t m_stream;
172
173}; // class RandomVariableStream
174
175
218{
219public:
224 static TypeId GetTypeId (void);
225
230
235 double GetMin (void) const;
236
241 double GetMax (void) const;
242
253 double GetValue (double min, double max);
254
266
267 // Inherited from RandomVariableStream
273 virtual double GetValue (void);
279 virtual uint32_t GetInteger (void);
280
281private:
283 double m_min;
284
286 double m_max;
287
288}; // class UniformRandomVariable
289
290
302{
303public:
308 static TypeId GetTypeId (void);
309
314
319 double GetConstant (void) const;
320
326 double GetValue (double constant);
332 uint32_t GetInteger (uint32_t constant);
333
334 // Inherited from RandomVariableStream
335 /* \note This RNG always returns the same value. */
336 virtual double GetValue (void);
337 /* \note This RNG always returns the same value. */
338 virtual uint32_t GetInteger (void);
339
340private:
343
344}; // class ConstantRandomVariable
345
346
383{
384public:
389 static TypeId GetTypeId (void);
390
396
401 double GetMin (void) const;
402
408 double GetMax (void) const;
409
415
421 uint32_t GetConsecutive (void) const;
422
423 // Inherited from RandomVariableStream
424 virtual double GetValue (void);
425 virtual uint32_t GetInteger (void);
426
427private:
429 double m_min;
430
432 double m_max;
433
436
439
441 double m_current;
442
445
448
449}; // class SequentialRandomVariable
450
451
522{
523public:
528 static TypeId GetTypeId (void);
529
535
543 double GetMean (void) const;
544
549 double GetBound (void) const;
550
558 double GetValue (double mean, double bound);
559
567 uint32_t GetInteger (uint32_t mean, uint32_t bound);
568
569 // Inherited from RandomVariableStream
570 virtual double GetValue (void);
571 virtual uint32_t GetInteger (void);
572
573private:
575 double m_mean;
576
578 double m_bound;
579
580}; // class ExponentialRandomVariable
581
582
624{
625public:
630 static TypeId GetTypeId (void);
631
637
642 double GetScale (void) const;
643
648 double GetShape (void) const;
649
654 double GetBound (void) const;
655
682 double GetValue (double scale, double shape, double bound);
683
710 uint32_t GetInteger (uint32_t scale, uint32_t shape, uint32_t bound);
711
744 virtual double GetValue (void);
745
769 virtual uint32_t GetInteger (void);
770
771private:
773 double m_scale;
774
776 double m_shape;
777
779 double m_bound;
780
781}; // class ParetoRandomVariable
782
783
838{
839public:
844 static TypeId GetTypeId (void);
845
851
856 double GetScale (void) const;
857
862 double GetShape (void) const;
863
868 double GetBound (void) const;
869
895 double GetValue (double scale, double shape, double bound);
896
922 uint32_t GetInteger (uint32_t scale, uint32_t shape, uint32_t bound);
923
951 virtual double GetValue (void);
952
975 virtual uint32_t GetInteger (void);
976
977private:
979 double m_scale;
980
982 double m_shape;
983
985 double m_bound;
986
987}; // class WeibullRandomVariable
988
989
1024{
1025public:
1027 static const double INFINITE_VALUE;
1028
1033 static TypeId GetTypeId (void);
1034
1040
1045 double GetMean (void) const;
1046
1051 double GetVariance (void) const;
1052
1057 double GetBound (void) const;
1058
1095 double GetValue (double mean, double variance, double bound = NormalRandomVariable::INFINITE_VALUE);
1096
1133 uint32_t GetInteger (uint32_t mean, uint32_t variance, uint32_t bound);
1134
1173 virtual double GetValue (void);
1174
1208 virtual uint32_t GetInteger (void);
1209
1210private:
1212 double m_mean;
1213
1216
1218 double m_bound;
1219
1222
1224 double m_v2;
1226 double m_y;
1227
1228}; // class NormalRandomVariable
1229
1230
1275{
1276public:
1281 static TypeId GetTypeId (void);
1282
1288
1293 double GetMu (void) const;
1294
1299 double GetSigma (void) const;
1300
1334 double GetValue (double mu, double sigma);
1335
1370
1407 virtual double GetValue (void);
1408
1440 virtual uint32_t GetInteger (void);
1441
1442private:
1444 double m_mu;
1445
1447 double m_sigma;
1448
1449}; // class LogNormalRandomVariable
1450
1451
1484{
1485public:
1490 static TypeId GetTypeId (void);
1491
1497
1502 double GetAlpha (void) const;
1503
1508 double GetBeta (void) const;
1509
1523 double GetValue (double alpha, double beta);
1524
1538 uint32_t GetInteger (uint32_t alpha, uint32_t beta);
1539
1556 virtual double GetValue (void);
1557
1569 virtual uint32_t GetInteger (void);
1570
1571private:
1608 double GetNormalValue (double mean, double variance, double bound);
1609
1611 double m_alpha;
1612
1614 double m_beta;
1615
1618
1620 double m_v2;
1622 double m_y;
1623
1624}; // class GammaRandomVariable
1625
1626
1663{
1664public:
1669 static TypeId GetTypeId (void);
1670
1676
1681 uint32_t GetK (void) const;
1682
1687 double GetLambda (void) const;
1688
1702 double GetValue (uint32_t k, double lambda);
1703
1718
1735 virtual double GetValue (void);
1736
1748 virtual uint32_t GetInteger (void);
1749
1750private:
1775 double GetExponentialValue (double mean, double bound);
1776
1779
1781 double m_lambda;
1782
1783}; // class ErlangRandomVariable
1784
1785
1815{
1816public:
1821 static TypeId GetTypeId (void);
1822
1828
1833 double GetMean (void) const;
1834
1839 double GetMin (void) const;
1840
1845 double GetMax (void) const;
1846
1885 double GetValue (double mean, double min, double max);
1886
1926
1967 virtual double GetValue (void);
1968
2004 virtual uint32_t GetInteger (void);
2005
2006private:
2008 double m_mean;
2009
2011 double m_min;
2012
2014 double m_max;
2015
2016}; // class TriangularRandomVariable
2017
2018
2078{
2079public:
2084 static TypeId GetTypeId (void);
2085
2091
2096 uint32_t GetN (void) const;
2097
2102 double GetAlpha (void) const;
2103
2117 double GetValue (uint32_t n, double alpha);
2118
2133
2150 virtual double GetValue (void);
2151
2163 virtual uint32_t GetInteger (void);
2164
2165private:
2168
2170 double m_alpha;
2171
2173 double m_c;
2174
2175}; // class ZipfRandomVariable
2176
2177
2218{
2219public:
2224 static TypeId GetTypeId (void);
2225
2231
2236 double GetAlpha (void) const;
2237
2250 double GetValue (double alpha);
2251
2265
2282 virtual double GetValue (void);
2283
2295 virtual uint32_t GetInteger (void);
2296
2297private:
2299 double m_alpha;
2300
2302 double m_b;
2303
2304}; // class ZetaRandomVariable
2305
2306
2338{
2339public:
2344 static TypeId GetTypeId (void);
2345
2352
2361 void SetValueArray (double* values, std::size_t length);
2362
2367 virtual double GetValue (void);
2368
2373 virtual uint32_t GetInteger (void);
2374
2375private:
2377 std::size_t m_count;
2378
2380 std::size_t m_next;
2381
2383 double* m_data;
2384
2385}; // class DeterministicRandomVariable
2386
2387
2465{
2466public:
2471 static TypeId GetTypeId (void);
2472
2478
2486 void CDF (double v, double c); // Value, prob <= Value
2487
2502 virtual double GetValue (void);
2503
2517 virtual uint32_t GetInteger (void);
2518
2525 virtual double Interpolate (void);
2526
2533 bool SetInterpolate (bool interpolate);
2534
2535private:
2538 {
2539 public:
2541 ValueCDF (void);
2548 ValueCDF (double v, double c);
2549
2551 double value;
2553 double cdf;
2554 }; // class ValueCDF
2555
2566 void Validate (void);
2580 bool PreSample (double & value);
2586 double DoSampleCDF (double r);
2594 double DoInterpolate (double r);
2595
2602 friend
2603 bool operator < (ValueCDF a, ValueCDF b);
2604
2608 std::vector<ValueCDF> m_emp;
2614
2615}; // class EmpiricalRandomVariable
2616
2617
2618} // namespace ns3
2619
2620#endif /* RANDOM_VARIABLE_STREAM_H */
#define min(a, b)
Definition: 80211b.c:42
#define max(a, b)
Definition: 80211b.c:43
Attribute helper (ATTRIBUTE_ )macros definition.
The Random Number Generator (RNG) that returns a constant.
ConstantRandomVariable()
Creates a constant RNG with the default constant value.
virtual double GetValue(void)
Get the next random value as a double drawn from the distribution.
double m_constant
The constant value returned by this RNG stream.
static TypeId GetTypeId(void)
Register this type.
virtual uint32_t GetInteger(void)
Get the next random value as an integer drawn from the distribution.
double GetConstant(void) const
Get the constant value returned by this RNG stream.
The Random Number Generator (RNG) that returns a predetermined sequence.
std::size_t m_next
Position of the next value in the array of values.
static TypeId GetTypeId(void)
Register this type.
virtual double GetValue(void)
Returns the next value in the sequence.
double * m_data
Array of values to return in sequence.
DeterministicRandomVariable()
Creates a deterministic RNG that will have a predetermined sequence of values.
void SetValueArray(double *values, std::size_t length)
Sets the array of values that holds the predetermined sequence.
virtual uint32_t GetInteger(void)
Returns the next value in the sequence.
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.
virtual double Interpolate(void)
Returns the next value in the empirical distribution using linear interpolation.
virtual double GetValue(void)
Returns the next value in the empirical distribution.
void CDF(double v, double c)
Specifies a point in the empirical distribution.
EmpiricalRandomVariable(void)
Creates an empirical RNG that has a specified, empirical distribution, and configured for interpolati...
virtual uint32_t GetInteger(void)
Returns the next value in the empirical distribution.
void Validate(void)
Check that the CDF is valid.
bool PreSample(double &value)
Do the initial rng draw and check against the extrema.
static TypeId GetTypeId(void)
Register this type.
double DoSampleCDF(double r)
Sample the CDF as a histogram (without interpolation).
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.
std::vector< ValueCDF > m_emp
The vector of CDF points.
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.
static TypeId GetTypeId(void)
Register this type.
double GetExponentialValue(double mean, double bound)
Returns a random double from an exponential distribution with the specified mean and upper bound.
double GetLambda(void) const
Returns the lambda value for the Erlang distribution returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from an Erlang distribution with the current k and lambda.
uint32_t GetK(void) const
Returns the k value for the Erlang distribution returned by this RNG stream.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from an Erlang distribution with the current k and lambda.
uint32_t m_k
The k value for the Erlang distribution returned by this RNG stream.
ErlangRandomVariable()
Creates an Erlang distribution RNG with the default values for k and lambda.
The exponential distribution Random Number Generator (RNG).
double GetBound(void) const
Get the configured upper bound of this RNG.
ExponentialRandomVariable()
Creates an exponential distribution RNG with the default values for the mean and upper bound.
double GetMean(void) const
Get the configured mean value of this RNG.
double m_mean
The mean value of the unbounded exponential distribution.
double m_bound
The upper bound on values that can be returned by this RNG stream.
virtual double GetValue(void)
Get the next random value as a double drawn from the distribution.
static TypeId GetTypeId(void)
Register this type.
virtual uint32_t GetInteger(void)
Get the next random value as an integer drawn from the distribution.
The gamma distribution Random Number Generator (RNG) that allows stream numbers to be set determinist...
double GetBeta(void) const
Returns the beta value for the gamma distribution returned by this RNG stream.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a gamma distribution with the current alpha and beta.
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.
virtual double GetValue(void)
Returns a random double from a gamma distribution with the current alpha and beta.
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.
static TypeId GetTypeId(void)
Register this type.
double m_v2
The algorithm produces two values at a time.
bool m_nextValid
True if the next normal value is valid.
double GetAlpha(void) const
Returns the alpha 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...
virtual double GetValue(void)
Returns a random double from a log-normal distribution with the current mu and sigma.
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 GetSigma(void) const
Returns the sigma value for the log-normal distribution returned by this RNG stream.
double GetMu(void) const
Returns the mu value for the log-normal distribution returned by this RNG stream.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a log-normal distribution with the current mu and sigma.
static TypeId GetTypeId(void)
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 GetVariance(void) const
Returns the variance value for the normal distribution returned by this RNG stream.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a normal distribution with the current mean,...
static TypeId GetTypeId(void)
Register this type.
double m_mean
The mean value for the normal distribution returned by this RNG stream.
double GetBound(void) const
Returns the bound on values that can be returned by this RNG stream.
static const double INFINITE_VALUE
Large constant to bound the range.
double GetMean(void) const
Returns the mean value for the normal distribution returned by this RNG stream.
double m_variance
The variance value for the normal distribution returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from a normal distribution with the current mean, variance,...
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:88
The Pareto distribution Random Number Generator (RNG).
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,...
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a Pareto distribution with the current mean,...
double GetShape(void) const
Returns the shape parameter for the Pareto distribution returned by this RNG stream.
double m_shape
The shape parameter for the Pareto distribution returned by this RNG stream.
static TypeId GetTypeId(void)
Register this type.
double m_bound
The upper bound on values that can be returned by this RNG stream.
double GetBound(void) const
Returns the upper bound on values that can be returned by this RNG stream.
double GetScale(void) const
Returns the scale parameter for the Pareto distribution returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from a Pareto distribution with the current mean, shape, and upper bound.
The basic uniform Random Number Generator (RNG).
static TypeId GetTypeId(void)
Register this type.
virtual ~RandomVariableStream()
Destructor.
RandomVariableStream & operator=(const RandomVariableStream &)=delete
RandomVariableStream(const RandomVariableStream &)=delete
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
virtual uint32_t GetInteger(void)=0
Get the next random value as an integer drawn from the distribution.
RngStream * Peek(void) const
Get the pointer to the underlying RngStream.
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.
RngStream * m_rng
Pointer to the underlying RngStream.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
int64_t GetStream(void) const
Returns the stream number for the RngStream.
bool IsAntithetic(void) const
Check if antithetic values will be generated.
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.
static TypeId GetTypeId(void)
Register this type.
double m_min
The first value of the sequence.
uint32_t m_consecutive
The number of times each distinct value is repeated.
virtual double GetValue(void)
Get the next random value as a double drawn from the distribution.
Ptr< RandomVariableStream > GetIncrement(void) const
Get the increment for the sequence.
double GetMax(void) const
Get the limit of the sequence, which is (at least) one more than the last value of the sequence.
double m_current
The current sequence value.
double GetMin(void) const
Get the first value of the sequence.
double m_max
Strict upper bound on the sequence.
virtual uint32_t GetInteger(void)
Get the next random value as an integer drawn from the distribution.
Ptr< RandomVariableStream > m_increment
Increment between distinct values.
uint32_t GetConsecutive(void) const
Get the number of times each distinct value of the sequence is repeated before incrementing to the ne...
SequentialRandomVariable()
Creates a sequential RNG with the default values for the sequence parameters.
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 GetMin(void) const
Returns the lower bound for the triangular distribution returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from a triangular distribution with the current mean, min,...
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a triangular distribution with the current mean,...
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.
static TypeId GetTypeId(void)
Register this type.
TriangularRandomVariable()
Creates a triangular distribution RNG with the default values for the mean, lower bound,...
double m_min
The lower bound on values that can be returned by this RNG stream.
double GetMax(void) const
Returns the upper bound on values that can be returned by this RNG stream.
double GetMean(void) const
Returns the mean value 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).
virtual uint32_t GetInteger(void)
Get the next random value as an integer drawn from the distribution.
double GetMax(void) const
Get the upper bound on values returned by GetValue(void).
UniformRandomVariable()
Creates a uniform distribution RNG with the default range.
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.
virtual double GetValue(void)
Get the next random value as a double drawn from the distribution.
static TypeId GetTypeId(void)
Register this type.
double GetMin(void) const
Get the lower bound on randoms returned by GetValue(void).
The Weibull distribution Random Number Generator (RNG) that allows stream numbers to be set determini...
virtual double GetValue(void)
Returns a random double from a Weibull distribution with the current scale, shape,...
double m_shape
The shape parameter for the Weibull distribution returned by this RNG stream.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a Weibull distribution with the current scale,...
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(void) const
Returns the upper bound on values that can be returned by this RNG stream.
WeibullRandomVariable()
Creates a Weibull distribution RNG with the default values for the scale, shape, and upper bound.
double GetScale(void) const
Returns the scale parameter for the Weibull distribution returned by this RNG stream.
double GetShape(void) const
Returns the shape parameter for the Weibull distribution returned by this RNG stream.
static TypeId GetTypeId(void)
Register this type.
The zeta distribution Random Number Generator (RNG) that allows stream numbers to be set deterministi...
double GetAlpha(void) const
Returns the alpha value for the zeta distribution returned by this RNG stream.
double m_alpha
The alpha value for the zeta distribution returned by this RNG stream.
static TypeId GetTypeId(void)
Register this type.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a zeta distribution with the current alpha.
ZetaRandomVariable()
Creates a zeta distribution RNG with the default value for alpha.
virtual double GetValue(void)
Returns a random double from a zeta distribution with the current alpha.
double m_b
Just for calculus simplifications.
The Zipf distribution Random Number Generator (RNG) that allows stream numbers to be set deterministi...
double GetAlpha(void) const
Returns the alpha value for the Zipf distribution returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from a Zipf distribution with the current n and alpha.
double m_c
The normalization constant.
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.
static TypeId GetTypeId(void)
Register this type.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a Zipf distribution with the current n and alpha.
uint32_t GetN(void) const
Returns the n value for the Zipf distribution returned by this RNG stream.
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.