src/core/random-variable.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 4579 c86681050541
permissions -rw-r--r--
Added tag ns-3.5 for changeset c975274c9707
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 //
     3 // Copyright (c) 2006 Georgia Tech Research Corporation
     4 //
     5 // This program is free software; you can redistribute it and/or modify
     6 // it under the terms of the GNU General Public License version 2 as
     7 // published by the Free Software Foundation;
     8 //
     9 // This program is distributed in the hope that it will be useful,
    10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12 // GNU General Public License for more details.
    13 //
    14 // You should have received a copy of the GNU General Public License
    15 // along with this program; if not, write to the Free Software
    16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17 //
    18 // Author: Rajib Bhattacharjea<raj.b@gatech.edu>
    19 // Author: Hadi Arbabi<marbabi@cs.odu.edu>
    20 //
    21 
    22 #ifndef __random_variable_h
    23 #define __random_variable_h
    24 
    25 #include <vector>
    26 #include <algorithm>
    27 #include <stdint.h>
    28 #include <istream>
    29 #include <ostream>
    30 #include "attribute.h"
    31 #include "attribute-helper.h"
    32 
    33 /**
    34  * \ingroup core
    35  * \defgroup randomvariable Random Variable Distributions
    36  *
    37  */
    38 
    39 namespace ns3 {
    40 
    41 class RandomVariableBase;
    42 
    43 class SeedManager
    44 {
    45 public:
    46 	  
    47   /**
    48    * \brief set the seed
    49    * it will duplicate the seed value 6 times
    50    * \code
    51    * SeedManger::SetSeed(15);
    52    * UniformVariable x(2,3);     //these will give the same output everytime
    53    * ExponentialVariable y(120); //as long as the seed stays the same
    54    * \endcode
    55    * \param seed
    56    *
    57    * Note, while the underlying RNG takes six integer values as a seed;
    58    * it is sufficient to set these all to the same integer, so we provide
    59    * a simpler interface here that just takes one integer.
    60    */ 
    61   static void SetSeed (uint32_t seed);
    62  
    63   /**
    64    * \brief Get the seed value
    65    * \return the seed value
    66    *
    67    * Note:  returns the first of the six seed values used in the underlying RNG
    68    */
    69    static uint32_t GetSeed ();
    70  
    71    /**
    72     * \brief Set the run number of simulation
    73     *
    74     * \code
    75     * SeedManager::SetSeed(12);
    76     * int N = atol(argv[1]); //read in run number from command line
    77     * SeedManager::SetRun(N);
    78     * UniformVariable x(0,10);
    79     * ExponentialVariable y(2902);
    80     * \endcode
    81     * In this example, N could successivly be equal to 1,2,3, etc. and the user
    82     * would continue to get independent runs out of the single simulation.  For
    83     * this simple example, the following might work:
    84     * \code
    85     * ./simulation 0
    86     * ...Results for run 0:...
    87     *
    88     * ./simulation 1
    89     * ...Results for run 1:...
    90     * \endcode
    91     */
    92   static void SetRun (uint32_t run);
    93   /**
    94    * \returns the current run number
    95    * @sa SetRun
    96    */
    97   static uint32_t GetRun (void);
    98   
    99   /**
   100    * \brief Check if seed value is valid if wanted to be used as seed
   101    * \return true if valid and false if invalid
   102    */
   103   static bool CheckSeed (uint32_t seed);
   104 };
   105 
   106 
   107 /**
   108  * \brief The basic RNG for NS-3.
   109  * \ingroup randomvariable
   110  *
   111  * Note: The underlying random number generation method used
   112  * by NS-3 is the RngStream code by Pierre L'Ecuyer at
   113  * the University of Montreal.
   114  * 
   115  * NS-3 has a rich set of  random number generators.
   116  * Class RandomVariable defines the base class functionalty
   117  * required for all random number generators.  By default, the underlying
   118  * generator is seeded all the time with the same seed value and run number
   119  * coming from the ns3::GlobalValue \ref GlobalValueRngSeed "RngSeed" and \ref GlobalValueRngRun "RngRun".
   120  */
   121 class RandomVariable
   122 { 
   123 public:
   124   RandomVariable();
   125   RandomVariable(const RandomVariable&o);
   126   RandomVariable &operator = (const RandomVariable &o);
   127   ~RandomVariable();
   128   
   129   /**
   130    * \brief Returns a random double from the underlying distribution
   131    * \return A floating point random value
   132    */
   133   double GetValue (void) const;
   134 
   135   /**
   136    * \brief Returns a random integer integer from the underlying distribution
   137    * \return  Integer cast of ::GetValue()
   138    */
   139   uint32_t GetInteger (void) const;
   140 
   141 private:
   142   friend std::ostream &operator << (std::ostream &os, const RandomVariable &var);
   143   friend std::istream &operator >> (std::istream &os, RandomVariable &var);
   144 
   145   RandomVariableBase *m_variable;
   146 protected:
   147   RandomVariable (const RandomVariableBase &variable);
   148   RandomVariableBase *Peek (void) const;
   149 };
   150 
   151 /**
   152  * \brief The uniform distribution RNG for NS-3.
   153  * \ingroup randomvariable
   154  *
   155  * This class supports the creation of objects that return random numbers
   156  * from a fixed uniform distribution.  It also supports the generation of 
   157  * single random numbers from various uniform distributions.
   158  *
   159  * The low end of the range is always included and the high end
   160  * of the range is always excluded.
   161  * \code
   162  * UniformVariable x(0,10);
   163  * x.GetValue();  //will always return numbers [0,10)
   164  * UniformVariable::GetSingleValue(100,1000); //returns a value [100,1000)
   165  * \endcode
   166  */
   167 class UniformVariable : public RandomVariable 
   168 {
   169 public:
   170   /**
   171    * Creates a uniform random number generator in the
   172    * range [0.0 .. 1.0).
   173    */
   174   UniformVariable();
   175 
   176   /**
   177    * Creates a uniform random number generator with the specified range
   178    * \param s Low end of the range
   179    * \param l High end of the range
   180    */
   181   UniformVariable(double s, double l);
   182 
   183   /**
   184   * \brief call RandomVariable::GetValue
   185   * \return A floating point random value
   186   *
   187   * Note: we have to re-implement this method here because the method is 
   188   * overloaded below for the two-argument variant and the c++ name resolution
   189   * rules don't work well with overloads split between parent and child 
   190   * classes.
   191   */
   192   double GetValue (void) const;
   193   
   194   /**
   195   * \brief Returns a random double with the specified range
   196   * \param s Low end of the range
   197   * \param l High end of the range
   198   * \return A floating point random value
   199   */
   200   double GetValue(double s, double l);
   201 
   202   /**
   203    * \brief Returns a random unsigned integer from the interval [s,l] including both ends.
   204    * \param s Low end of the range
   205    * \param l High end of the range
   206    * \return A random unsigned integer value.
   207    */
   208   uint32_t GetInteger (uint32_t s, uint32_t l);
   209 };
   210 
   211 /**
   212  * \brief A random variable that returns a constant
   213  * \ingroup randomvariable
   214  *
   215  * Class ConstantVariable defines a random number generator that
   216  * returns the same value every sample.
   217  */
   218 class ConstantVariable : public RandomVariable { 
   219 
   220 public:
   221   /**
   222    * Construct a ConstantVariable RNG that returns zero every sample
   223    */
   224   ConstantVariable();
   225   
   226   /**
   227    * Construct a ConstantVariable RNG that returns the specified value
   228    * every sample.
   229    * \param c Unchanging value for this RNG.
   230    */
   231   ConstantVariable(double c);
   232 
   233   /**
   234    * \brief Specify a new constant RNG for this generator.
   235    * \param c New constant value for this RNG.
   236    */
   237   void SetConstant(double c);
   238 
   239 };
   240 
   241 /**
   242  * \brief Return a sequential list of values
   243  * \ingroup randomvariable
   244  *
   245  * Class SequentialVariable defines a random number generator that
   246  * returns a sequential sequence.  The sequence monotonically
   247  * increases for a period, then wraps around to the low value 
   248  * and begins monotonicaly increasing again.
   249  */
   250 class SequentialVariable : public RandomVariable 
   251 {
   252 public:
   253   /**
   254    * \brief Constructor for the SequentialVariable RNG.
   255    *
   256    * The four parameters define the sequence.  For example
   257    * SequentialVariable(0,5,1,2) creates a RNG that has the sequence
   258    * 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 0 ...
   259    * \param f First value of the sequence.
   260    * \param l One more than the last value of the sequence.
   261    * \param i Increment between sequence values
   262    * \param c Number of times each member of the sequence is repeated
   263    */
   264   SequentialVariable(double f, double l, double i = 1, uint32_t c = 1);
   265 
   266   /**
   267    * \brief Constructor for the SequentialVariable RNG.
   268    *
   269    * Differs from the first only in that the increment parameter is a
   270    * random variable
   271    * \param f First value of the sequence.
   272    * \param l One more than the last value of the sequence.
   273    * \param i Reference to a RandomVariable for the sequence increment
   274    * \param c Number of times each member of the sequence is repeated
   275    */
   276   SequentialVariable(double f, double l, const RandomVariable& i, uint32_t c = 1);
   277 
   278 };
   279 
   280 /**
   281  * \brief Exponentially Distributed random var
   282  * \ingroup randomvariable
   283  *
   284  * This class supports the creation of objects that return random numbers
   285  * from a fixed exponential distribution.  It also supports the generation of 
   286  * single random numbers from various exponential distributions.
   287  *
   288  * The probability density function of an exponential variable 
   289  * is defined over the interval [0, +inf) as:
   290  * \f$ \alpha  e^{-\alpha x} \f$
   291  * where \f$ \alpha = \frac{1}{mean} \f$ 
   292  *
   293  * The bounded version is defined over the internal [0,+inf) as:
   294  * \f$ \left\{ \begin{array}{cl} \alpha  e^{-\alpha x} & x < bound \\ bound & x > bound \end{array}\right. \f$
   295  * 
   296  * \code
   297  * ExponentialVariable x(3.14);
   298  * x.GetValue();  //will always return with mean 3.14
   299  * ExponentialVariable::GetSingleValue(20.1); //returns with mean 20.1
   300  * ExponentialVariable::GetSingleValue(108); //returns with mean 108
   301  * \endcode
   302  *
   303  */
   304 class ExponentialVariable : public RandomVariable 
   305 { 
   306 public:
   307   /**
   308    * Constructs an exponential random variable  with a mean
   309    * value of 1.0.
   310    */
   311   ExponentialVariable();
   312 
   313   /**
   314    * \brief Constructs an exponential random variable with a specified mean
   315    * \param m Mean value for the random variable
   316    */
   317   explicit ExponentialVariable(double m);
   318 
   319   /**
   320    * \brief Constructs an exponential random variable with spefified
   321    * \brief mean and upper limit.
   322    *
   323    * Since exponential distributions can theoretically return unbounded values,
   324    * it is sometimes useful to specify a fixed upper limit.  Note however when
   325    * the upper limit is specified, the true mean of the distribution is 
   326    * slightly smaller than the mean value specified.
   327    * \param m Mean value of the random variable
   328    * \param b Upper bound on returned values
   329    */
   330   ExponentialVariable(double m, double b);
   331 
   332 };
   333 
   334 /**
   335  * \brief ParetoVariable distributed random var
   336  * \ingroup randomvariable
   337  *
   338  * This class supports the creation of objects that return random numbers
   339  * from a fixed pareto distribution.  It also supports the generation of 
   340  * single random numbers from various pareto distributions.
   341  *
   342  * The probability density function is defined over the range [\f$x_m\f$,+inf) as:
   343  * \f$ k \frac{x_m^k}{x^{k+1}}\f$ where \f$x_m > 0\f$ is called the location 
   344  * parameter and \f$ k > 0\f$ is called the pareto index or shape.
   345  * 
   346  * The parameter \f$ x_m \f$ can be infered from the mean and the parameter \f$ k \f$
   347  * with the equation \f$ x_m = mean \frac{k-1}{k},  k > 1\f$.
   348  *
   349  * \code
   350  * ParetoVariable x(3.14);
   351  * x.GetValue();  //will always return with mean 3.14
   352  * ParetoVariable::GetSingleValue(20.1); //returns with mean 20.1
   353  * ParetoVariable::GetSingleValue(108); //returns with mean 108
   354  * \endcode
   355  */
   356 class ParetoVariable : public RandomVariable
   357 {
   358 public:
   359   /**
   360    * Constructs a pareto random variable with a mean of 1 and a shape
   361    * parameter of 1.5
   362    */
   363   ParetoVariable ();
   364 
   365   /**
   366    * Constructs a pareto random variable with specified mean and shape
   367    * parameter of 1.5
   368    * \param m Mean value of the distribution
   369    */
   370   explicit ParetoVariable(double m);
   371 
   372   /**
   373    * Constructs a pareto random variable with the specified mean value and
   374    * shape parameter.
   375    * \param m Mean value of the distribution
   376    * \param s Shape parameter for the distribution
   377    */
   378   ParetoVariable(double m, double s);
   379 
   380   /**
   381    * \brief Constructs a pareto random variable with the specified mean
   382    * \brief value, shape (alpha), and upper bound.
   383    *
   384    * Since pareto distributions can theoretically return unbounded values,
   385    * it is sometimes useful to specify a fixed upper limit.  Note however
   386    * when the upper limit is specified, the true mean of the distribution
   387    * is slightly smaller than the mean value specified.
   388    * \param m Mean value
   389    * \param s Shape parameter
   390    * \param b Upper limit on returned values
   391    */
   392   ParetoVariable(double m, double s, double b);
   393 
   394 };
   395 
   396 /**
   397  * \brief WeibullVariable distributed random var
   398  * \ingroup randomvariable
   399  *
   400  * This class supports the creation of objects that return random numbers
   401  * from a fixed weibull distribution.  It also supports the generation of 
   402  * single random numbers from various weibull distributions.
   403  *
   404  * The probability density function is defined over the interval [0, +inf]
   405  * as: \f$ \frac{k}{\lambda}\left(\frac{x}{\lambda}\right)^{k-1}e^{-\left(\frac{x}{\lambda}\right)^k} \f$
   406  * where \f$ k > 0\f$ is the shape parameter and \f$ \lambda > 0\f$  is the scale parameter. The
   407  * specified mean is related to the scale and shape parameters by the following relation:
   408  * \f$ mean = \lambda\Gamma\left(1+\frac{1}{k}\right) \f$ where \f$ \Gamma \f$ is the Gamma function.
   409  */
   410 class WeibullVariable : public RandomVariable {
   411 public:
   412   /**
   413    * Constructs a weibull random variable  with a mean
   414    * value of 1.0 and a shape (alpha) parameter of 1
   415    */
   416   WeibullVariable();
   417 
   418 
   419   /**
   420    * Constructs a weibull random variable with the specified mean
   421    * value and a shape (alpha) parameter of 1.5.
   422    * \param m mean value of the distribution
   423    */
   424   WeibullVariable(double m) ;
   425 
   426   /**
   427    * Constructs a weibull random variable with the specified mean
   428    * value and a shape (alpha).
   429    * \param m Mean value for the distribution.
   430    * \param s Shape (alpha) parameter for the distribution.
   431    */
   432   WeibullVariable(double m, double s);
   433 
   434    /**
   435    * \brief Constructs a weibull random variable with the specified mean
   436    * \brief value, shape (alpha), and upper bound.
   437    * Since WeibullVariable distributions can theoretically return unbounded values,
   438    * it is sometimes usefull to specify a fixed upper limit.  Note however
   439    * that when the upper limit is specified, the true mean of the distribution
   440    * is slightly smaller than the mean value specified.
   441    * \param m Mean value for the distribution.
   442    * \param s Shape (alpha) parameter for the distribution.
   443    * \param b Upper limit on returned values
   444    */
   445   WeibullVariable(double m, double s, double b);
   446 
   447 };
   448 
   449 /**
   450  * \brief Class NormalVariable defines a random variable with a
   451  * normal (Gaussian) distribution.
   452  * \ingroup randomvariable
   453  * 
   454  * This class supports the creation of objects that return random numbers
   455  * from a fixed normal distribution.  It also supports the generation of 
   456  * single random numbers from various normal distributions.
   457  *
   458  * The density probability function is defined over the interval (-inf,+inf)
   459  * as: \f$ \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{s\sigma^2}}\f$
   460  * where \f$ mean = \mu \f$ and \f$ variance = \sigma^2 \f$
   461  *
   462  */
   463 class NormalVariable : public RandomVariable
   464 {
   465 public:
   466   /**
   467    * Constructs an normal random variable  with a mean
   468    * value of 0 and variance of 1.
   469    */ 
   470   NormalVariable();
   471 
   472   /**
   473    * \brief Construct a normal random variable with specified mean and variance.
   474    * \param m Mean value
   475    * \param v Variance
   476    */ 
   477   NormalVariable(double m, double v);
   478 
   479   /**
   480    * \brief Construct a normal random variable with specified mean and variance
   481    * \param m Mean value
   482    * \param v Variance
   483    * \param b Bound.  The NormalVariable is bounded symetrically about the mean
   484    * [mean-bound,mean+bound]
   485    */ 
   486   NormalVariable(double m, double v, double b);
   487 };
   488 
   489 /**
   490  * \brief EmpiricalVariable distribution random var
   491  * \ingroup randomvariable
   492  *
   493  * Defines a random variable  that has a specified, empirical 
   494  * distribution.  The distribution is specified by a
   495  * series of calls to the CDF member function, specifying a
   496  * value and the probability that the function value is less than
   497  * the specified value.  When values are requested,
   498  * a uniform random variable is used to select a probabililty,
   499  * and the return value is interpreted linerarly between the
   500  * two appropriate points in the CDF.  The method is known
   501  * as inverse transform sampling:
   502  * (http://en.wikipedia.org/wiki/Inverse_transform_sampling).
   503  */
   504 class EmpiricalVariable : public RandomVariable {
   505 public:
   506   /**
   507    * Constructor for the EmpiricalVariable random variables.
   508    */
   509   explicit EmpiricalVariable();
   510 
   511   /**
   512    * \brief Specifies a point in the empirical distribution
   513    * \param v The function value for this point
   514    * \param c Probability that the function is less than or equal to v
   515    */
   516   void CDF(double v, double c);  // Value, prob <= Value
   517 protected:
   518   EmpiricalVariable (const RandomVariableBase &variable);
   519 };
   520 
   521 /**
   522  * \brief Integer-based empirical distribution
   523  * \ingroup randomvariable
   524  *
   525  * Defines an empirical distribution where all values are integers.
   526  * Indentical to EmpiricalVariable, except that the inverse transform
   527  * sampling interpolation described in the EmpiricalVariable documentation
   528  * is modified to only return integers.
   529  */
   530 class IntEmpiricalVariable : public EmpiricalVariable 
   531 {
   532 public:
   533   IntEmpiricalVariable();
   534 };
   535 
   536 /**
   537  * \brief a non-random variable
   538  * \ingroup randomvariable
   539  *
   540  * Defines a random variable  that has a specified, predetermined
   541  * sequence.  This would be useful when trying to force
   542  * the RNG to return a known sequence, perhaps to
   543  * compare NS-3 to some other simulator
   544  */
   545 class DeterministicVariable : public RandomVariable
   546 {
   547 public:
   548   /**
   549    * \brief Constructor
   550    *
   551    * Creates a generator that returns successive elements of the d array
   552    * on successive calls to ::Value().  Note that the d pointer is copied
   553    * for use by the generator (shallow-copy), not its contents, so the 
   554    * contents of the array d points to have to remain unchanged for the use 
   555    * of DeterministicVariable to be meaningful.
   556    * \param d Pointer to array of random values to return in sequence
   557    * \param c Number of values in the array
   558    */
   559   explicit DeterministicVariable(double* d, uint32_t c);
   560 };
   561 
   562 /**
   563  * \brief Log-normal Distributed random var
   564  * \ingroup randomvariable
   565  *
   566  * LogNormalVariable defines a random variable with log-normal
   567  * distribution.  If one takes the natural logarithm of random
   568  * variable following the log-normal distribution, the obtained values
   569  * follow a normal distribution.
   570  *  This class supports the creation of objects that return random numbers
   571  * from a fixed lognormal distribution.  It also supports the generation of
   572  * single random numbers from various lognormal distributions.
   573  *
   574  * The probability density function is defined over the interval [0,+inf) as:
   575  * \f$ \frac{1}{x\sigma\sqrt{2\pi}} e^{-\frac{(ln(x) - \mu)^2}{2\sigma^2}}\f$
   576  * where \f$ mean = e^{\mu+\frac{\sigma^2}{2}} \f$ and 
   577  * \f$ variance = (e^{\sigma^2}-1)e^{2\mu+\sigma^2}\f$
   578  *
   579  * The \f$ \mu \f$ and \f$ \sigma \f$ parameters can be calculated from the mean
   580  * and standard deviation with the following equations:
   581  * \f$ \mu = ln(mean) - \frac{1}{2}ln\left(1+\frac{stddev}{mean^2}\right)\f$, and,
   582  * \f$ \sigma = \sqrt{ln\left(1+\frac{stddev}{mean^2}\right)}\f$
   583  */
   584 class LogNormalVariable : public RandomVariable 
   585 {
   586 public:
   587   /**
   588    * \param mu mu parameter of the lognormal distribution
   589    * \param sigma sigma parameter of the lognormal distribution
   590    */
   591   LogNormalVariable (double mu, double sigma);
   592 };
   593 
   594 /**
   595  * \brief Gamma Distributed Random Variable
   596  * \ingroup randomvariable
   597  *
   598  * GammaVariable defines a random variable with gamma distribution. 
   599  *
   600  * This class supports the creation of objects that return random numbers
   601  * from a fixed gamma distribution. It also supports the generation of 
   602  * single random numbers from various gamma distributions.
   603  *
   604  * The probability density function is defined over the interval [0,+inf) as:
   605  * \f$ x^{\alpha-1} \frac{e^{-\frac{x}{\beta}}}{\beta^\alpha \Gamma(\alpha)}\f$
   606  * where \f$ mean = \alpha\beta \f$ and 
   607  * \f$ variance = \alpha \beta^2\f$
   608  */
   609 class GammaVariable : public RandomVariable 
   610 {
   611 public:
   612   /**
   613    * Constructs a gamma random variable with alpha = 1.0 and beta = 1.0
   614    */
   615   GammaVariable ();
   616 
   617   /**
   618    * \param alpha alpha parameter of the gamma distribution
   619    * \param beta beta parameter of the gamma distribution
   620    */
   621   GammaVariable (double alpha, double beta);
   622 
   623   /**
   624    * \brief call RandomVariable::GetValue
   625    * \return A floating point random value 
   626    *
   627    * Note: we have to re-implement this method here because the method is
   628    * overloaded below for the two-argument variant and the c++ name resolution
   629    * rules don't work well with overloads split between parent and child
   630    * classes.
   631    */
   632   double GetValue (void) const;
   633   
   634   /**
   635    * \brief Returns a gamma random distributed double with parameters alpha and beta.
   636    * \param alpha alpha parameter of the gamma distribution
   637    * \param beta beta parameter of the gamma distribution
   638    * \return A floating point random value
   639    */
   640   double GetValue(double alpha, double beta) const;
   641 };
   642 
   643 /**
   644  * \brief Erlang Distributed Random Variable
   645  * \ingroup randomvariable
   646  *
   647  * ErlangVariable defines a random variable with Erlang distribution.
   648  *
   649  * The Erlang distribution is a special case of the Gamma distribution where k
   650  * (= alpha) is a non-negative integer. Erlang distributed variables can be
   651  * generated using a much faster algorithm than gamma variables.
   652  *
   653  * This class supports the creation of objects that return random numbers from
   654  * a fixed Erlang distribution. It also supports the generation of single
   655  * random numbers from various Erlang distributions.
   656  *
   657  * The probability density function is defined over the interval [0,+inf) as:
   658  * \f$ \frac{x^{k-1} e^{-\frac{x}{\lambda}}}{\lambda^k (k-1)!}\f$
   659  * where \f$ mean = k \lambda \f$ and 
   660  * \f$ variance = k \lambda^2\f$
   661  */
   662 class ErlangVariable : public RandomVariable 
   663 {
   664 public:
   665   /**
   666    * Constructs an Erlang random variable with k = 1 and lambda = 1.0
   667    */
   668   ErlangVariable ();
   669 
   670   /**
   671    * \param k k parameter of the Erlang distribution. Must be a non-negative integer.
   672    * \param lambda lambda parameter of the Erlang distribution
   673    */
   674   ErlangVariable (unsigned int k, double lambda);
   675 
   676   /**
   677    * \brief call RandomVariable::GetValue
   678    * \return A floating point random value 
   679    *
   680    * Note: we have to re-implement this method here because the method is
   681    * overloaded below for the two-argument variant and the c++ name resolution
   682    * rules don't work well with overloads split between parent and child
   683    * classes.
   684    */
   685   double GetValue (void) const;
   686   
   687   /**
   688    * \brief Returns an Erlang random distributed double with parameters k and lambda.
   689    * \param k k parameter of the Erlang distribution. Must be a non-negative integer.
   690    * \param lambda lambda parameter of the Erlang distribution
   691    * \return A floating point random value
   692    */
   693   double GetValue(unsigned int k, double lambda) const;
   694 };
   695 
   696 /**
   697  * \brief Zipf Distributed random var (between 1 and n included)
   698  * \ingroup randomvariable
   699  *
   700  */
   701 class ZipfVariable : public RandomVariable 
   702 {
   703 public:
   704   /**
   705    * \param n the number of possible items
   706    * \param alpha the alpha parameter
   707    */
   708   ZipfVariable (long n, double alpha);
   709   /**
   710    * A zipf variable with N=1 and alpha=0
   711    */
   712   ZipfVariable ();
   713 };
   714 
   715 /**
   716  * \brief Triangularly Distributed random var
   717  * \ingroup randomvariable
   718  * 
   719  * This distribution is a triangular distribution.  The probablility density
   720  * is in the shape of a triangle.
   721  */
   722 class TriangularVariable : public RandomVariable 
   723 {
   724 public:
   725   /**
   726    * Creates a triangle distribution random number generator in the
   727    * range [0.0 .. 1.0), with mean of 0.5
   728    */
   729   TriangularVariable();
   730 
   731   /**
   732    * Creates a triangle distribution random number generator with the specified
   733    * range
   734    * \param s Low end of the range
   735    * \param l High end of the range
   736    * \param mean mean of the distribution
   737    */
   738   TriangularVariable(double s, double l, double mean);
   739 
   740 };
   741 
   742 std::ostream &operator << (std::ostream &os, const RandomVariable &var);
   743 std::istream &operator >> (std::istream &os, RandomVariable &var);
   744 
   745 /**
   746  * \class ns3::RandomVariableValue
   747  * \brief hold objects of type ns3::RandomVariable
   748  */
   749 
   750 ATTRIBUTE_VALUE_DEFINE (RandomVariable);
   751 ATTRIBUTE_CHECKER_DEFINE (RandomVariable);
   752 ATTRIBUTE_ACCESSOR_DEFINE (RandomVariable);
   753 
   754 }//namespace ns3
   755 
   756 
   757 #endif