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 
40 namespace ns3 {
41 
72 class RngStream;
73 
98 {
99 public:
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 
152 protected:
157  RngStream *Peek(void) const;
158 
159 private:
180 
183 
186 
188  int64_t m_stream;
189 
190 }; // class RandomVariableStream
191 
192 
235 {
236 public:
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 
282  uint32_t GetInteger (uint32_t min, uint32_t max);
283 
284  // Inherited from RandomVariableStream
290  virtual double GetValue (void);
296  virtual uint32_t GetInteger (void);
297 
298 private:
300  double m_min;
301 
303  double m_max;
304 
305 }; // class UniformRandomVariable
306 
307 
319 {
320 public:
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 
357 private:
359  double m_constant;
360 
361 }; // class ConstantRandomVariable
362 
363 
400 {
401 public:
406  static TypeId GetTypeId (void);
407 
413 
418  double GetMin (void) const;
419 
425  double GetMax (void) const;
426 
431  Ptr<RandomVariableStream> GetIncrement (void) const;
432 
438  uint32_t GetConsecutive (void) const;
439 
440  // Inherited from RandomVariableStream
441  virtual double GetValue (void);
442  virtual uint32_t GetInteger (void);
443 
444 private:
446  double m_min;
447 
449  double m_max;
450 
453 
455  uint32_t m_consecutive;
456 
458  double m_current;
459 
462 
465 
466 }; // class SequentialRandomVariable
467 
468 
539 {
540 public:
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 
590 private:
592  double m_mean;
593 
595  double m_bound;
596 
597 }; // class ExponentialRandomVariable
598 
599 
641 {
642 public:
647  static TypeId GetTypeId (void);
648 
654 
660  double GetMean (void) const;
661 
666  double GetScale (void) const;
667 
672  double GetShape (void) const;
673 
678  double GetBound (void) const;
679 
706  double GetValue (double scale, double shape, double bound);
707 
734  uint32_t GetInteger (uint32_t scale, uint32_t shape, uint32_t bound);
735 
768  virtual double GetValue (void);
769 
793  virtual uint32_t GetInteger (void);
794 
795 private:
797  double m_mean;
798 
800  double m_scale;
801 
803  double m_shape;
804 
806  double m_bound;
807 
808 }; // class ParetoRandomVariable
809 
810 
865 {
866 public:
871  static TypeId GetTypeId (void);
872 
878 
883  double GetScale (void) const;
884 
889  double GetShape (void) const;
890 
895  double GetBound (void) const;
896 
922  double GetValue (double scale, double shape, double bound);
923 
949  uint32_t GetInteger (uint32_t scale, uint32_t shape, uint32_t bound);
950 
978  virtual double GetValue (void);
979 
1002  virtual uint32_t GetInteger (void);
1003 
1004 private:
1006  double m_scale;
1007 
1009  double m_shape;
1010 
1012  double m_bound;
1013 
1014 }; // class WeibullRandomVariable
1015 
1016 
1051 {
1052 public:
1054  static const double INFINITE_VALUE;
1055 
1060  static TypeId GetTypeId (void);
1061 
1067 
1072  double GetMean (void) const;
1073 
1078  double GetVariance (void) const;
1079 
1084  double GetBound (void) const;
1085 
1122  double GetValue (double mean, double variance, double bound = NormalRandomVariable::INFINITE_VALUE);
1123 
1160  uint32_t GetInteger (uint32_t mean, uint32_t variance, uint32_t bound);
1161 
1200  virtual double GetValue (void);
1201 
1235  virtual uint32_t GetInteger (void);
1236 
1237 private:
1239  double m_mean;
1240 
1242  double m_variance;
1243 
1245  double m_bound;
1246 
1249 
1251  double m_next;
1252 
1253 }; // class NormalRandomVariable
1254 
1255 
1300 {
1301 public:
1306  static TypeId GetTypeId (void);
1307 
1313 
1318  double GetMu (void) const;
1319 
1324  double GetSigma (void) const;
1325 
1359  double GetValue (double mu, double sigma);
1360 
1394  uint32_t GetInteger (uint32_t mu, uint32_t sigma);
1395 
1432  virtual double GetValue (void);
1433 
1465  virtual uint32_t GetInteger (void);
1466 
1467 private:
1469  double m_mu;
1470 
1472  double m_sigma;
1473 
1474 }; // class LogNormalRandomVariable
1475 
1476 
1509 {
1510 public:
1515  static TypeId GetTypeId (void);
1516 
1522 
1527  double GetAlpha (void) const;
1528 
1533  double GetBeta (void) const;
1534 
1548  double GetValue (double alpha, double beta);
1549 
1563  uint32_t GetInteger (uint32_t alpha, uint32_t beta);
1564 
1581  virtual double GetValue (void);
1582 
1594  virtual uint32_t GetInteger (void);
1595 
1596 private:
1633  double GetNormalValue (double mean, double variance, double bound);
1634 
1636  double m_alpha;
1637 
1639  double m_beta;
1640 
1643 
1645  double m_next;
1646 
1647 }; // class GammaRandomVariable
1648 
1649 
1686 {
1687 public:
1692  static TypeId GetTypeId (void);
1693 
1699 
1704  uint32_t GetK (void) const;
1705 
1710  double GetLambda (void) const;
1711 
1725  double GetValue (uint32_t k, double lambda);
1726 
1740  uint32_t GetInteger (uint32_t k, uint32_t lambda);
1741 
1758  virtual double GetValue (void);
1759 
1771  virtual uint32_t GetInteger (void);
1772 
1773 private:
1798  double GetExponentialValue (double mean, double bound);
1799 
1801  uint32_t m_k;
1802 
1804  double m_lambda;
1805 
1806 }; // class ErlangRandomVariable
1807 
1808 
1838 {
1839 public:
1844  static TypeId GetTypeId (void);
1845 
1851 
1856  double GetMean (void) const;
1857 
1862  double GetMin (void) const;
1863 
1868  double GetMax (void) const;
1869 
1908  double GetValue (double mean, double min, double max);
1909 
1948  uint32_t GetInteger (uint32_t mean, uint32_t min, uint32_t max);
1949 
1990  virtual double GetValue (void);
1991 
2027  virtual uint32_t GetInteger (void);
2028 
2029 private:
2031  double m_mean;
2032 
2034  double m_min;
2035 
2037  double m_max;
2038 
2039 }; // class TriangularRandomVariable
2040 
2041 
2101 {
2102 public:
2107  static TypeId GetTypeId (void);
2108 
2113  ZipfRandomVariable ();
2114 
2119  uint32_t GetN (void) const;
2120 
2125  double GetAlpha (void) const;
2126 
2140  double GetValue (uint32_t n, double alpha);
2141 
2155  uint32_t GetInteger (uint32_t n, uint32_t alpha);
2156 
2173  virtual double GetValue (void);
2174 
2186  virtual uint32_t GetInteger (void);
2187 
2188 private:
2190  uint32_t m_n;
2191 
2193  double m_alpha;
2194 
2196  double m_c;
2197 
2198 }; // class ZipfRandomVariable
2199 
2200 
2241 {
2242 public:
2247  static TypeId GetTypeId (void);
2248 
2253  ZetaRandomVariable ();
2254 
2259  double GetAlpha (void) const;
2260 
2273  double GetValue (double alpha);
2274 
2287  uint32_t GetInteger (uint32_t alpha);
2288 
2305  virtual double GetValue (void);
2306 
2318  virtual uint32_t GetInteger (void);
2319 
2320 private:
2322  double m_alpha;
2323 
2325  double m_b;
2326 
2327 }; // class ZetaRandomVariable
2328 
2329 
2361 {
2362 public:
2367  static TypeId GetTypeId (void);
2368 
2374  virtual ~DeterministicRandomVariable ();
2375 
2384  void SetValueArray (double* values, std::size_t length);
2385 
2390  virtual double GetValue (void);
2391 
2396  virtual uint32_t GetInteger (void);
2397 
2398 private:
2400  std::size_t m_count;
2401 
2403  std::size_t m_next;
2404 
2406  double* m_data;
2407 
2408 }; // class DeterministicRandomVariable
2409 
2410 
2443 {
2444 public:
2449  static TypeId GetTypeId (void);
2450 
2456 
2462  void CDF (double v, double c); // Value, prob <= Value
2463 
2475  virtual double GetValue (void);
2476 
2488  virtual uint32_t GetInteger (void);
2489 
2490 private:
2492  class ValueCDF
2493  {
2494 public:
2496  ValueCDF ();
2503  ValueCDF (double v, double c);
2509  ValueCDF (const ValueCDF& c);
2510 
2512  double value;
2514  double cdf;
2515  };
2526  virtual void Validate ();
2538  virtual double Interpolate (double c1, double c2,
2539  double v1, double v2, double r);
2540 
2544  std::vector<ValueCDF> m_emp;
2545 
2546 }; // class EmpiricalRandomVariable
2547 
2548 
2549 } // namespace ns3
2550 
2551 #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.
std::vector< ValueCDF > m_emp
The vector of CDF points.
double m_next
The algorithm produces two values at a time.
void SetAntithetic(bool isAntithetic)
Specify whether antithetic values should be generated.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
bool m_validated
true once the CDF has been validated.
double m_alpha
The alpha value for the Zipf distribution returned by this RNG stream.
double m_mean
The mean value for the triangular distribution returned by this RNG stream.
double m_bound
The upper bound on values that can be returned by this RNG stream.
#define min(a, b)
Definition: 80211b.c:42
The exponential distribution Random Number Generator (RNG).
The Random Number Generator (RNG) that returns a pattern of sequential values.
RandomVariableStream()
Default constructor.
The normal (Gaussian) distribution Random Number Generator (RNG) that allows stream numbers to be set...
std::size_t m_count
Size of the array of values.
double m_mean
The mean parameter for the Pareto distribution returned by this RNG stream.
double m_shape
The shape parameter for the Weibull distribution returned by this RNG stream.
int64_t m_stream
The stream number for the RngStream.
double m_constant
The constant value returned by this RNG stream.
double m_min
The first value of the sequence.
Ptr< RandomVariableStream > m_increment
Increment between distinct values.
bool m_nextValid
True if the next value is valid.
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
double m_bound
The upper bound on values that can be returned by this RNG stream.
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 the RngStream.
RngStream * m_rng
Pointer to the underlying RngStream.
Combined Multiple-Recursive Generator MRG32k3a.
Definition: rng-stream.h:49
double * m_data
Array of values to return in sequence.
virtual uint32_t GetInteger(void)=0
Get the next random value as an integer drawn from the distribution.
double m_lambda
The lambda value for the Erlang distribution returned by this RNG stream.
#define max(a, b)
Definition: 80211b.c:43
double m_alpha
The alpha value for the zeta distribution returned by this RNG stream.
double m_max
Strict upper bound on the sequence.
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...
Helper to hold one point of the CDF.
double m_sigma
The sigma value for the log-normal distribution returned by this RNG stream.
The uniform distribution Random Number Generator (RNG).
static TypeId GetTypeId(void)
Register this type.
double m_scale
The scale parameter for the Pareto distribution returned by this RNG stream.
double m_c
The normalization constant.
uint32_t m_consecutive
The number of times each distinct value is repeated.
double m_variance
The variance value for the normal distribution returned by this RNG stream.
double m_mean
The mean value of the unbounded exponential distribution.
bool m_isCurrentSet
Indicates if the current sequence value has been properly initialized.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double m_mean
The mean value for the normal distribution returned by this RNG stream.
static const double INFINITE_VALUE
Large constant to bound the range.
uint32_t m_currentConsecutive
The number of times the current distinct value has been repeated.
ns3::TypeId declaration; inline and template implementations.
double m_bound
The upper bound on values that can be returned by this RNG stream.
double m_beta
The beta value for the gamma distribution returned by this RNG stream.
bool IsAntithetic(void) const
Check if antithetic values will be generated.
double m_alpha
The alpha value for the gamma distribution returned by this RNG stream.
Attribute helper (ATTRIBUTE_ )macros definition.
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
#define NS_DEPRECATED
Mark a function as deprecated.
Definition: deprecated.h:60
The Zipf distribution Random Number Generator (RNG) that allows stream numbers to be set deterministi...
The basic uniform Random Number Generator (RNG).
double m_bound
The bound on values that can be returned by this RNG stream.
virtual ~RandomVariableStream()
Destructor.
double m_next
The algorithm produces two normal values at a time.
RngStream * Peek(void) const
Get the pointer to the underlying RngStream.
double m_b
Just for calculus simplifications.
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.
bool m_nextValid
True if the next normal value is valid.
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
The Random Number Generator (RNG) that has a specified empirical distribution.
std::size_t m_next
Position of the next value in the array of values.
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:58
The Pareto distribution Random Number Generator (RNG).
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)
Assignment operator.
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...
bool m_isAntithetic
Indicates if antithetic values should be generated by this RNG stream.