A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
34 namespace ns3 {
35 
66 class RngStream;
67 
88 {
89 public:
90  static TypeId GetTypeId (void);
92  virtual ~RandomVariableStream();
93 
98  void SetStream (int64_t stream);
99 
104  int64_t GetStream(void) const;
105 
111  void SetAntithetic(bool isAntithetic);
112 
118  bool IsAntithetic(void) const;
119 
124  virtual double GetValue (void) = 0;
125 
130  virtual uint32_t GetInteger (void) = 0;
131 
132 protected:
136  RngStream *Peek(void) const;
137 
138 private:
139  // you can't copy these objects.
140  // Theoretically, it is possible to give them good copy semantics
141  // but not enough time to iron out the details.
144 
147 
150 
152  int64_t m_stream;
153 };
154 
184 {
185 public:
186  static TypeId GetTypeId (void);
187 
192 
197  double GetMin (void) const;
198 
203  double GetMax (void) const;
204 
224  double GetValue (double min, double max);
225 
245  uint32_t GetInteger (uint32_t min, uint32_t max);
246 
269  virtual double GetValue (void);
270 
288  virtual uint32_t GetInteger (void);
289 private:
291  double m_min;
292 
294  double m_max;
295 };
296 
304 {
305 public:
306  static TypeId GetTypeId (void);
307 
312 
317  double GetConstant (void) const;
318 
323  double GetValue (double constant);
328  uint32_t GetInteger (uint32_t constant);
329 
334  virtual double GetValue (void);
335 
340  virtual uint32_t GetInteger (void);
341 
342 private:
344  double m_constant;
345 };
346 
358 {
359 public:
360  static TypeId GetTypeId (void);
361 
366 
371  double GetMin (void) const;
372 
377  double GetMax (void) const;
378 
384 
389  uint32_t GetConsecutive (void) const;
390 
404  virtual double GetValue (void);
405 
410  virtual uint32_t GetInteger (void);
411 
412 private:
414  double m_min;
415 
417  double m_max;
418 
421 
423  uint32_t m_consecutive;
424 
426  double m_current;
427 
430 
433 
434 };
435 
471 {
472 public:
473  static TypeId GetTypeId (void);
474 
480 
485  double GetMean (void) const;
486 
491  double GetBound (void) const;
492 
517  double GetValue (double mean, double bound);
518 
543  uint32_t GetInteger (uint32_t mean, uint32_t bound);
544 
572  virtual double GetValue (void);
573 
596  virtual uint32_t GetInteger (void);
597 
598 private:
600  double m_mean;
601 
603  double m_bound;
604 };
605 
651 {
652 public:
653  static TypeId GetTypeId (void);
654 
660 
665  double GetMean (void) const;
666 
671  double GetShape (void) const;
672 
677  double GetBound (void) const;
678 
710  double GetValue (double mean, double shape, double bound);
711 
743  uint32_t GetInteger (uint32_t mean, uint32_t shape, uint32_t bound);
744 
778  virtual double GetValue (void);
779 
808  virtual uint32_t GetInteger (void);
809 
810 private:
812  double m_mean;
813 
815  double m_shape;
816 
818  double m_bound;
819 };
820 
875 {
876 public:
877  static TypeId GetTypeId (void);
878 
884 
889  double GetScale (void) const;
890 
895  double GetShape (void) const;
896 
901  double GetBound (void) const;
902 
928  double GetValue (double scale, double shape, double bound);
929 
955  uint32_t GetInteger (uint32_t scale, uint32_t shape, uint32_t bound);
956 
984  virtual double GetValue (void);
985 
1008  virtual uint32_t GetInteger (void);
1009 
1010 private:
1012  double m_scale;
1013 
1015  double m_shape;
1016 
1018  double m_bound;
1019 };
1020 
1055 {
1056 public:
1057  static const double INFINITE_VALUE;
1058 
1059  static TypeId GetTypeId (void);
1060 
1066 
1071  double GetMean (void) const;
1072 
1077  double GetVariance (void) const;
1078 
1083  double GetBound (void) const;
1084 
1121  double GetValue (double mean, double variance, double bound = NormalRandomVariable::INFINITE_VALUE);
1122 
1159  uint32_t GetInteger (uint32_t mean, uint32_t variance, uint32_t bound);
1160 
1199  virtual double GetValue (void);
1200 
1234  virtual uint32_t GetInteger (void);
1235 
1236 private:
1238  double m_mean;
1239 
1241  double m_variance;
1242 
1244  double m_bound;
1245 
1248 
1250  double m_next;
1251 };
1252 
1297 {
1298 public:
1299  static TypeId GetTypeId (void);
1300 
1306 
1311  double GetMu (void) const;
1312 
1317  double GetSigma (void) const;
1318 
1352  double GetValue (double mu, double sigma);
1353 
1387  uint32_t GetInteger (uint32_t mu, uint32_t sigma);
1388 
1425  virtual double GetValue (void);
1426 
1458  virtual uint32_t GetInteger (void);
1459 
1460 private:
1462  double m_mu;
1463 
1465  double m_sigma;
1466 };
1467 
1500 {
1501 public:
1502  static TypeId GetTypeId (void);
1503 
1509 
1514  double GetAlpha (void) const;
1515 
1520  double GetBeta (void) const;
1521 
1535  double GetValue (double alpha, double beta);
1536 
1550  uint32_t GetInteger (uint32_t alpha, uint32_t beta);
1551 
1568  virtual double GetValue (void);
1569 
1581  virtual uint32_t GetInteger (void);
1582 
1583 private:
1620  double GetNormalValue (double mean, double variance, double bound);
1621 
1623  double m_alpha;
1624 
1626  double m_beta;
1627 
1630 
1632  double m_next;
1633 
1634 };
1635 
1672 {
1673 public:
1674  static TypeId GetTypeId (void);
1675 
1681 
1686  uint32_t GetK (void) const;
1687 
1692  double GetLambda (void) const;
1693 
1707  double GetValue (uint32_t k, double lambda);
1708 
1722  uint32_t GetInteger (uint32_t k, uint32_t lambda);
1723 
1740  virtual double GetValue (void);
1741 
1753  virtual uint32_t GetInteger (void);
1754 
1755 private:
1780  double GetExponentialValue (double mean, double bound);
1781 
1783  uint32_t m_k;
1784 
1786  double m_lambda;
1787 
1788 };
1789 
1819 {
1820 public:
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 
1925  uint32_t GetInteger (uint32_t mean, uint32_t min, uint32_t max);
1926 
1967  virtual double GetValue (void);
1968 
2004  virtual uint32_t GetInteger (void);
2005 
2006 private:
2008  double m_mean;
2009 
2011  double m_min;
2012 
2014  double m_max;
2015 };
2016 
2076 {
2077 public:
2078  static TypeId GetTypeId (void);
2079 
2084  ZipfRandomVariable ();
2085 
2090  uint32_t GetN (void) const;
2091 
2096  double GetAlpha (void) const;
2097 
2111  double GetValue (uint32_t n, double alpha);
2112 
2126  uint32_t GetInteger (uint32_t n, uint32_t alpha);
2127 
2144  virtual double GetValue (void);
2145 
2157  virtual uint32_t GetInteger (void);
2158 
2159 private:
2161  uint32_t m_n;
2162 
2164  double m_alpha;
2165 
2167  double m_c;
2168 };
2169 
2210 {
2211 public:
2212  static TypeId GetTypeId (void);
2213 
2218  ZetaRandomVariable ();
2219 
2224  double GetAlpha (void) const;
2225 
2238  double GetValue (double alpha);
2239 
2252  uint32_t GetInteger (uint32_t alpha);
2253 
2270  virtual double GetValue (void);
2271 
2283  virtual uint32_t GetInteger (void);
2284 
2285 private:
2287  double m_alpha;
2288 
2290  double m_b;
2291 };
2292 
2324 {
2325 public:
2326  static TypeId GetTypeId (void);
2327 
2333  virtual ~DeterministicRandomVariable ();
2334 
2343  void SetValueArray (double* values, uint64_t length);
2344 
2349  virtual double GetValue (void);
2350 
2355  virtual uint32_t GetInteger (void);
2356 
2357 private:
2359  uint64_t m_count;
2360 
2362  uint64_t m_next;
2363 
2365  double* m_data;
2366 };
2367 
2400 {
2401 public:
2402  static TypeId GetTypeId (void);
2403 
2409 
2415  void CDF (double v, double c); // Value, prob <= Value
2416 
2428  virtual double GetValue (void);
2429 
2441  virtual uint32_t GetInteger (void);
2442 
2443 private:
2444  class ValueCDF
2445  {
2446 public:
2447  ValueCDF ();
2448  ValueCDF (double v, double c);
2449  ValueCDF (const ValueCDF& c);
2450  double value;
2451  double cdf;
2452  };
2453  virtual void Validate (); // Insure non-decreasing emiprical values
2454  virtual double Interpolate (double, double, double, double, double);
2455  bool validated; // True if non-decreasing validated
2456  std::vector<ValueCDF> emp; // Empicical CDF
2457 };
2458 
2459 } // namespace ns3
2460 
2461 #endif /* RANDOM_VARIABLE_STREAM_H */
The Random Number Generator (RNG) that returns a predetermined sequence.
double m_scale
The scale parameter for the Weibull distribution returned by this RNG stream.
double m_current
The current sequence value.
ExponentialRandomVariable()
Creates a exponential distribution RNG with the default values for the mean and upper bound...
double GetSigma(void) const
Returns the sigma value for the log-normal distribution returned by this RNG stream.
double m_next
The algorithm produces two values at a time.
double GetAlpha(void) const
Returns the alpha value for the Zipf distribution returned by this RNG stream.
void SetAntithetic(bool isAntithetic)
Specifies whether antithetic values should be generated.
NormalRandomVariable()
Creates a normal distribution RNG with the default values for the mean, variance, and bound...
virtual double GetValue(void)
Returns the next value in the empirical distribution.
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
WeibullRandomVariable()
Creates a Weibull distribution RNG with the default values for the scale, shape, and upper bound...
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a Weibull distribution with the current scale, shape, and upper bound.
double GetAlpha(void) const
Returns the alpha value for the gamma distribution returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from an exponential distribution with the current mean and upper bound...
double m_alpha
The alpha value for the Zipf distribution returned by this RNG stream.
double GetLambda(void) const
Returns the lambda value for the Erlang distribution returned by this RNG stream. ...
double GetBound(void) const
Returns the upper bound on values that can be returned by this RNG stream.
double m_mean
The mean value for the triangular distribution returned by this RNG stream.
SequentialRandomVariable()
Creates a sequential RNG with the default values for the sequence parameters.
double m_bound
The upper bound on values that can be returned by this RNG stream.
The exponential distribution Random Number Generator (RNG) that allows stream numbers to be set deter...
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a triangular distribution with the current mean...
The Random Number Generator (RNG) that returns a sequential list of values.
The normal (Gaussian) distribution Random Number Generator (RNG) that allows stream numbers to be set...
uint64_t m_count
Position in the array of values.
double GetExponentialValue(double mean, double bound)
Returns a random double from an exponential distribution with the specified mean and upper bound...
double m_mean
The mean parameter for the Pareto distribution returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from a normal distribution with the current mean, variance, and bound.
double m_min
The lower bound on values that can be returned by this RNG stream.
double m_shape
The shape parameter for the Weibull distribution returned by this RNG stream.
uint32_t GetN(void) const
Returns the n value for the Zipf distribution returned by this RNG stream.
int64_t m_stream
The stream number for this RNG stream.
double m_constant
The constant value returned by this RNG stream.
double m_min
The first value of the sequence.
double GetConstant(void) const
Returns the constant value returned by this RNG stream.
double GetMin(void) const
Returns the first value of the sequence.
Ptr< RandomVariableStream > m_increment
The sequence random variable increment.
bool m_nextValid
True if the next value is valid.
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
virtual double Interpolate(double, double, double, double, double)
double m_bound
The upper bound on values that can be returned by this RNG stream.
DeterministicRandomVariable()
Creates a deterministic RNG that will have a predetermined sequence of values.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a gamma distribution with the current alpha and beta...
double m_shape
The shape parameter for the Pareto distribution returned by this RNG stream.
uint32_t m_n
The n value for the Zipf distribution returned by this RNG stream.
int64_t GetStream(void) const
Returns the stream number for this RNG stream.
virtual double GetValue(void)
Returns the next value in the sequence returned by this RNG stream.
RngStream * m_rng
Pointer to the underlying RNG stream.
Combined Multiple-Recursive Generator MRG32k3a.
Definition: rng-stream.h:38
double * m_data
Array of values to return in sequence.
Ptr< RandomVariableStream > GetIncrement(void) const
Returns the random variable increment for the sequence.
virtual uint32_t GetInteger(void)=0
Returns a random integer integer from the underlying distribution.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a uniform distribution over the interval [min,max] including both ends, where min and max are the current lower and upper bounds.
double m_lambda
The lambda value for the Erlang distribution returned by this RNG stream.
double GetMin(void) const
Returns the lower bound on values that can be returned by this RNG stream.
double m_alpha
The alpha value for the zeta distribution returned by this RNG stream.
virtual double GetValue(void)
Returns the next value in the sequence.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a Pareto distribution with the current mean, shape, and upper bound.
LogNormalRandomVariable()
Creates a log-normal distribution RNG with the default values for mu and sigma.
double GetScale(void) const
Returns the scale parameter for the Weibull 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...
double GetMin(void) const
Returns the lower bound for the triangular distribution returned by this RNG stream.
uint32_t GetK(void) const
Returns the k value for the Erlang distribution returned by this RNG stream.
double m_max
One more than the last value of the sequence.
uint32_t GetConsecutive(void) const
Returns the number of times each member of the sequence is repeated.
ZetaRandomVariable()
Creates a zeta distribution RNG with the default value for alpha.
uint32_t m_k
The k value for the Erlang distribution returned by this RNG stream.
The gamma distribution Random Number Generator (RNG) that allows stream numbers to be set determinist...
virtual double GetValue(void)
Returns a random double from a triangular distribution with the current mean, min, and max.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a Zipf distribution with the current n and alpha...
void CDF(double v, double c)
Specifies a point in the empirical distribution.
virtual uint32_t GetInteger(void)
Returns an integer cast of the constant value returned by this RNG stream.
double m_sigma
The sigma value for the log-normal distribution returned by this RNG stream.
ZipfRandomVariable()
Creates a Zipf distribution RNG with the default values for n and alpha.
The uniform distribution Random Number Generator (RNG) that allows stream numbers to be set determini...
GammaRandomVariable()
Creates a gamma distribution RNG with the default values for alpha and beta.
double GetMu(void) const
Returns the mu value for the log-normal distribution returned by this RNG stream. ...
uint64_t m_next
Position of the next value in the array of values.
double m_c
The normalization constant.
uint32_t m_consecutive
The number of times each member of the sequence is repeated.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a normal distribution with the current mean, variance, and bound.
double GetMax(void) const
Returns the upper bound on values that can be returned by this RNG stream.
double m_variance
The variance value for the normal distribution returned by this RNG stream.
double GetMean(void) const
Returns the mean value of the random variables returned by this RNG stream.
double m_mean
The mean value of the random variables returned by this RNG stream.
double GetVariance(void) const
Returns the variance value for the normal distribution returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from a Zipf distribution with the current n and alpha.
virtual double GetValue(void)
Returns the constant value returned by this RNG stream.
bool m_isCurrentSet
Indicates if the current sequence value has been set.
virtual double GetValue(void)
Returns a random double from an Erlang distribution with the current k and lambda.
double m_mean
The mean value for the normal distribution returned by this RNG stream.
double m_max
The upper bound on values that can be returned by this RNG stream.
uint32_t m_currentConsecutive
The number of times the sequence has been repeated.
double GetMean(void) const
Returns the mean value for the normal distribution returned by this RNG stream.
void SetValueArray(double *values, uint64_t length)
Sets the array of values that holds the predetermined sequence.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from an exponential distribution with the current mean and upper bo...
double m_bound
The upper bound on values that can be returned by this RNG stream.
EmpiricalRandomVariable()
Creates an empirical RNG that has a specified, empirical distribution.
double m_beta
The beta value for the gamma distribution returned by this RNG stream.
bool IsAntithetic(void) const
Returns true if antithetic values should be generated.
virtual double GetValue(void)
Returns a random double from a Weibull distribution with the current scale, shape, and upper bound.
double m_alpha
The alpha value for the gamma distribution returned by this RNG stream.
virtual uint32_t GetInteger(void)
Returns the next value in the sequence.
double GetNormalValue(double mean, double variance, double bound)
Returns a random double from a normal distribution with the specified mean, variance, and bound.
double GetMax(void) const
Returns one more than the last value of the sequence.
virtual double GetValue(void)
Returns a random double from a log-normal distribution with the current mu and sigma.
virtual uint32_t GetInteger(void)
Returns a random unsigned integer from a zeta distribution with the current alpha.
ParetoRandomVariable()
Creates a Pareto distribution RNG with the default values for the mean, the shape, and upper bound.
double GetBound(void) const
Returns the bound on values that can be returned by this RNG stream.
The Zipf distribution Random Number Generator (RNG) that allows stream numbers to be set deterministi...
The Random Number Generator (RNG) that allows stream numbers to be set deterministically.
virtual uint32_t GetInteger(void)
Returns an integer cast of the next value in the sequence returned by this RNG stream.
double GetBound(void) const
Returns the upper bound on values that can be returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from a zeta distribution with the current alpha.
double GetShape(void) const
Returns the shape parameter for the Weibull distribution returned by this RNG stream.
virtual uint32_t GetInteger(void)
Returns the next value in the empirical distribution.
double m_bound
The bound on values that can be returned by this RNG stream.
double GetMean(void) const
Returns the mean parameter for the Pareto 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...
double m_next
The algorithm produces two normal values at a time.
RngStream * Peek(void) const
Returns a pointer to the underlying RNG stream.
double m_b
Just for calculus simplifications.
UniformRandomVariable()
Creates a uniform distribution RNG with the default range.
The triangular distribution Random Number Generator (RNG) that allows stream numbers to be set determ...
double m_max
The upper bound on values that can be returned by this RNG stream.
ErlangRandomVariable()
Creates an Erlang distribution RNG with the default values for k and lambda.
bool m_nextValid
True if the next normal value is valid.
double GetBound(void) const
Returns the upper bound on values that can be returned by this RNG stream.
The Erlang distribution Random Number Generator (RNG) that allows stream numbers to be set determinis...
a base class which provides memory management and object aggregation
Definition: object.h:64
virtual double GetValue(void)
Returns a random double from a Pareto distribution with the current mean, shape, and upper bound...
The Random Number Generator (RNG) that has a specified empirical distribution.
double GetBeta(void) const
Returns the beta value for the gamma distribution returned by this RNG stream.
virtual double GetValue(void)
Returns a random double from the uniform distribution with the range [min,max), where min and max are...
virtual double GetValue(void)
Returns a random double from a gamma distribution with the current alpha and beta.
double GetAlpha(void) const
Returns the alpha value for the zeta distribution returned by this RNG stream.
The log-normal distribution Random Number Generator (RNG) that allows stream numbers to be set determ...
a unique identifier for an interface.
Definition: type-id.h:49
TriangularRandomVariable()
Creates a triangular distribution RNG with the default values for the mean, lower bound...
ConstantRandomVariable()
Creates a constant RNG with the default constant value.
The Pareto distribution Random Number Generator (RNG) that allows stream numbers to be set determinis...
double GetMean(void) const
Returns the mean value for the triangular distribution returned by this RNG stream.
double m_mu
The mu value for the log-normal distribution returned by this RNG stream.
double m_min
The lower bound on values that can be returned by this RNG stream.
RandomVariableStream & operator=(const RandomVariableStream &o)
The Random Number Generator (RNG) that returns a constant.
The Weibull distribution Random Number Generator (RNG) that allows stream numbers to be set determini...
The zeta distribution Random Number Generator (RNG) that allows stream numbers to be set deterministi...
double GetShape(void) const
Returns the shape parameter for the Pareto distribution returned by this RNG stream.
bool m_isAntithetic
Indicates if antithetic values should be generated by this RNG stream.
double GetMax(void) const
Returns the upper bound on values that can be returned by this RNG stream.