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 
34 namespace ns3 {
35 
66 class RngStream;
67 
88 {
89 public:
94  static TypeId GetTypeId (void);
96  virtual ~RandomVariableStream();
97 
102  void SetStream (int64_t stream);
103 
108  int64_t GetStream(void) const;
109 
115  void SetAntithetic(bool isAntithetic);
116 
122  bool IsAntithetic(void) const;
123 
128  virtual double GetValue (void) = 0;
129 
134  virtual uint32_t GetInteger (void) = 0;
135 
136 protected:
140  RngStream *Peek(void) const;
141 
142 private:
143  // you can't copy these objects.
144  // Theoretically, it is possible to give them good copy semantics
145  // but not enough time to iron out the details.
148 
151 
154 
156  int64_t m_stream;
157 };
158 
188 {
189 public:
190  static TypeId GetTypeId (void);
191 
196 
201  double GetMin (void) const;
202 
207  double GetMax (void) const;
208 
228  double GetValue (double min, double max);
229 
249  uint32_t GetInteger (uint32_t min, uint32_t max);
250 
273  virtual double GetValue (void);
274 
292  virtual uint32_t GetInteger (void);
293 private:
295  double m_min;
296 
298  double m_max;
299 };
300 
308 {
309 public:
310  static TypeId GetTypeId (void);
311 
316 
321  double GetConstant (void) const;
322 
327  double GetValue (double constant);
332  uint32_t GetInteger (uint32_t constant);
333 
338  virtual double GetValue (void);
339 
344  virtual uint32_t GetInteger (void);
345 
346 private:
348  double m_constant;
349 };
350 
362 {
363 public:
364  static TypeId GetTypeId (void);
365 
370 
375  double GetMin (void) const;
376 
381  double GetMax (void) const;
382 
388 
393  uint32_t GetConsecutive (void) const;
394 
408  virtual double GetValue (void);
409 
414  virtual uint32_t GetInteger (void);
415 
416 private:
418  double m_min;
419 
421  double m_max;
422 
425 
427  uint32_t m_consecutive;
428 
430  double m_current;
431 
434 
437 
438 };
439 
475 {
476 public:
477  static TypeId GetTypeId (void);
478 
484 
489  double GetMean (void) const;
490 
495  double GetBound (void) const;
496 
521  double GetValue (double mean, double bound);
522 
547  uint32_t GetInteger (uint32_t mean, uint32_t bound);
548 
576  virtual double GetValue (void);
577 
600  virtual uint32_t GetInteger (void);
601 
602 private:
604  double m_mean;
605 
607  double m_bound;
608 };
609 
655 {
656 public:
657  static TypeId GetTypeId (void);
658 
664 
669  double GetMean (void) const;
670 
675  double GetShape (void) const;
676 
681  double GetBound (void) const;
682 
714  double GetValue (double mean, double shape, double bound);
715 
747  uint32_t GetInteger (uint32_t mean, uint32_t shape, uint32_t bound);
748 
782  virtual double GetValue (void);
783 
812  virtual uint32_t GetInteger (void);
813 
814 private:
816  double m_mean;
817 
819  double m_shape;
820 
822  double m_bound;
823 };
824 
879 {
880 public:
881  static TypeId GetTypeId (void);
882 
888 
893  double GetScale (void) const;
894 
899  double GetShape (void) const;
900 
905  double GetBound (void) const;
906 
932  double GetValue (double scale, double shape, double bound);
933 
959  uint32_t GetInteger (uint32_t scale, uint32_t shape, uint32_t bound);
960 
988  virtual double GetValue (void);
989 
1012  virtual uint32_t GetInteger (void);
1013 
1014 private:
1016  double m_scale;
1017 
1019  double m_shape;
1020 
1022  double m_bound;
1023 };
1024 
1059 {
1060 public:
1061  static const double INFINITE_VALUE;
1062 
1063  static TypeId GetTypeId (void);
1064 
1070 
1075  double GetMean (void) const;
1076 
1081  double GetVariance (void) const;
1082 
1087  double GetBound (void) const;
1088 
1125  double GetValue (double mean, double variance, double bound = NormalRandomVariable::INFINITE_VALUE);
1126 
1163  uint32_t GetInteger (uint32_t mean, uint32_t variance, uint32_t bound);
1164 
1203  virtual double GetValue (void);
1204 
1238  virtual uint32_t GetInteger (void);
1239 
1240 private:
1242  double m_mean;
1243 
1245  double m_variance;
1246 
1248  double m_bound;
1249 
1252 
1254  double m_next;
1255 };
1256 
1301 {
1302 public:
1303  static TypeId GetTypeId (void);
1304 
1310 
1315  double GetMu (void) const;
1316 
1321  double GetSigma (void) const;
1322 
1356  double GetValue (double mu, double sigma);
1357 
1391  uint32_t GetInteger (uint32_t mu, uint32_t sigma);
1392 
1429  virtual double GetValue (void);
1430 
1462  virtual uint32_t GetInteger (void);
1463 
1464 private:
1466  double m_mu;
1467 
1469  double m_sigma;
1470 };
1471 
1504 {
1505 public:
1506  static TypeId GetTypeId (void);
1507 
1513 
1518  double GetAlpha (void) const;
1519 
1524  double GetBeta (void) const;
1525 
1539  double GetValue (double alpha, double beta);
1540 
1554  uint32_t GetInteger (uint32_t alpha, uint32_t beta);
1555 
1572  virtual double GetValue (void);
1573 
1585  virtual uint32_t GetInteger (void);
1586 
1587 private:
1624  double GetNormalValue (double mean, double variance, double bound);
1625 
1627  double m_alpha;
1628 
1630  double m_beta;
1631 
1634 
1636  double m_next;
1637 
1638 };
1639 
1676 {
1677 public:
1678  static TypeId GetTypeId (void);
1679 
1685 
1690  uint32_t GetK (void) const;
1691 
1696  double GetLambda (void) const;
1697 
1711  double GetValue (uint32_t k, double lambda);
1712 
1726  uint32_t GetInteger (uint32_t k, uint32_t lambda);
1727 
1744  virtual double GetValue (void);
1745 
1757  virtual uint32_t GetInteger (void);
1758 
1759 private:
1784  double GetExponentialValue (double mean, double bound);
1785 
1787  uint32_t m_k;
1788 
1790  double m_lambda;
1791 
1792 };
1793 
1823 {
1824 public:
1825  static TypeId GetTypeId (void);
1826 
1832 
1837  double GetMean (void) const;
1838 
1843  double GetMin (void) const;
1844 
1849  double GetMax (void) const;
1850 
1889  double GetValue (double mean, double min, double max);
1890 
1929  uint32_t GetInteger (uint32_t mean, uint32_t min, uint32_t max);
1930 
1971  virtual double GetValue (void);
1972 
2008  virtual uint32_t GetInteger (void);
2009 
2010 private:
2012  double m_mean;
2013 
2015  double m_min;
2016 
2018  double m_max;
2019 };
2020 
2080 {
2081 public:
2082  static TypeId GetTypeId (void);
2083 
2088  ZipfRandomVariable ();
2089 
2094  uint32_t GetN (void) const;
2095 
2100  double GetAlpha (void) const;
2101 
2115  double GetValue (uint32_t n, double alpha);
2116 
2130  uint32_t GetInteger (uint32_t n, uint32_t alpha);
2131 
2148  virtual double GetValue (void);
2149 
2161  virtual uint32_t GetInteger (void);
2162 
2163 private:
2165  uint32_t m_n;
2166 
2168  double m_alpha;
2169 
2171  double m_c;
2172 };
2173 
2214 {
2215 public:
2216  static TypeId GetTypeId (void);
2217 
2222  ZetaRandomVariable ();
2223 
2228  double GetAlpha (void) const;
2229 
2242  double GetValue (double alpha);
2243 
2256  uint32_t GetInteger (uint32_t alpha);
2257 
2274  virtual double GetValue (void);
2275 
2287  virtual uint32_t GetInteger (void);
2288 
2289 private:
2291  double m_alpha;
2292 
2294  double m_b;
2295 };
2296 
2328 {
2329 public:
2330  static TypeId GetTypeId (void);
2331 
2337  virtual ~DeterministicRandomVariable ();
2338 
2347  void SetValueArray (double* values, uint64_t length);
2348 
2353  virtual double GetValue (void);
2354 
2359  virtual uint32_t GetInteger (void);
2360 
2361 private:
2363  uint64_t m_count;
2364 
2366  uint64_t m_next;
2367 
2369  double* m_data;
2370 };
2371 
2404 {
2405 public:
2406  static TypeId GetTypeId (void);
2407 
2413 
2419  void CDF (double v, double c); // Value, prob <= Value
2420 
2432  virtual double GetValue (void);
2433 
2445  virtual uint32_t GetInteger (void);
2446 
2447 private:
2448  class ValueCDF
2449  {
2450 public:
2451  ValueCDF ();
2452  ValueCDF (double v, double c);
2453  ValueCDF (const ValueCDF& c);
2454  double value;
2455  double cdf;
2456  };
2457  virtual void Validate (); // Insure non-decreasing emiprical values
2458  virtual double Interpolate (double, double, double, double, double);
2459  bool validated; // True if non-decreasing validated
2460  std::vector<ValueCDF> emp; // Empicical CDF
2461 };
2462 
2463 } // namespace ns3
2464 
2465 #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...
static TypeId GetTypeId(void)
Register this type.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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.
Declaration of Attribute helper macros.
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.
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
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:87
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:51
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.