00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 // 00003 // Copyright (c) 2006 Georgia Tech Research Corporation 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License version 2 as 00007 // published by the Free Software Foundation; 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 // 00018 // Author: Rajib Bhattacharjea<raj.b@gatech.edu> 00019 // 00020 00021 #ifndef __random_variable_h__ 00022 #define __random_variable_h__ 00023 00024 #include <vector> 00025 #include <algorithm> 00026 #include <stdint.h> 00027 #include <istream> 00028 #include <ostream> 00029 #include "attribute.h" 00030 #include "attribute-helper.h" 00031 00032 /** 00033 * \ingroup core 00034 * \defgroup randomvariable Random Variable Distributions 00035 * 00036 */ 00037 00038 namespace ns3 { 00039 00040 class RandomVariableBase; 00041 00042 /** 00043 * \brief The basic RNG for NS-3. 00044 * \ingroup randomvariable 00045 * 00046 * Note: The underlying random number generation method used 00047 * by NS-3 is the RngStream code by Pierre L'Ecuyer at 00048 * the University of Montreal. 00049 * 00050 * NS-3 has a rich set of random number generators. 00051 * Class RandomVariable defines the base class functionalty 00052 * required for all random number generators. By default, the underlying 00053 * generator is seeded with the time of day, and then deterministically 00054 * creates a sequence of seeds for each subsequent generator that is created. 00055 * The rest of the documentation outlines how to change this behavior. 00056 */ 00057 class RandomVariable 00058 { 00059 public: 00060 RandomVariable(); 00061 RandomVariable(const RandomVariable&o); 00062 RandomVariable &operator = (const RandomVariable &o); 00063 ~RandomVariable(); 00064 00065 /** 00066 * \brief Returns a random double from the underlying distribution 00067 * \return A floating point random value 00068 */ 00069 double GetValue (void) const; 00070 00071 /** 00072 * \brief Returns a random integer integer from the underlying distribution 00073 * \return Integer cast of ::GetValue() 00074 */ 00075 uint32_t GetInteger (void) const; 00076 00077 /** 00078 * \brief Get the internal state of the RNG 00079 * 00080 * This function is for power users who understand the inner workings 00081 * of the underlying RngStream method used. It returns the internal 00082 * state of the RNG via the input parameter. 00083 * \param seed Output parameter; gets overwritten with the internal state of 00084 * of the RNG. 00085 */ 00086 void GetSeed(uint32_t seed[6]) const; 00087 00088 /** 00089 * \brief Set seeding behavior 00090 * 00091 * Specify whether the POSIX device /dev/random is to 00092 * be used for seeding. When this is used, the underlying 00093 * generator is seeded with data from /dev/random instead of 00094 * being seeded based upon the time of day. For this to be effective, 00095 * it must be called before the creation of the first instance of a 00096 * RandomVariable or subclass. Example: 00097 * \code 00098 * RandomVariable::UseDevRandom(); 00099 * UniformVariable x(2,3); //these are seeded randomly 00100 * ExponentialVariable y(120); //etc 00101 * \endcode 00102 * \param udr True if /dev/random desired. 00103 */ 00104 static void UseDevRandom(bool udr = true); 00105 00106 /** 00107 * \brief Use the global seed to force precisely reproducible results. 00108 * 00109 * It is often desirable to create a simulation that uses random 00110 * numbers, while at the same time is completely reproducible. 00111 * Specifying this set of six random seeds initializes the 00112 * random number generator with the specified seed. 00113 * Once this is set, all generators will produce fixed output 00114 * from run to run. This is because each time a new generator is created, 00115 * the underlying RngStream deterministically creates a new seed based upon 00116 * the old one, hence a "stream" of RNGs. Example: 00117 * \code 00118 * RandomVariable::UseGlobalSeed(...); 00119 * UniformVariable x(2,3); //these will give the same output everytime 00120 * ExponentialVariable y(120); //as long as the seed stays the same 00121 * \endcode 00122 * \param s0 00123 * \param s1 00124 * \param s2 00125 * \param s3 00126 * \param s4 00127 * \param s5 00128 * \return True if seed is valid. 00129 */ 00130 static void UseGlobalSeed(uint32_t s0, uint32_t s1, uint32_t s2, 00131 uint32_t s3, uint32_t s4, uint32_t s5); 00132 00133 /** 00134 * \brief Set the run number of this simulation 00135 * 00136 * These RNGs have the ability to give independent sets of trials for a fixed 00137 * global seed. For example, suppose one sets up a simulation with 00138 * RandomVariables with a given global seed. Suppose the user wanted to 00139 * retry the same simulation with different random values for validity, 00140 * statistical rigor, etc. The user could either change the global seed and 00141 * re-run the simulation, or could use this facility to increment all of the 00142 * RNGs to a next substream state. This predictably advances the internal 00143 * state of all RandomVariables n steps. This should be called immediately 00144 * after the global seed is set, and before the creation of any 00145 * RandomVariables. For example: 00146 * \code 00147 * RandomVariable::UseGlobalSeed(1,2,3,4,5,6); 00148 * int N = atol(argv[1]); //read in run number from command line 00149 * RandomVariable::SetRunNumber(N); 00150 * UniformVariable x(0,10); 00151 * ExponentialVariable y(2902); 00152 * \endcode 00153 * In this example, N could successivly be equal to 1,2,3, etc. and the user 00154 * would continue to get independent runs out of the single simulation. For 00155 * this simple example, the following might work: 00156 * \code 00157 * ./simulation 0 00158 * ...Results for run 0:... 00159 * 00160 * ./simulation 1 00161 * ...Results for run 1:... 00162 * \endcode 00163 */ 00164 static void SetRunNumber(uint32_t n); 00165 00166 private: 00167 friend std::ostream &operator << (std::ostream &os, const RandomVariable &var); 00168 friend std::istream &operator >> (std::istream &os, RandomVariable &var); 00169 00170 RandomVariableBase *m_variable; 00171 protected: 00172 RandomVariable (const RandomVariableBase &variable); 00173 RandomVariableBase *Peek (void) const; 00174 }; 00175 00176 /** 00177 * \brief The uniform distribution RNG for NS-3. 00178 * \ingroup randomvariable 00179 * 00180 * This class supports the creation of objects that return random numbers 00181 * from a fixed uniform distribution. It also supports the generation of 00182 * single random numbers from various uniform distributions. 00183 * 00184 * The low end of the range is always included and the high end 00185 * of the range is always excluded. 00186 * \code 00187 * UniformVariable x(0,10); 00188 * x.GetValue(); //will always return numbers [0,10) 00189 * UniformVariable::GetSingleValue(100,1000); //returns a value [100,1000) 00190 * \endcode 00191 */ 00192 class UniformVariable : public RandomVariable 00193 { 00194 public: 00195 /** 00196 * Creates a uniform random number generator in the 00197 * range [0.0 .. 1.0). 00198 */ 00199 UniformVariable(); 00200 00201 /** 00202 * Creates a uniform random number generator with the specified range 00203 * \param s Low end of the range 00204 * \param l High end of the range 00205 */ 00206 UniformVariable(double s, double l); 00207 public: 00208 /** 00209 * \param s Low end of the range 00210 * \param l High end of the range 00211 * \return A uniformly distributed random number between s and l 00212 */ 00213 static double GetSingleValue(double s, double l); 00214 }; 00215 00216 /** 00217 * \brief A random variable that returns a constant 00218 * \ingroup randomvariable 00219 * 00220 * Class ConstantVariable defines a random number generator that 00221 * returns the same value every sample. 00222 */ 00223 class ConstantVariable : public RandomVariable { 00224 00225 public: 00226 /** 00227 * Construct a ConstantVariable RNG that returns zero every sample 00228 */ 00229 ConstantVariable(); 00230 00231 /** 00232 * Construct a ConstantVariable RNG that returns the specified value 00233 * every sample. 00234 * \param c Unchanging value for this RNG. 00235 */ 00236 ConstantVariable(double c); 00237 00238 /** 00239 * \brief Specify a new constant RNG for this generator. 00240 * \param c New constant value for this RNG. 00241 */ 00242 void SetConstant(double c); 00243 00244 }; 00245 00246 /** 00247 * \brief Return a sequential list of values 00248 * \ingroup randomvariable 00249 * 00250 * Class SequentialVariable defines a random number generator that 00251 * returns a sequential sequence. The sequence monotonically 00252 * increases for a period, then wraps around to the low value 00253 * and begins monotonicaly increasing again. 00254 */ 00255 class SequentialVariable : public RandomVariable 00256 { 00257 public: 00258 /** 00259 * \brief Constructor for the SequentialVariable RNG. 00260 * 00261 * The four parameters define the sequence. For example 00262 * SequentialVariable(0,5,1,2) creates a RNG that has the sequence 00263 * 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 0 ... 00264 * \param f First value of the sequence. 00265 * \param l One more than the last value of the sequence. 00266 * \param i Increment between sequence values 00267 * \param c Number of times each member of the sequence is repeated 00268 */ 00269 SequentialVariable(double f, double l, double i = 1, uint32_t c = 1); 00270 00271 /** 00272 * \brief Constructor for the SequentialVariable RNG. 00273 * 00274 * Differs from the first only in that the increment parameter is a 00275 * random variable 00276 * \param f First value of the sequence. 00277 * \param l One more than the last value of the sequence. 00278 * \param i Reference to a RandomVariable for the sequence increment 00279 * \param c Number of times each member of the sequence is repeated 00280 */ 00281 SequentialVariable(double f, double l, const RandomVariable& i, uint32_t c = 1); 00282 00283 }; 00284 00285 /** 00286 * \brief Exponentially Distributed random var 00287 * \ingroup randomvariable 00288 * 00289 * This class supports the creation of objects that return random numbers 00290 * from a fixed exponential distribution. It also supports the generation of 00291 * single random numbers from various exponential distributions. 00292 * 00293 * The probability density function of an exponential variable 00294 * is defined over the interval [0, +inf) as: 00295 * \f$ \alpha e^{-\alpha x} \f$ 00296 * where \f$ \alpha = \frac{1}{mean} \f$ 00297 * 00298 * The bounded version is defined over the internal [0,+inf) as: 00299 * \f$ \left\{ \begin{array}{cl} \alpha e^{-\alpha x} & x < bound \\ bound & x > bound \end{array}\right. \f$ 00300 * 00301 * \code 00302 * ExponentialVariable x(3.14); 00303 * x.GetValue(); //will always return with mean 3.14 00304 * ExponentialVariable::GetSingleValue(20.1); //returns with mean 20.1 00305 * ExponentialVariable::GetSingleValue(108); //returns with mean 108 00306 * \endcode 00307 * 00308 */ 00309 class ExponentialVariable : public RandomVariable 00310 { 00311 public: 00312 /** 00313 * Constructs an exponential random variable with a mean 00314 * value of 1.0. 00315 */ 00316 ExponentialVariable(); 00317 00318 /** 00319 * \brief Constructs an exponential random variable with a specified mean 00320 * \param m Mean value for the random variable 00321 */ 00322 explicit ExponentialVariable(double m); 00323 00324 /** 00325 * \brief Constructs an exponential random variable with spefified 00326 * \brief mean and upper limit. 00327 * 00328 * Since exponential distributions can theoretically return unbounded values, 00329 * it is sometimes useful to specify a fixed upper limit. Note however when 00330 * the upper limit is specified, the true mean of the distribution is 00331 * slightly smaller than the mean value specified. 00332 * \param m Mean value of the random variable 00333 * \param b Upper bound on returned values 00334 */ 00335 ExponentialVariable(double m, double b); 00336 00337 /** 00338 * \param m The mean of the distribution from which the return value is drawn 00339 * \param b The upper bound value desired, beyond which values get clipped 00340 * \return A random number from an exponential distribution with mean m 00341 */ 00342 static double GetSingleValue(double m, double b=0); 00343 }; 00344 00345 /** 00346 * \brief ParetoVariable distributed random var 00347 * \ingroup randomvariable 00348 * 00349 * This class supports the creation of objects that return random numbers 00350 * from a fixed pareto distribution. It also supports the generation of 00351 * single random numbers from various pareto distributions. 00352 * 00353 * The probability density function is defined over the range [\f$x_m\f$,+inf) as: 00354 * \f$ k \frac{x_m^k}{x^{k+1}}\f$ where \f$x_m > 0\f$ is called the location 00355 * parameter and \f$ k > 0\f$ is called the pareto index or shape. 00356 * 00357 * The parameter \f$ x_m \f$ can be infered from the mean and the parameter \f$ k \f$ 00358 * with the equation \f$ x_m = mean \frac{k-1}{k}, k > 1\f$. 00359 * 00360 * \code 00361 * ParetoVariable x(3.14); 00362 * x.GetValue(); //will always return with mean 3.14 00363 * ParetoVariable::GetSingleValue(20.1); //returns with mean 20.1 00364 * ParetoVariable::GetSingleValue(108); //returns with mean 108 00365 * \endcode 00366 */ 00367 class ParetoVariable : public RandomVariable 00368 { 00369 public: 00370 /** 00371 * Constructs a pareto random variable with a mean of 1 and a shape 00372 * parameter of 1.5 00373 */ 00374 ParetoVariable (); 00375 00376 /** 00377 * Constructs a pareto random variable with specified mean and shape 00378 * parameter of 1.5 00379 * \param m Mean value of the distribution 00380 */ 00381 explicit ParetoVariable(double m); 00382 00383 /** 00384 * Constructs a pareto random variable with the specified mean value and 00385 * shape parameter. 00386 * \param m Mean value of the distribution 00387 * \param s Shape parameter for the distribution 00388 */ 00389 ParetoVariable(double m, double s); 00390 00391 /** 00392 * \brief Constructs a pareto random variable with the specified mean 00393 * \brief value, shape (alpha), and upper bound. 00394 * 00395 * Since pareto distributions can theoretically return unbounded values, 00396 * it is sometimes useful to specify a fixed upper limit. Note however 00397 * when the upper limit is specified, the true mean of the distribution 00398 * is slightly smaller than the mean value specified. 00399 * \param m Mean value 00400 * \param s Shape parameter 00401 * \param b Upper limit on returned values 00402 */ 00403 ParetoVariable(double m, double s, double b); 00404 00405 /** 00406 * \param m The mean value of the distribution from which the return value 00407 * is drawn. 00408 * \param s The shape parameter of the distribution from which the return 00409 * value is drawn. 00410 * \param b The upper bound to which to restrict return values 00411 * \return A random number from a Pareto distribution with mean m and shape 00412 * parameter s. 00413 */ 00414 static double GetSingleValue(double m, double s, double b=0); 00415 }; 00416 00417 /** 00418 * \brief WeibullVariable distributed random var 00419 * \ingroup randomvariable 00420 * 00421 * This class supports the creation of objects that return random numbers 00422 * from a fixed weibull distribution. It also supports the generation of 00423 * single random numbers from various weibull distributions. 00424 * 00425 * The probability density function is defined over the interval [0, +inf] 00426 * as: \f$ \frac{k}{\lambda}\left(\frac{x}{\lambda}\right)^{k-1}e^{-\left(\frac{x}{\lambda}\right)^k} \f$ 00427 * where \f$ k > 0\f$ is the shape parameter and \f$ \lambda > 0\f$ is the scale parameter. The 00428 * specified mean is related to the scale and shape parameters by the following relation: 00429 * \f$ mean = \lambda\Gamma\left(1+\frac{1}{k}\right) \f$ where \f$ \Gamma \f$ is the Gamma function. 00430 */ 00431 class WeibullVariable : public RandomVariable { 00432 public: 00433 /** 00434 * Constructs a weibull random variable with a mean 00435 * value of 1.0 and a shape (alpha) parameter of 1 00436 */ 00437 WeibullVariable(); 00438 00439 00440 /** 00441 * Constructs a weibull random variable with the specified mean 00442 * value and a shape (alpha) parameter of 1.5. 00443 * \param m mean value of the distribution 00444 */ 00445 WeibullVariable(double m) ; 00446 00447 /** 00448 * Constructs a weibull random variable with the specified mean 00449 * value and a shape (alpha). 00450 * \param m Mean value for the distribution. 00451 * \param s Shape (alpha) parameter for the distribution. 00452 */ 00453 WeibullVariable(double m, double s); 00454 00455 /** 00456 * \brief Constructs a weibull random variable with the specified mean 00457 * \brief value, shape (alpha), and upper bound. 00458 * Since WeibullVariable distributions can theoretically return unbounded values, 00459 * it is sometimes usefull to specify a fixed upper limit. Note however 00460 * that when the upper limit is specified, the true mean of the distribution 00461 * is slightly smaller than the mean value specified. 00462 * \param m Mean value for the distribution. 00463 * \param s Shape (alpha) parameter for the distribution. 00464 * \param b Upper limit on returned values 00465 */ 00466 WeibullVariable(double m, double s, double b); 00467 /** 00468 * \param m Mean value for the distribution. 00469 * \param s Shape (alpha) parameter for the distribution. 00470 * \param b Upper limit on returned values 00471 * \return Random number from a distribution specified by m,s, and b 00472 */ 00473 static double GetSingleValue(double m, double s, double b=0); 00474 }; 00475 00476 /** 00477 * \brief Class NormalVariable defines a random variable with a 00478 * normal (Gaussian) distribution. 00479 * \ingroup randomvariable 00480 * 00481 * This class supports the creation of objects that return random numbers 00482 * from a fixed normal distribution. It also supports the generation of 00483 * single random numbers from various normal distributions. 00484 * 00485 * The density probability function is defined over the interval (-inf,+inf) 00486 * as: \f$ \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{s\sigma^2}}\f$ 00487 * where \f$ mean = \mu \f$ and \f$ variance = \sigma^2 \f$ 00488 * 00489 */ 00490 class NormalVariable : public RandomVariable 00491 { 00492 public: 00493 /** 00494 * Constructs an normal random variable with a mean 00495 * value of 0 and variance of 1. 00496 */ 00497 NormalVariable(); 00498 00499 /** 00500 * \brief Construct a normal random variable with specified mean and variance. 00501 * \param m Mean value 00502 * \param v Variance 00503 */ 00504 NormalVariable(double m, double v); 00505 00506 /** 00507 * \brief Construct a normal random variable with specified mean and variance 00508 * \param m Mean value 00509 * \param v Variance 00510 * \param b Bound. The NormalVariable is bounded symetrically about the mean 00511 * [mean-bound,mean+bound] 00512 */ 00513 NormalVariable(double m, double v, double b); 00514 00515 /** 00516 * \param m Mean value 00517 * \param v Variance 00518 * \return A random number from a distribution specified by m, and v. 00519 */ 00520 static double GetSingleValue(double m, double v); 00521 00522 /** 00523 * \param m Mean value 00524 * \param v Variance 00525 * \param b Bound. The NormalVariable is bounded symetrically about the mean 00526 * [mean-bound,mean+bound] 00527 * \return A random number from a distribution specified by m,v, and b. 00528 */ 00529 static double GetSingleValue(double m, double v, double b); 00530 }; 00531 00532 /** 00533 * \brief EmpiricalVariable distribution random var 00534 * \ingroup randomvariable 00535 * 00536 * Defines a random variable that has a specified, empirical 00537 * distribution. The distribution is specified by a 00538 * series of calls to the CDF member function, specifying a 00539 * value and the probability that the function value is less than 00540 * the specified value. When values are requested, 00541 * a uniform random variable is used to select a probabililty, 00542 * and the return value is interpreted linerarly between the 00543 * two appropriate points in the CDF. The method is known 00544 * as inverse transform sampling: 00545 * (http://en.wikipedia.org/wiki/Inverse_transform_sampling). 00546 */ 00547 class EmpiricalVariable : public RandomVariable { 00548 public: 00549 /** 00550 * Constructor for the EmpiricalVariable random variables. 00551 */ 00552 explicit EmpiricalVariable(); 00553 00554 /** 00555 * \brief Specifies a point in the empirical distribution 00556 * \param v The function value for this point 00557 * \param c Probability that the function is less than or equal to v 00558 */ 00559 void CDF(double v, double c); // Value, prob <= Value 00560 protected: 00561 EmpiricalVariable (const RandomVariableBase &variable); 00562 }; 00563 00564 /** 00565 * \brief Integer-based empirical distribution 00566 * \ingroup randomvariable 00567 * 00568 * Defines an empirical distribution where all values are integers. 00569 * Indentical to EmpiricalVariable, except that the inverse transform 00570 * sampling interpolation described in the EmpiricalVariable documentation 00571 * is modified to only return integers. 00572 */ 00573 class IntEmpiricalVariable : public EmpiricalVariable 00574 { 00575 public: 00576 IntEmpiricalVariable(); 00577 }; 00578 00579 /** 00580 * \brief a non-random variable 00581 * \ingroup randomvariable 00582 * 00583 * Defines a random variable that has a specified, predetermined 00584 * sequence. This would be useful when trying to force 00585 * the RNG to return a known sequence, perhaps to 00586 * compare NS-3 to some other simulator 00587 */ 00588 class DeterministicVariable : public RandomVariable 00589 { 00590 public: 00591 /** 00592 * \brief Constructor 00593 * 00594 * Creates a generator that returns successive elements of the d array 00595 * on successive calls to ::Value(). Note that the d pointer is copied 00596 * for use by the generator (shallow-copy), not its contents, so the 00597 * contents of the array d points to have to remain unchanged for the use 00598 * of DeterministicVariable to be meaningful. 00599 * \param d Pointer to array of random values to return in sequence 00600 * \param c Number of values in the array 00601 */ 00602 explicit DeterministicVariable(double* d, uint32_t c); 00603 }; 00604 00605 /** 00606 * \brief Log-normal Distributed random var 00607 * \ingroup randomvariable 00608 * 00609 * LogNormalVariable defines a random variable with log-normal 00610 * distribution. If one takes the natural logarithm of random 00611 * variable following the log-normal distribution, the obtained values 00612 * follow a normal distribution. 00613 * This class supports the creation of objects that return random numbers 00614 * from a fixed lognormal distribution. It also supports the generation of 00615 * single random numbers from various lognormal distributions. 00616 * 00617 * The probability density function is defined over the interval [0,+inf) as: 00618 * \f$ \frac{1}{x\sigma\sqrt{2\pi}} e^{-\frac{(ln(x) - \mu)^2}{2\sigma^2}}\f$ 00619 * where \f$ mean = e^{\mu+\frac{\sigma^2}{2}} \f$ and 00620 * \f$ variance = (e^{\sigma^2}-1)e^{2\mu+\sigma^2}\f$ 00621 * 00622 * The \f$ \mu \f$ and \f$ \sigma \f$ parameters can be calculated from the mean 00623 * and standard deviation with the following equations: 00624 * \f$ \mu = ln(mean) - \frac{1}{2}ln\left(1+\frac{stddev}{mean^2}\right)\f$, and, 00625 * \f$ \sigma = \sqrt{ln\left(1+\frac{stddev}{mean^2}\right)}\f$ 00626 */ 00627 class LogNormalVariable : public RandomVariable 00628 { 00629 public: 00630 /** 00631 * \param mu mu parameter of the lognormal distribution 00632 * \param sigma sigma parameter of the lognormal distribution 00633 */ 00634 LogNormalVariable (double mu, double sigma); 00635 00636 /** 00637 * \param mu mu parameter of the underlying normal distribution 00638 * \param sigma sigma parameter of the underlying normal distribution 00639 * \return A random number from the distribution specified by mu and sigma 00640 */ 00641 static double GetSingleValue(double mu, double sigma); 00642 }; 00643 00644 /** 00645 * \brief Gamma Distributed Random Variable 00646 * \ingroup randomvariable 00647 * 00648 * GammaVariable defines a random variable with gamma distribution. 00649 * 00650 * This class supports the creation of objects that return random numbers 00651 * from a fixed gamma distribution. It also supports the generation of 00652 * single random numbers from various gamma distributions. 00653 * 00654 * The probability density function is defined over the interval [0,+inf) as: 00655 * \f$ x^{\alpha-1} \frac{e^{-\frac{x}{\beta}}}{\beta^\alpha \Gamma(\alpha)}\f$ 00656 * where \f$ mean = \alpha\beta \f$ and 00657 * \f$ variance = \alpha \beta^2\f$ 00658 */ 00659 class GammaVariable : public RandomVariable 00660 { 00661 public: 00662 /** 00663 * \param alpha alpha parameter of the gamma distribution 00664 * \param beta beta parameter of the gamma distribution 00665 */ 00666 GammaVariable (double alpha, double beta); 00667 00668 /** 00669 * \param alpha alpha parameter of the underlying gamma distribution 00670 * \param beta beta parameter of the underlying gamma distribution 00671 * \return A random number from the distribution specified by alpha and beta 00672 */ 00673 static double GetSingleValue(double alpha, double beta); 00674 }; 00675 00676 /** 00677 * \brief Erlang Distributed Random Variable 00678 * \ingroup randomvariable 00679 * 00680 * ErlangVariable defines a random variable with Erlang distribution. 00681 * 00682 * The Erlang distribution is a special case of the Gamma distribution where k 00683 * (= alpha) is a non-negative integer. Erlang distributed variables can be 00684 * generated using a much faster algorithm than gamma variables. 00685 * 00686 * This class supports the creation of objects that return random numbers from 00687 * a fixed Erlang distribution. It also supports the generation of single 00688 * random numbers from various Erlang distributions. 00689 * 00690 * The probability density function is defined over the interval [0,+inf) as: 00691 * \f$ \frac{x^{k-1} e^{-\frac{x}{\lambda}}}{\lambda^k (k-1)!}\f$ 00692 * where \f$ mean = k \lambda \f$ and 00693 * \f$ variance = k \lambda^2\f$ 00694 */ 00695 class ErlangVariable : public RandomVariable 00696 { 00697 public: 00698 /** 00699 * \param k k parameter of the Erlang distribution. Must be a non-negative integer. 00700 * \param lambda lambda parameter of the Erlang distribution 00701 */ 00702 ErlangVariable (double k, double lambda); 00703 00704 /** 00705 * \param k k parameter of the underlying Erlang distribution. Must be a non-negative integer. 00706 * \param lambda lambda parameter of the underlying Erlang distribution 00707 * \return A random number from the distribution specified by k and lambda 00708 */ 00709 static double GetSingleValue(double k, double lambda); 00710 }; 00711 00712 /** 00713 * \brief Triangularly Distributed random var 00714 * \ingroup randomvariable 00715 * 00716 * This distribution is a triangular distribution. The probablility density 00717 * is in the shape of a triangle. 00718 */ 00719 class TriangularVariable : public RandomVariable 00720 { 00721 public: 00722 /** 00723 * Creates a triangle distribution random number generator in the 00724 * range [0.0 .. 1.0), with mean of 0.5 00725 */ 00726 TriangularVariable(); 00727 00728 /** 00729 * Creates a triangle distribution random number generator with the specified 00730 * range 00731 * \param s Low end of the range 00732 * \param l High end of the range 00733 * \param mean mean of the distribution 00734 */ 00735 TriangularVariable(double s, double l, double mean); 00736 /** 00737 * \param s Low end of the range 00738 * \param l High end of the range 00739 * \param mean mean of the distribution 00740 * \return A triangularly distributed random number between s and l 00741 */ 00742 static double GetSingleValue(double s, double l, double mean); 00743 }; 00744 00745 std::ostream &operator << (std::ostream &os, const RandomVariable &var); 00746 std::istream &operator >> (std::istream &os, RandomVariable &var); 00747 00748 /** 00749 * \class ns3::RandomVariableValue 00750 * \brief hold objects of type ns3::RandomVariable 00751 */ 00752 00753 ATTRIBUTE_VALUE_DEFINE (RandomVariable); 00754 ATTRIBUTE_CHECKER_DEFINE (RandomVariable); 00755 ATTRIBUTE_ACCESSOR_DEFINE (RandomVariable); 00756 00757 }//namespace ns3 00758 00759 00760 #endif