A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
random-variable-stream.h
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 
36 class RngStream;
37 
58 {
59 public:
60  static TypeId GetTypeId (void);
62  virtual ~RandomVariableStream();
63 
68  void SetStream (int64_t stream);
69 
74  int64_t GetStream(void) const;
75 
81  void SetAntithetic(bool isAntithetic);
82 
88  bool IsAntithetic(void) const;
89 
94  virtual double GetValue (void) = 0;
95 
100  virtual uint32_t GetInteger (void) = 0;
101 
102 protected:
106  RngStream *Peek(void) const;
107 
108 private:
109  // you can't copy these objects.
110  // Theoretically, it is possible to give them good copy semantics
111  // but not enough time to iron out the details.
113  RandomVariableStream &operator = (const RandomVariableStream &o);
114 
117 
120 
122  int64_t m_stream;
123 };
124 
154 {
155 public:
156  static TypeId GetTypeId (void);
157 
162 
167  double GetMin (void) const;
168 
173  double GetMax (void) const;
174 
194  double GetValue (double min, double max);
195 
215  uint32_t GetInteger (uint32_t min, uint32_t max);
216 
239  virtual double GetValue (void);
240 
258  virtual uint32_t GetInteger (void);
259 private:
261  double m_min;
262 
264  double m_max;
265 };
266 
274 {
275 public:
276  static TypeId GetTypeId (void);
277 
282 
287  double GetConstant (void) const;
288 
293  double GetValue (double constant);
298  uint32_t GetInteger (uint32_t constant);
299 
304  virtual double GetValue (void);
305 
310  virtual uint32_t GetInteger (void);
311 
312 private:
314  double m_constant;
315 };
316 
328 {
329 public:
330  static TypeId GetTypeId (void);
331 
336 
341  double GetMin (void) const;
342 
347  double GetMax (void) const;
348 
354 
359  uint32_t GetConsecutive (void) const;
360 
374  virtual double GetValue (void);
375 
380  virtual uint32_t GetInteger (void);
381 
382 private:
384  double m_min;
385 
387  double m_max;
388 
391 
393  uint32_t m_consecutive;
394 
396  double m_current;
397 
400 
403 
404 };
405 
441 {
442 public:
443  static TypeId GetTypeId (void);
444 
450 
455  double GetMean (void) const;
456 
461  double GetBound (void) const;
462 
487  double GetValue (double mean, double bound);
488 
513  uint32_t GetInteger (uint32_t mean, uint32_t bound);
514 
542  virtual double GetValue (void);
543 
566  virtual uint32_t GetInteger (void);
567 
568 private:
570  double m_mean;
571 
573  double m_bound;
574 };
575 
621 {
622 public:
623  static TypeId GetTypeId (void);
624 
630 
635  double GetMean (void) const;
636 
641  double GetShape (void) const;
642 
647  double GetBound (void) const;
648 
680  double GetValue (double mean, double shape, double bound);
681 
713  uint32_t GetInteger (uint32_t mean, uint32_t shape, uint32_t bound);
714 
748  virtual double GetValue (void);
749 
778  virtual uint32_t GetInteger (void);
779 
780 private:
782  double m_mean;
783 
785  double m_shape;
786 
788  double m_bound;
789 };
790 
845 {
846 public:
847  static TypeId GetTypeId (void);
848 
854 
859  double GetScale (void) const;
860 
865  double GetShape (void) const;
866 
871  double GetBound (void) const;
872 
898  double GetValue (double scale, double shape, double bound);
899 
925  uint32_t GetInteger (uint32_t scale, uint32_t shape, uint32_t bound);
926 
954  virtual double GetValue (void);
955 
978  virtual uint32_t GetInteger (void);
979 
980 private:
982  double m_scale;
983 
985  double m_shape;
986 
988  double m_bound;
989 };
990 
1025 {
1026 public:
1027  static const double INFINITE_VALUE;
1028 
1029  static TypeId GetTypeId (void);
1030 
1036 
1041  double GetMean (void) const;
1042 
1047  double GetVariance (void) const;
1048 
1053  double GetBound (void) const;
1054 
1091  double GetValue (double mean, double variance, double bound = NormalRandomVariable::INFINITE_VALUE);
1092 
1129  uint32_t GetInteger (uint32_t mean, uint32_t variance, uint32_t bound);
1130 
1169  virtual double GetValue (void);
1170 
1204  virtual uint32_t GetInteger (void);
1205 
1206 private:
1208  double m_mean;
1209 
1211  double m_variance;
1212 
1214  double m_bound;
1215 
1218 
1220  double m_next;
1221 };
1222 
1267 {
1268 public:
1269  static TypeId GetTypeId (void);
1270 
1276 
1281  double GetMu (void) const;
1282 
1287  double GetSigma (void) const;
1288 
1322  double GetValue (double mu, double sigma);
1323 
1357  uint32_t GetInteger (uint32_t mu, uint32_t sigma);
1358 
1395  virtual double GetValue (void);
1396 
1428  virtual uint32_t GetInteger (void);
1429 
1430 private:
1432  double m_mu;
1433 
1435  double m_sigma;
1436 };
1437 
1470 {
1471 public:
1472  static TypeId GetTypeId (void);
1473 
1479 
1484  double GetAlpha (void) const;
1485 
1490  double GetBeta (void) const;
1491 
1505  double GetValue (double alpha, double beta);
1506 
1520  uint32_t GetInteger (uint32_t alpha, uint32_t beta);
1521 
1538  virtual double GetValue (void);
1539 
1551  virtual uint32_t GetInteger (void);
1552 
1553 private:
1590  double GetNormalValue (double mean, double variance, double bound);
1591 
1593  double m_alpha;
1594 
1596  double m_beta;
1597 
1600 
1602  double m_next;
1603 
1604 };
1605 
1642 {
1643 public:
1644  static TypeId GetTypeId (void);
1645 
1651 
1656  uint32_t GetK (void) const;
1657 
1662  double GetLambda (void) const;
1663 
1677  double GetValue (uint32_t k, double lambda);
1678 
1692  uint32_t GetInteger (uint32_t k, uint32_t lambda);
1693 
1710  virtual double GetValue (void);
1711 
1723  virtual uint32_t GetInteger (void);
1724 
1725 private:
1750  double GetExponentialValue (double mean, double bound);
1751 
1753  uint32_t m_k;
1754 
1756  double m_lambda;
1757 
1758 };
1759 
1789 {
1790 public:
1791  static TypeId GetTypeId (void);
1792 
1798 
1803  double GetMean (void) const;
1804 
1809  double GetMin (void) const;
1810 
1815  double GetMax (void) const;
1816 
1855  double GetValue (double mean, double min, double max);
1856 
1895  uint32_t GetInteger (uint32_t mean, uint32_t min, uint32_t max);
1896 
1937  virtual double GetValue (void);
1938 
1974  virtual uint32_t GetInteger (void);
1975 
1976 private:
1978  double m_mean;
1979 
1981  double m_min;
1982 
1984  double m_max;
1985 
1988  double m_mode;
1989 };
1990 
2050 {
2051 public:
2052  static TypeId GetTypeId (void);
2053 
2058  ZipfRandomVariable ();
2059 
2064  uint32_t GetN (void) const;
2065 
2070  double GetAlpha (void) const;
2071 
2085  double GetValue (uint32_t n, double alpha);
2086 
2100  uint32_t GetInteger (uint32_t n, uint32_t alpha);
2101 
2118  virtual double GetValue (void);
2119 
2131  virtual uint32_t GetInteger (void);
2132 
2133 private:
2135  uint32_t m_n;
2136 
2138  double m_alpha;
2139 
2141  double m_c;
2142 };
2143 
2184 {
2185 public:
2186  static TypeId GetTypeId (void);
2187 
2192  ZetaRandomVariable ();
2193 
2198  double GetAlpha (void) const;
2199 
2212  double GetValue (double alpha);
2213 
2226  uint32_t GetInteger (uint32_t alpha);
2227 
2244  virtual double GetValue (void);
2245 
2257  virtual uint32_t GetInteger (void);
2258 
2259 private:
2261  double m_alpha;
2262 
2264  double m_b;
2265 };
2266 
2298 {
2299 public:
2300  static TypeId GetTypeId (void);
2301 
2307  virtual ~DeterministicRandomVariable ();
2308 
2317  void SetValueArray (double* values, uint64_t length);
2318 
2323  virtual double GetValue (void);
2324 
2329  virtual uint32_t GetInteger (void);
2330 
2331 private:
2333  uint64_t m_count;
2334 
2336  uint64_t m_next;
2337 
2339  double* m_data;
2340 };
2341 
2374 {
2375 public:
2376  static TypeId GetTypeId (void);
2377 
2383 
2389  void CDF (double v, double c); // Value, prob <= Value
2390 
2402  virtual double GetValue (void);
2403 
2415  virtual uint32_t GetInteger (void);
2416 
2417 private:
2418  class ValueCDF
2419  {
2420 public:
2421  ValueCDF ();
2422  ValueCDF (double v, double c);
2423  ValueCDF (const ValueCDF& c);
2424  double value;
2425  double cdf;
2426  };
2427  virtual void Validate (); // Insure non-decreasing emiprical values
2428  virtual double Interpolate (double, double, double, double, double);
2429  bool validated; // True if non-decreasing validated
2430  std::vector<ValueCDF> emp; // Empicical CDF
2431 };
2432 
2433 } // namespace ns3
2434 
2435 #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.
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:39
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:63
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:44
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.
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.