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
119 void SetStream (int64_t stream);
120
126 int64_t GetStream (void) const;
127
132 void SetAntithetic (bool isAntithetic);
133
138 bool IsAntithetic (void) const;
139
144 virtual double GetValue (void) = 0;
145
150 virtual uint32_t GetInteger (void) = 0;
151
152protected:
157 RngStream * Peek (void) const;
158
159private:
180
183
186
188 int64_t m_stream;
189
190}; // class RandomVariableStream
191
192
235{
236public:
241 static TypeId GetTypeId (void);
242
247
252 double GetMin (void) const;
253
258 double GetMax (void) const;
259
270 double GetValue (double min, double max);
271
283
284 // Inherited from RandomVariableStream
290 virtual double GetValue (void);
296 virtual uint32_t GetInteger (void);
297
298private:
300 double m_min;
301
303 double m_max;
304
305}; // class UniformRandomVariable
306
307
319{
320public:
325 static TypeId GetTypeId (void);
326
331
336 double GetConstant (void) const;
337
343 double GetValue (double constant);
349 uint32_t GetInteger (uint32_t constant);
350
351 // Inherited from RandomVariableStream
352 /* \note This RNG always returns the same value. */
353 virtual double GetValue (void);
354 /* \note This RNG always returns the same value. */
355 virtual uint32_t GetInteger (void);
356
357private:
360
361}; // class ConstantRandomVariable
362
363
400{
401public:
406 static TypeId GetTypeId (void);
407
413
418 double GetMin (void) const;
419
425 double GetMax (void) const;
426
432
438 uint32_t GetConsecutive (void) const;
439
440 // Inherited from RandomVariableStream
441 virtual double GetValue (void);
442 virtual uint32_t GetInteger (void);
443
444private:
446 double m_min;
447
449 double m_max;
450
453
456
458 double m_current;
459
462
465
466}; // class SequentialRandomVariable
467
468
539{
540public:
545 static TypeId GetTypeId (void);
546
552
560 double GetMean (void) const;
561
566 double GetBound (void) const;
567
575 double GetValue (double mean, double bound);
576
584 uint32_t GetInteger (uint32_t mean, uint32_t bound);
585
586 // Inherited from RandomVariableStream
587 virtual double GetValue (void);
588 virtual uint32_t GetInteger (void);
589
590private:
592 double m_mean;
593
595 double m_bound;
596
597}; // class ExponentialRandomVariable
598
599
641{
642public:
647 static TypeId GetTypeId (void);
648
654
659 double GetScale (void) const;
660
665 double GetShape (void) const;
666
671 double GetBound (void) const;
672
699 double GetValue (double scale, double shape, double bound);
700
727 uint32_t GetInteger (uint32_t scale, uint32_t shape, uint32_t bound);
728
761 virtual double GetValue (void);
762
786 virtual uint32_t GetInteger (void);
787
788private:
790 double m_scale;
791
793 double m_shape;
794
796 double m_bound;
797
798}; // class ParetoRandomVariable
799
800
855{
856public:
861 static TypeId GetTypeId (void);
862
868
873 double GetScale (void) const;
874
879 double GetShape (void) const;
880
885 double GetBound (void) const;
886
912 double GetValue (double scale, double shape, double bound);
913
939 uint32_t GetInteger (uint32_t scale, uint32_t shape, uint32_t bound);
940
968 virtual double GetValue (void);
969
992 virtual uint32_t GetInteger (void);
993
994private:
996 double m_scale;
997
999 double m_shape;
1000
1002 double m_bound;
1003
1004}; // class WeibullRandomVariable
1005
1006
1041{
1042public:
1044 static const double INFINITE_VALUE;
1045
1050 static TypeId GetTypeId (void);
1051
1057
1062 double GetMean (void) const;
1063
1068 double GetVariance (void) const;
1069
1074 double GetBound (void) const;
1075
1112 double GetValue (double mean, double variance, double bound = NormalRandomVariable::INFINITE_VALUE);
1113
1150 uint32_t GetInteger (uint32_t mean, uint32_t variance, uint32_t bound);
1151
1190 virtual double GetValue (void);
1191
1225 virtual uint32_t GetInteger (void);
1226
1227private:
1229 double m_mean;
1230
1233
1235 double m_bound;
1236
1239
1241 double m_v2;
1243 double m_y;
1244
1245}; // class NormalRandomVariable
1246
1247
1292{
1293public:
1298 static TypeId GetTypeId (void);
1299
1305
1310 double GetMu (void) const;
1311
1316 double GetSigma (void) const;
1317
1351 double GetValue (double mu, double sigma);
1352
1387
1424 virtual double GetValue (void);
1425
1457 virtual uint32_t GetInteger (void);
1458
1459private:
1461 double m_mu;
1462
1464 double m_sigma;
1465
1466}; // class LogNormalRandomVariable
1467
1468
1501{
1502public:
1507 static TypeId GetTypeId (void);
1508
1514
1519 double GetAlpha (void) const;
1520
1525 double GetBeta (void) const;
1526
1540 double GetValue (double alpha, double beta);
1541
1556
1573 virtual double GetValue (void);
1574
1586 virtual uint32_t GetInteger (void);
1587
1588private:
1625 double GetNormalValue (double mean, double variance, double bound);
1626
1628 double m_alpha;
1629
1631 double m_beta;
1632
1635
1637 double m_v2;
1639 double m_y;
1640
1641}; // class GammaRandomVariable
1642
1643
1680{
1681public:
1686 static TypeId GetTypeId (void);
1687
1693
1698 uint32_t GetK (void) const;
1699
1704 double GetLambda (void) const;
1705
1719 double GetValue (uint32_t k, double lambda);
1720
1735
1752 virtual double GetValue (void);
1753
1765 virtual uint32_t GetInteger (void);
1766
1767private:
1792 double GetExponentialValue (double mean, double bound);
1793
1796
1798 double m_lambda;
1799
1800}; // class ErlangRandomVariable
1801
1802
1832{
1833public:
1838 static TypeId GetTypeId (void);
1839
1845
1850 double GetMean (void) const;
1851
1856 double GetMin (void) const;
1857
1862 double GetMax (void) const;
1863
1902 double GetValue (double mean, double min, double max);
1903
1943
1984 virtual double GetValue (void);
1985
2021 virtual uint32_t GetInteger (void);
2022
2023private:
2025 double m_mean;
2026
2028 double m_min;
2029
2031 double m_max;
2032
2033}; // class TriangularRandomVariable
2034
2035
2095{
2096public:
2101 static TypeId GetTypeId (void);
2102
2108
2113 uint32_t GetN (void) const;
2114
2119 double GetAlpha (void) const;
2120
2134 double GetValue (uint32_t n, double alpha);
2135
2150
2167 virtual double GetValue (void);
2168
2180 virtual uint32_t GetInteger (void);
2181
2182private:
2185
2187 double m_alpha;
2188
2190 double m_c;
2191
2192}; // class ZipfRandomVariable
2193
2194
2235{
2236public:
2241 static TypeId GetTypeId (void);
2242
2248
2253 double GetAlpha (void) const;
2254
2267 double GetValue (double alpha);
2268
2282
2299 virtual double GetValue (void);
2300
2312 virtual uint32_t GetInteger (void);
2313
2314private:
2316 double m_alpha;
2317
2319 double m_b;
2320
2321}; // class ZetaRandomVariable
2322
2323
2355{
2356public:
2361 static TypeId GetTypeId (void);
2362
2369
2378 void SetValueArray (double* values, std::size_t length);
2379
2384 virtual double GetValue (void);
2385
2390 virtual uint32_t GetInteger (void);
2391
2392private:
2394 std::size_t m_count;
2395
2397 std::size_t m_next;
2398
2400 double* m_data;
2401
2402}; // class DeterministicRandomVariable
2403
2404
2482{
2483public:
2488 static TypeId GetTypeId (void);
2489
2495
2503 void CDF (double v, double c); // Value, prob <= Value
2504
2519 virtual double GetValue (void);
2520
2534 virtual uint32_t GetInteger (void);
2535
2542 virtual double Interpolate (void);
2543
2550 bool SetInterpolate (bool interpolate);
2551
2552private:
2555 {
2556 public:
2558 ValueCDF (void);
2565 ValueCDF (double v, double c);
2566
2568 double value;
2570 double cdf;
2571 }; // class ValueCDF
2572
2583 void Validate (void);
2597 bool PreSample (double & value);
2603 double DoSampleCDF (double r);
2611 double DoInterpolate (double r);
2612
2619 friend
2620 bool operator < (ValueCDF a, ValueCDF b);
2621
2625 std::vector<ValueCDF> m_emp;
2631
2632}; // class EmpiricalRandomVariable
2633
2634
2635} // namespace ns3
2636
2637#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.
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.
RandomVariableStream(const RandomVariableStream &o)
Copy constructor.
RngStream * Peek(void) const
Get the pointer to the underlying RngStream.
RandomVariableStream & operator=(const RandomVariableStream &o)
Assignment operator.
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.
float alpha
Plot alpha value (transparency)
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
ns3::TypeId declaration; inline and template implementations.