Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

rng.h

Go to the documentation of this file.
00001 // GENERAL PUBLIC LICENSE AGREEMENT
00002 // 
00003 // PLEASE READ THIS DOCUMENT CAREFULLY BEFORE UTILIZING THE PROGRAM
00004 // 
00005 // BY UTILIZING THIS PROGRAM, YOU AGREE TO BECOME BOUND BY THE TERMS OF
00006 // THIS LICENSE.  IF YOU DO NOT AGREE TO THE TERMS OF THIS LICENSE, DO
00007 // NOT USE THIS PROGRAM OR ANY PORTION THEREOF IN ANY FORM OR MANNER.
00008 // 
00009 // This Program is licensed, not sold to you by GEORGIA TECH RESEARCH
00010 // CORPORATION ("GTRC"), owner of all code and accompanying documentation
00011 // (hereinafter "Program"), for use only under the terms of this License,
00012 // and GTRC reserves any rights not expressly granted to you.
00013 // 
00014 // 1.  This License allows you to:
00015 // 
00016 // (a) make copies and distribute copies of the Program's source code
00017 // provide that any such copy clearly displays any and all appropriate
00018 // copyright notices and disclaimer of warranty as set forth in Article 5
00019 // and 6 of this License.  All notices that refer to this License and to
00020 // the absence of any warranty must be kept intact at all times.  A copy
00021 // of this License must accompany any and all copies of the Program
00022 // distributed to third parties.
00023 // 
00024 // A fee may be charged to cover the cost associated with the physical
00025 // act of transferring a copy to a third party.  At no time shall the
00026 // program be sold for commercial gain either alone or incorporated with
00027 // other program(s) without entering into a separate agreement with GTRC.
00028 //  
00029 // 
00030 // (b) modify the original copy or copies of the Program or any portion
00031 // thereof ("Modification(s)").  Modifications may be copied and
00032 // distributed under the terms and conditions as set forth above,
00033 // provided the following conditions are met:
00034 // 
00035 //     i) any and all modified files must be affixed with prominent
00036 // notices that you have changed the files and the date that the changes
00037 // occurred.
00038 //              
00039 //     ii) any work that you distribute, publish, or make available, that
00040 // in whole or in part contains portions of the Program or derivative
00041 // work thereof, must be licensed at no charge to all third parties under
00042 // the terms of this License.
00043 // 
00044 //    iii) if the modified program normally reads commands interactively
00045 // when run, you must cause it, when started running for such interactive
00046 // use in the most ordinary way, to display and/or print an announcement
00047 // with all appropriate copyright notices and disclaimer of warranty as
00048 // set forth in Article 5 and 6 of this License to be clearly displayed.
00049 // In addition, you must provide reasonable access to this License to the
00050 // user.
00051 // 
00052 // Any portion of a Modification that can be reasonably considered
00053 // independent of the Program and separate work in and of itself is not
00054 // subject to the terms and conditions set forth in this License as long
00055 // as it is not distributed with the Program or any portion thereof.
00056 // 
00057 // 
00058 // 2. This License further allows you to copy and distribute the Program
00059 //    or a work based on it, as set forth in Article 1 Section b in
00060 //    object code or executable form under the terms of Article 1 above
00061 //    provided that you also either:
00062 // 
00063 //    i) accompany it with complete corresponding machine-readable source
00064 // code, which must be distributed under the terms of Article 1, on a
00065 // medium customarily used for software interchange; or,
00066 // 
00067 //   ii) accompany it with a written offer, valid for no less than three
00068 // (3) years from the time of distribution, to give any third party, for
00069 // no consideration greater than the cost of physical transfer, a
00070 // complete machine-readable copy of the corresponding source code, to be
00071 // distributed under the terms of Article 1 on a medium customarily used
00072 // for software interchange; or,
00073 // 
00074 // 
00075 // 3.  Export Law Assurance.
00076 // 
00077 // You agree that the Software will not be shipped, transferred or
00078 // exported, directly into any country prohibited by the United States
00079 // Export Administration Act and the regulations thereunder nor will be
00080 // used for any purpose prohibited by the Act.
00081 //  
00082 // 4.  Termination.
00083 // 
00084 // If at anytime you are unable to comply with any portion of this
00085 // License you must immediately cease use of the Program and all
00086 // distribution activities involving the Program or any portion thereof.
00087 // 
00088 // 
00089 // 5.  Disclaimer of Warranties and Limitation on Liability.
00090 // 
00091 // YOU ACCEPT THE PROGRAM ON AN "AS IS" BASIS.  GTRC MAKES NO WARRANTY
00092 // THAT ALL ERRORS CAN BE OR HAVE BEEN ELIMINATED FROM PROGRAM.  GTRC
00093 // SHALL NOT BE RESPONSIBLE FOR LOSSES OF ANY KIND RESULTING FROM THE USE
00094 // OF PROGRAM AND ITS ACCOMPANYING DOCUMENT(S), AND CAN IN NO WAY PROVIDE
00095 // COMPENSATION FOR ANY LOSSES SUSTAINED, INCLUDING BUT NOT LIMITED TO
00096 // ANY OBLIGATION, LIABILITY, RIGHT, CLAIM OR REMEDY FOR TORT, OR FOR ANY
00097 // ACTUAL OR ALLEGED INFRINGEMENT OF PATENTS, COPYRIGHTS, TRADE SECRETS,
00098 // OR SIMILAR RIGHTS OF THIRD PARTIES, NOR ANY BUSINESS EXPENSE, MACHINE
00099 // DOWNTIME OR DAMAGES CAUSED TO YOU BY ANY DEFICIENCY, DEFECT OR ERROR
00100 // IN PROGRAM OR MALFUNCTION THEREOF, NOR ANY INCIDENTAL OR CONSEQUENTIAL
00101 // DAMAGES, HOWEVER CAUSED.  GTRC DISCLAIMS ALL WARRANTIES, BOTH EXPRESS
00102 // AND IMPLIED RESPECTING THE USE AND OPERATION OF PROGRAM AND ITS
00103 // ACCOMPANYING DOCUMENTATION, INCLUDING ALL IMPLIED WARRANTIES OF
00104 // MERCHANTABILITY AND FITNESS FOR PARTICULAR PURPOSE AND ANY IMPLIED
00105 // WARRANTY ARISING FROM COURSE OF PERFORMANCE, COURSE OF DEALING OR
00106 // USAGE OF TRADE.  GTRC MAKES NO WARRANTY THAT PROGRAM IS ADEQUATELY OR
00107 // COMPLETELY DESCRIBED IN, OR BEHAVES IN ACCORDANCE WITH ANY
00108 // ACCOMPANYING DOCUMENTATION.  THE USER OF PROGRAM IS EXPECTED TO MAKE
00109 // THE FINAL EVALUATION OF PROGRAM'S USEFULNESS IN USER'S OWN
00110 // ENVIRONMENT.
00111 // 
00112 // GTRC represents that, to the best of its knowledge, the software
00113 // furnished hereunder does not infringe any copyright or patent.
00114 // 
00115 // GTRC shall have no obligation for support or maintenance of Program.
00116 // 
00117 // 6.  Copyright Notice.
00118 // 
00119 // THE SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE COPYRIGHTED WITH ALL
00120 // RIGHTS RESERVED BY GTRC.  UNDER UNITED STATES COPYRIGHT LAWS, THE
00121 // SOFTWARE AND ITS ACCOMPANYING DOCUMENTATION MAY NOT BE COPIED EXCEPT
00122 // AS GRANTED HEREIN.
00123 // 
00124 // You acknowledge that GTRC is the sole owner of Program, including all
00125 // copyrights subsisting therein.  Any and all copies or partial copies
00126 // of Program made by you shall bear the copyright notice set forth below
00127 // and affixed to the original version or such other notice as GTRC shall
00128 // designate.  Such notice shall also be affixed to all improvements or
00129 // enhancements of Program made by you or portions thereof in such a
00130 // manner and location as to give reasonable notice of GTRC's copyright
00131 // as set forth in Article 1.
00132 // 
00133 // Said copyright notice shall read as follows:
00134 // 
00135 // Copyright 2004
00136 // Dr. George F. Riley
00137 // Georgia Tech Research Corporation
00138 // Atlanta, Georgia 30332-0415
00139 // All Rights Reserved
00140 //
00141 // $Id: rng.h 460 2006-01-31 20:48:39Z riley $
00142 
00143 
00144 
00145 // Georgia Tech Network Simulator - Random Number class
00146 // George F. Riley.  Georgia Tech, Spring 2002
00147 
00148 // Random is base class for all random number generators
00149 
00150 #ifndef __random_h__
00151 #define __random_h__
00152 
00153 #include <vector>
00154 #include <algorithm>
00155 
00156 #include "common-defs.h"
00157 #include "RngStream.h"
00158 
00159 typedef double        Random_t;  // Real Random Variable
00160 typedef unsigned long IRandom_t; // Integer Random Variable
00161 typedef double        CDF_t;     // Cumulative distribution Function value
00162 typedef unsigned long Seed_t;
00163 
00164 class Uniform;
00165 
00166 class Seed {
00167   // Seed is used to seed the random number generator(s)
00168   // This is a base class for RandomSeed and ConstantSeed
00169   // No constructors supplied, since we can't create any of these
00170 public:
00171   virtual ~Seed() {}
00172   virtual bool IsRandom() const = 0;
00173 };
00174 
00175 class RandomSeed : public Seed {
00176 public:
00177   RandomSeed() {};
00178   ~RandomSeed() {};
00179   bool IsRandom() const { return true; }
00180 };
00181 
00182 class ConstantSeed : public Seed 
00183 {
00184 public:
00185   ConstantSeed(Seed_t); // Use six copies of the specified value
00186   ConstantSeed(Seed_t,Seed_t,Seed_t,Seed_t,Seed_t,Seed_t);  // Six seeds
00187   bool IsRandom() const { return false; }
00188   ~ConstantSeed() {};
00189 public:
00190   Seed_t seeds[6];
00191 };
00192   
00193   
00194 //Doc:ClassXRef
00195 class Random { 
00196   //Doc:Class \GTNS\ has a rich set of  random number generators.
00197   //Doc:Class Class {\tt Random} defines the base class functionalty
00198   //Doc:Class required for all random number generators.
00199   //Doc:Class Note: The underlying random number generation method used
00200   //Doc:Class by \GTNS\ is the {\tt RngStream} code by Pierre L'Ecuyer at
00201   //Doc:Class the University of Montreal.
00202 public:
00203   //Doc:Method
00204   Random();
00205     //Doc:Desc Constructor for a random number generator with a random seed.
00206 
00207   virtual ~Random() { }
00208   //Doc:Method
00209   virtual Random_t  Value();     // Returns a value [0.0 .. 1.0)
00210     //Doc:Desc Return a floating point random value
00211     //Doc:Return Floating point random value.
00212 
00213   // Returns integer value
00214   //Doc:Method
00215   virtual IRandom_t IntValue() { return (IRandom_t)Value();}
00216     //Doc:Desc Return an integer random value.
00217     //Doc:Return Integer random value.
00218 
00219   virtual Random*   Copy() const;
00220 
00221   // Static methods
00222 
00223   //Doc:Method
00224   bool SetSeed(const Seed&);
00225     //Doc:Desc Use a private seed and private stream for this generator.
00226     //Doc:Arg1 Seed to use.  Can either be a RandomSeed or ConstantSeed.
00227     //Doc:Return True if valid seed.
00228 
00229 
00230   //Doc:Method
00231   static  void UseDevRandom(bool udr = true) { useDevRandom = udr;}
00232     //Doc:Desc Specify whether the linux device {\tt /dev/random} is to
00233     //Doc:Desc be used for a random seed.
00234     //Doc:Arg1 True if {\tt /dev/random} desired.
00235 
00236   // Use the global seed to force precisely reproducible results.
00237   //Doc:Method
00238   static bool GlobalSeed(Seed_t,Seed_t,Seed_t,Seed_t,Seed_t,Seed_t) ;
00239     //Doc:Desc It is often desirable to create a simulation that uses random
00240     //Doc:Desc numbers, while at the same time is completely reproducible.
00241     //Doc:Desc Specifying this set of six random seeds initializes the
00242     //Doc:Desc random number generator with the specified seed.
00243     //Doc:Desc This leads to precisely reproducible results.
00244     //Doc:Desc Note. This constructor is deprecated.  New code should use 
00245     //Doc:Desc the GlobalSeed call with a Seed class argument (below).
00246     //Doc:Arg1 Seed to use (32 bit unsigned)
00247     //Doc:Arg2 Seed to use (32 bit unsigned)
00248     //Doc:Arg3 Seed to use (32 bit unsigned)
00249     //Doc:Arg4 Seed to use (32 bit unsigned)
00250     //Doc:Arg5 Seed to use (32 bit unsigned)
00251     //Doc:Arg6 Seed to use (32 bit unsigned)
00252     //Doc:Return True if seed is valid.
00253 
00254   //Doc:Method
00255   static bool GlobalSeed(const Seed&);
00256     //Doc:Desc It is often desirable to create a simulation that uses random
00257     //Doc:Desc numbers, while at the same time is completely reproducible.
00258     //Doc:Desc Specifying this set of six random seeds initializes the
00259     //Doc:Desc random number generator with the specified seed.
00260     //Doc:Desc This leads to precisely reproducible results.
00261     //Doc:Arg1 Seed to use.  Can either be a RandomSeed or ConstantSeed.
00262     //Doc:Return True if seed is valid.
00263 
00264 private:
00265   RngStream* privateStream;    // Private stream for generator (if specified)
00266   static void Initialize();    // Initialize  the RNG system
00267   static void GetRandomSeeds(Seed_t seeds[6]);
00268 private:
00269   static bool useDevRandom;    // True if using /dev/random desired
00270   static bool globalSeedSet;   // True if global seed has been specified
00271   static int  devRandom;       // File handle for /dev/random
00272   static Seed_t globalSeed[6]; // The global seed to use
00273 protected:
00274   static unsigned long heuristic_sequence;
00275   static RngStream* globalRNG;
00276 public:
00277 };
00278 
00279 
00280 //Doc:ClassXRef
00281 class Uniform : public Random { // Uniformly distributed random variable
00282   //Doc:Class Creates a uniformly distributed random number generator.
00283 public:
00284   //Doc:Method
00285   Uniform() : m_min(0), m_max(1.0) { }
00286     //Doc:Desc Creates a uniform random number generator in the
00287     //Doc:Desc range [0.0 .. 1.0)
00288 
00289   //Doc:Method
00290   Uniform(Random_t s, Random_t l) : m_min(s), m_max(l) { };
00291     //Doc:Desc Creates a uniform random number generator with the specified
00292     //Doc:Desc range.
00293 
00294   Uniform(const Uniform& c) : m_min(c.m_min), m_max(c.m_max) { }
00295   virtual Random_t Value();
00296   virtual Random*  Copy() const;
00297 private:
00298   Random_t m_min;
00299   Random_t m_max;
00300 };
00301 
00302 //Doc:ClassXRef
00303 class Constant : public Random { // A random variable that returns a constant
00304   //Doc:Class Class {\tt Constant} defines a random number generator that
00305   //Doc:Class returns the same value every sample.  It's not immediately
00306   //Doc:Class obvious
00307   //Doc:Class why such a generator is useful, but it is.  A number of other
00308   //Doc:Class \GTNS\ objects require a random number generator as parameters
00309   //Doc:Class to describe the behavior.  For example, application {\tt TCPSend}
00310   //Doc:Class uses a random number generator to determine how much data
00311   //Doc:Class to send.  By passing a {\tt Constant} RNG to the {\tt TCPSend}
00312   //Doc:Class application, it will send a known constant amount.
00313 
00314 public:
00315   //Doc:Method
00316   Constant() : m_const(0) { }
00317     //Doc:Desc Construct a {\tt Constant} RNG that return zero every sample.
00318 
00319   //Doc:Method
00320   Constant(Random_t c) : m_const(c) { };
00321     //Doc:Desc Construct a {\tt Constant} RNG that returns the specified value
00322     //Doc:Desc every sample.
00323     //Doc:Arg1 Constant value for this RNG.
00324 
00325   Constant(const Constant& c) : m_const(c.m_const) { }
00326   //Doc:Method
00327   void    NewConstant(Random_t c) { m_const = c;}
00328     //Doc:Desc Specify a new constant RNG for this generator.
00329     //Doc:Arg1 Constant value for this RNG.
00330 
00331   virtual Random_t  Value();
00332   virtual IRandom_t IntValue();
00333   virtual Random*   Copy() const;
00334 private:
00335   Random_t m_const;
00336 };
00337 
00338 //Doc:ClassXRef
00339 class Sequential : public Random { // Return a sequential list of values
00340   //Doc:Class Class {\tt Sequential} defines a random number generator that
00341   //Doc:Class returns a sequential sequence.
00342 public:
00343   // first, last, increment, consecutive
00344   //Doc:Method
00345   Sequential(Random_t f, Random_t l, Random_t i = 1, Count_t c = 1);
00346     //Doc:Desc Constructor for the {\tt Sequential} RNG.  The four parameters
00347     //Doc:Desc define the sequence.  For example {\tt Sequential(0, 5, 1, 2)}
00348     //Doc:Desc returns the sequence 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 0 \ldots
00349     //Doc:Arg1 First value returned.
00350     //Doc:Arg2 Last + 1 value returned.
00351     //Doc:Arg3 Increment.
00352     //Doc:Arg4 Repeat count for  each  value.
00353 
00354   //Doc:Method
00355   Sequential(Random_t f, Random_t l, const Random& i, Count_t c = 1);
00356     //Doc:Desc Constructor for the {\tt Sequential} RNG.
00357     //Doc:Desc Differs from the first constructor only in the fact that the
00358     //Doc:Desc increment paramenter is a random variable.
00359     //Doc:Arg1 First value returned.
00360     //Doc:Arg2 Last + 1 value returned.
00361     //Doc:Arg3 Reference to a random variable for the sequence increment.
00362     //Doc:Arg4 Repeat count for  each  value.
00363 
00364   Sequential(const Sequential& c);
00365   virtual Random_t Value();
00366   virtual Random*  Copy() const;
00367 private:
00368   Random_t m_min;
00369   Random_t m_max;
00370   Random*  m_increment;
00371   Count_t  m_consecutive;
00372   Random_t m_current;
00373   Count_t  m_currentConsecutive;
00374 };
00375 
00376 //Doc:ClassXRef
00377 class Exponential : public Random { // Exponentially Distributed random var
00378   //Doc:Class Class {\tt Exponential} defines a random variable with an
00379   //Doc:Class  exponential distribution.
00380 public:
00381   //Doc:Method
00382   Exponential() : m_mean(1.0), m_bound(0) { }
00383     //Doc:Desc Constructs an exponential random variable  with a mean
00384     //Doc:Desc value of 1.0.
00385 
00386   //Doc:Method
00387   explicit Exponential(Random_t m) : m_mean(m), m_bound(0) { };
00388     //Doc:Desc Constructs an exponential  random variable with the specified
00389     //Doc:Desc mean value.
00390     //Doc:Arg1 Mean value for the random variable.
00391 
00392   //Doc:Method
00393   Exponential(Random_t m, Random_t b) : m_mean(m), m_bound(b) { };
00394     //Doc:Desc Constructs an exponential randome variable  with the specified
00395     //Doc:Desc mean value and specified upper limit.  Since exponential
00396     //Doc:Desc distributions can theoretically return unbounded values,
00397     //Doc:Desc it is sometimes useful to specify  a fixed upper limit.
00398     //Doc:Desc Note however that when the upper limit is specified, the
00399     //Doc:Desc true mean of the distribution is slightly smaller than
00400     //Doc:Desc the mean value specified.
00401     //Doc:Arg1 Mean value for the random variable.
00402     //Doc:Arg2 Upper limit on returned values.
00403 
00404   Exponential(const Exponential& c) : m_mean(c.m_mean), m_bound(c.m_bound) { }
00405   virtual Random_t Value();
00406   virtual Random* Copy() const;
00407 private:
00408   Random_t m_mean;  // Mean value of RV
00409   Random_t m_bound; // Upper bound on value (if non-zero)
00410 };
00411 
00412 //Doc:ClassXRef
00413 class Pareto : public Random { // Pareto distributed random var
00414   //Doc:Class Class {\tt Pareto} defines a random variable with a
00415   //Doc:Class pareto distribution.
00416 public:
00417   //Doc:Method
00418   Pareto() : m_mean(1.0), m_shape(1.5), m_bound(0) { }
00419     //Doc:Desc Constructs a pareto random variable  with a mean
00420     //Doc:Desc value of 1.0 and a shape (alpha) parameter of 1.5.
00421 
00422   //Doc:Method
00423   explicit Pareto(Random_t m) 
00424     : m_mean(m), m_shape(1.5), m_bound(0) { };
00425     //Doc:Desc Constructs a pareto random variable with the specified mean
00426     //Doc:Desc value and a shape (alpha) parameter of 1.5.
00427     //Doc:Arg1 Mean value for the distribution.
00428 
00429   //Doc:Method
00430   Pareto(Random_t m, Random_t s) 
00431     : m_mean(m), m_shape(s), m_bound(0) { };
00432     //Doc:Desc Constructs a pareto random variable with the specified mean
00433     //Doc:Desc value and shape (alpha).
00434     //Doc:Arg1 Mean value for the distribution.
00435     //Doc:Arg2 Shape (alpha) parameter for the distribution.
00436 
00437   //Doc:Method
00438   Pareto(Random_t m, Random_t s, Random_t b) 
00439     : m_mean(m), m_shape(s), m_bound(b) { };
00440     //Doc:Desc Constructs a pareto random variable with the specified mean
00441     //Doc:Desc value, shape (alpha), and upper bound.
00442     //Doc:Desc Since pareto 
00443     //Doc:Desc distributions can theoretically return unbounded values,
00444     //Doc:Desc it is sometimes useful to specify  a fixed upper limit.
00445     //Doc:Desc Note however that when the upper limit is specified, the
00446     //Doc:Desc true mean of the distribution is slightly smaller than
00447     //Doc:Desc the mean value specified.
00448     //Doc:Arg1 Mean value for the random variable.
00449     //Doc:Arg2 Shape (alpha) parameter for the distribution.
00450     //Doc:Arg3 Upper limit on returned values.
00451 
00452   Pareto(const Pareto& c) 
00453     : m_mean(c.m_mean), m_shape(c.m_shape), m_bound(c.m_bound) { }
00454   virtual Random_t Value();
00455   virtual Random* Copy() const;
00456 private:
00457   Random_t m_mean;  // Mean value of RV
00458   Random_t m_shape; // Shape parameter
00459   Random_t m_bound; // Upper bound on value (if non-zero)
00460 };
00461 
00462 //Doc:ClassXRef
00463 class Weibull : public Random { // Weibull distributed random var
00464   //Doc:Class Class {\tt Weibull} defines a random variable with a
00465   //Doc:Class weibull distribution.
00466 public:
00467   //Doc:Method
00468   Weibull() : m_mean(1.0), m_alpha(1), m_bound(0) { }
00469     //Doc:Desc Constructs a weibull random variable  with a mean
00470     //Doc:Desc value of 1.0 and a shape (alpha) parameter of 1
00471 
00472   //Doc:Method
00473   explicit Weibull(Random_t m) 
00474     : m_mean(m), m_alpha(1), m_bound(0) { };
00475     //Doc:Desc Constructs a weibull random variable with the specified mean
00476     //Doc:Desc value and a shape (alpha) parameter of 1.5.
00477     //Doc:Arg1 Mean value for the distribution.
00478 
00479   //Doc:Method
00480   Weibull(Random_t m, Random_t s) 
00481     : m_mean(m), m_alpha(s), m_bound(0) { };
00482     //Doc:Desc Constructs a weibull random variable with the specified mean
00483     //Doc:Desc value and a shape (alpha).
00484     //Doc:Arg1 Mean value for the distribution.
00485     //Doc:Arg2 Shape (alpha) parameter for the distribution.
00486 
00487   //Doc:Method
00488   Weibull(Random_t m, Random_t s, Random_t b) 
00489     : m_mean(m), m_alpha(s), m_bound(b) { };
00490     //Doc:Desc Constructs a weibull random variable with the specified mean
00491     //Doc:Desc value, alpha, and upper bound.
00492     //Doc:Desc Since weibull 
00493     //Doc:Desc distributions can theoretically return unbounded values,
00494     //Doc:Desc it is sometimes useful to specify  a fixed upper limit.
00495     //Doc:Desc Note however that when the upper limit is specified, the
00496     //Doc:Desc true mean of the distribution is slightly smaller than
00497     //Doc:Desc the mean value specified.
00498     //Doc:Arg1 Mean value for the random variable.
00499     //Doc:Arg2 Shape (alpha) parameter for the distribution.
00500     //Doc:Arg3 Upper limit on returned values.
00501 
00502   Weibull(const Weibull& c) 
00503     : m_mean(c.m_mean), m_alpha(c.m_alpha), m_bound(c.m_bound) { }
00504   virtual Random_t Value();
00505   virtual Random* Copy() const;
00506 private:
00507   Random_t m_mean;  // Mean value of RV
00508   Random_t m_alpha; // Shape parameter
00509   Random_t m_bound; // Upper bound on value (if non-zero)
00510 };
00511 
00512 //Doc:ClassXRef
00513 class Normal : public Random { // Normally Distributed random var
00514   //Doc:Class Class {\tt Normal} defines a random variable with an
00515   //Doc:Class  exponential distribution.
00516 public:
00517   //Doc:Method
00518   Normal() : m_mean(0.0), m_variance(1.0), m_bound(INFINITE_VALUE),
00519                      m_nextValid(false) { }
00520     //Doc:Desc Constructs an normal random variable  with a mean
00521     //Doc:Desc value of 0 and variance of 1.
00522 
00523   //Doc:Method
00524   Normal(Random_t m, Random_t v, Random_t b = INFINITE_VALUE)
00525       : m_mean(m), m_variance(v), m_bound(b), m_nextValid(false) { };
00526     //Doc:Desc Constructs an normal random variable with the specified
00527     //Doc:Desc mean and variance values.
00528     //Doc:Arg1 Mean value for the random variable.
00529     //Doc:Arg2 Variance for the random variable.
00530     //Doc:Arg1 Bound value for the random variable.  The bound is
00531     //Doc:Arg1 positive.  The Normal is bounded within +- bound.
00532 
00533   Normal(const Normal& c)
00534       : m_mean(c.m_mean), m_variance(c.m_variance), m_bound(c.m_bound) { }
00535   virtual Random_t Value();
00536   virtual Random* Copy() const;
00537 private:
00538   Random_t m_mean;      // Mean value of RV
00539   Random_t m_variance;  // Mean value of RV
00540   Random_t m_bound;     // Bound on value (absolute value)
00541   bool     m_nextValid; // True if next valid
00542   Random_t m_next;      // The algorithm produces two values at a time
00543 };
00544 
00545 // Value/CDF pair class for Emiprical Distributions
00546 //Doc:ClassXRef
00547 class ValueCDF {
00548 public:
00549   ValueCDF() : value(0.0), cdf(0.0){ }
00550   ValueCDF(Random_t v, CDF_t c) : value(v), cdf(c) { }
00551   ValueCDF(const ValueCDF& c) : value(c.value), cdf(c.cdf) { }
00552   Random_t value;
00553   CDF_t    cdf;
00554 };
00555 
00556 typedef std::vector<ValueCDF> ValueCDFVec_t;
00557 
00558 //Doc:ClassXRef
00559 class Empirical : public Random { // Empirical distribution random var
00560   //Doc:Class Defines a random variable  that has a specified, empirical 
00561   //Doc:Class distribution.  The distribution is specified by a
00562   //Doc:Class series of calls the the {\tt CDF} member function, specifying a
00563   //Doc:Class value and the probability that the function value is less than
00564   //Doc:Class the specified value.  When values are requested,
00565   //Doc:Class a uniform random variable is used to select a probabililty,
00566   //Doc:Class and the return value is interpreted linerarly between the
00567   //Doc:Class two appropriate points in the CDF.
00568 public:
00569   //Doc:Method
00570   explicit Empirical() : validated(false) { }
00571     //Doc:Desc Constructor for the {\tt Empirical} random variables.
00572 
00573   virtual ~Empirical() { }
00574   Empirical(const Empirical& c) : validated(c.validated), emp(c.emp) { }
00575   virtual Random_t Value();
00576   virtual Random* Copy() const;
00577   //Doc:Method
00578   virtual void     CDF(Random_t, CDF_t);  // Value, prob <= Value
00579     //Doc:Desc Specifies  a point in the empirical distribution.
00580     //Doc:Arg1 The function value for this point.
00581     //Doc:Arg2 Probability that the function is less than or equal
00582     //Doc:Arg2 to the specified value.
00583 private:
00584   virtual void     Validate();  // Insure non-decreasing emiprical values
00585   virtual Random_t Interpolate(CDF_t, CDF_t, Random_t, Random_t, CDF_t);
00586   bool               validated; // True if non-decreasing validated
00587   ValueCDFVec_t      emp;       // Empicical CDF
00588 };
00589 
00590 //Doc:ClassXRef
00591 class IntEmpirical : public Empirical { // Empirical distribution, integer
00592   //Doc:Class Defines an empirical distribution where all values are integers.
00593   //Doc:Class Indentical to {\tt Empirical}, but with slightly different
00594   //Doc:Class interpolation between points.
00595   // Identical to Empirical, but slightly different interpolation
00596 public:
00597   //Doc:Method
00598   IntEmpirical() { }
00599     //Doc:Desc Constructor for {\tt IntEmpirical}
00600 
00601   virtual Random* Copy() const;
00602   virtual IRandom_t IntValue();
00603   virtual Random_t Interpolate(CDF_t, CDF_t, Random_t, Random_t, CDF_t);
00604 };
00605 
00606 //Doc:ClassXRef
00607 class Deterministic : public Random { // Deterministic distribution random var
00608   //Doc:Class Defines a random variable  that has a specified, deterministic
00609   //Doc:Class distribution.  This would be useful when trying to force
00610   //Doc:Class the RNG to return a known sequence, perhaps to
00611   //Doc:Class compare GTNetS to some other simulator
00612 public:
00613   //Doc:Method
00614   explicit Deterministic(Random_t*, Count_t);
00615     //Doc:Desc Constructor for the {\tt Deterministic} random variables.
00616     //Doc:Arg1 Pointer to array of random values to return in sequence
00617     //Doc:Arg2 Number of values in the array.
00618 
00619   virtual ~Deterministic() { }
00620   virtual Random_t Value();
00621   virtual Random* Copy() const;
00622 private:
00623   Count_t   count;
00624   Count_t   next;
00625   Random_t* data;
00626 };
00627 
00628 
00629 #endif

Generated on Wed Aug 27 16:17:14 2008 for Georgia Tech Network Simulator (GTNetS) by  doxygen 1.3.9.1