rndgen.h

Go to the documentation of this file.
00001 /*
00002  $Id: rndgen.h,v 1.4 2004/12/12 23:44:43 pecos Exp $ 
00003  */
00004 
00005 /* *********
00006 *  
00007 *  This file is part of:
00008 *  NePSing, Network Protocol Simulator next generation
00009 *  
00010 *  Copyright (C) 2004  Tommaso Pecorella <tpecorella@mac.com>
00011 *  
00012 *  This library is free software; you can redistribute it and/or
00013 *  modify it under the terms of the GNU Lesser General Public
00014 *  License as published by the Free Software Foundation; either
00015 *  version 2.1 of the License, or (at your option) any later version.
00016 *  
00017 *  This library is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 *  Lesser General Public License for more details.
00021 *  
00022 *  You should have received a copy of the GNU Lesser General Public
00023 *  License along with this library; if not, write to the Free Software
00024 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *  
00026 ********* */
00027 
00028 #include <stdlib.h>
00029 #include <math.h>
00030 
00031 #include <gsl/gsl_rng.h>
00032 #include <gsl/gsl_randist.h>
00033 
00034 #ifndef ___RNDGEN_H___
00035 #define ___RNDGEN_H___
00036 
00041 
00056 
00057 
00062 void SetSeed(char* genType,
00063              int seed);
00064 
00066 // generic functions w/o initalizers
00067 
00069 
00076 double rndUniformDouble(double low=0.0, double high=1.0);
00077 
00079 
00086 long int rndUniformInt(long int low=0, long int high=1);
00087 
00089 
00095 double rndExponential(double M);
00096 
00098 
00105 double rndGaussian(double M, double sigma);
00106 
00108 
00114 unsigned int rndGeometric0(double M);
00115 
00117 
00123 unsigned int rndGeometric1(double M);
00124 
00125 
00126 /***********************************************************************
00127 *                                                                      *
00128 *   Negative Binomial distribution                                     *
00129 *                                                                      *
00130 *     p(k) = (k + r -1 ) * p^r * (1-p)^k                               *
00131 *            (    k    )                                               *
00132 *                                                                      *
00133 *     mean     = r*(1-p)/p                                             *
00134 *     variance = r*(1-p)/p^2                                           *
00135 *                                                                      *
00136 ***********************************************************************/
00138 
00153 long int rndNegativeBinomial(long r, float p);
00154 
00155 
00156 /***********************************************************************
00157 *                                                                      *
00158 *   Pareto distribution                                                *
00159 *                                                                      *
00160 *     p(x) = (shape * location^shape)/(x^(shape+1))                    *
00161 *     P(x) = 1 - (location/x)^shape                                    *
00162 *     mean     = location * shape / (shape - 1)                        *
00163 *     variance = location^2 * shape / ( (shape -2) * (shape - 1)^2 )   *
00164 *                                                                      *
00165 ***********************************************************************/
00167 
00182 double rndPareto(double location, double shape);
00183         
00184 
00185 /**************************************************************************
00186 *                                                                         *
00187 *   Weibull distribution                                                  *
00188 *                                                                         *
00189 *        l = location, sh = shape, sc = scale, Gamma() = Gamma function   *
00190 *     p(x) = sh/sc * ((x-l)/sc)^(sh-1) * e^(-((x-l)/sc)^sh)               *
00191 *     P(x) = 1 - e^(-((x-l)/sc)^sh)                                       *
00192 *     mean     = l + sc*Gamma((sh+1)/sh)                                  *
00193 *     variance = sc^2 * ( Gamma((sh+2)/sh) - Gamma^2((sh+1)/sh) )         *
00194 *                                                                         *
00195 **************************************************************************/
00197 
00213 double rndWeibull(double location, double scale, double shape);
00214 
00216 
00230 double rndRayleigh(double sigma);
00231 
00233 
00240 void rndShuffle( void* vect, size_t size, size_t elem_size );
00241 
00242 
00244 
00248 class UniformDoubleRndGen
00249 {
00250 protected:
00251   double low, high;
00252   double range;
00253 
00254 public:
00255     UniformDoubleRndGen(double _low=0,  
00256                       double _high=1)   
00257     : low(_low), high(_high), range(_high-_low) {};
00258   
00260   double get(); 
00261 };
00262 
00264 
00268 class UniformIntRndGen
00269 {
00270 protected:
00271   long int low, high;
00272   long int range;
00273 public:
00274   UniformIntRndGen(long int _low=0, 
00275                    long int _high=1) 
00276     : low(_low), high(_high), range(_high-_low+1) {};
00277 
00279   long int get();
00280 };
00281 
00283 
00287 class ExponentialRndGen
00288 {
00289 protected:
00290   double meanExp;
00291 
00292 public:
00293   ExponentialRndGen(double _mean=0) 
00294   : meanExp(_mean) {};
00295   
00297   double get();
00298 };
00299 
00301 
00305 class GaussianRndGen
00306 {
00307 protected:
00308   double mean, sigma;
00309 
00310 public:
00311   GaussianRndGen(double _mean=0, 
00312                  double _sigma=0) 
00313   : mean(_mean), sigma(_sigma) {};
00314   
00316   double get();
00317 };
00318 
00320 
00324 class Geometric0RndGen
00325 {
00326 protected:
00327   double meanGeo0;
00328   double pGeo0;
00329 
00330 public:
00331   Geometric0RndGen(double _mean=0) 
00332     : meanGeo0(_mean)
00333   {
00334     if( _mean > 0 )
00335       pGeo0 = 1 / (_mean + 1);
00336   };
00337 
00338   
00340   unsigned long int get();
00341 };
00342 
00344 
00348 class Geometric1RndGen
00349 {
00350 protected:
00351   double meanGeo1;
00352   double pGeo1;
00353 
00354 public:
00355   Geometric1RndGen(double _mean=1) 
00356     : meanGeo1(_mean)
00357   {
00358     if( _mean > 1 )
00359       pGeo1 = 1 / _mean;
00360   };
00361   
00363   unsigned long int get();
00364 };
00365 
00367 
00379 class ParetoRndGen
00380 {
00381 protected:
00382   double location;
00383   double shape;
00384 
00385 public:
00386   ParetoRndGen(double _location=1, 
00387                double _shape=1) 
00388     : location(_location), shape(_shape)
00389   {};
00390 
00392   double get();
00393 };
00394 
00396 
00408 class WeibullRndGen
00409 {
00410 protected:
00411   double location;
00412   double scale;
00413   double shape;
00414 
00415 public:
00416   WeibullRndGen(double _location=1, 
00417                 double _scale=1, 
00418                 double _shape=1) 
00419     : location(_location), scale(_scale), shape(_shape)
00420   {};
00421   
00423   double get();
00424 };
00425 
00427 
00439 class RayleighRndGen
00440 {
00441 protected:
00442   double sigma;
00443 
00444 public:
00445   RayleighRndGen(double _sigma=1) 
00446     : sigma(_sigma)
00447   {};
00448   
00450   double get();
00451 };
00452 
00454 
00455 #endif
00456 
00457 
00458 /*
00459 $Log: rndgen.h,v $
00460 Revision 1.4  2004/12/12 23:44:43  pecos
00461 Added Copyright message - LGPL
00462 
00463 Revision 1.3  2004/12/11 23:53:24  pecos
00464 Added DoxyGen comments
00465 
00466 Revision 1.2  2004/08/11 16:32:44  pecos
00467 Added Shuffling
00468 
00469 Revision 1.1.1.1  2004/07/08 16:59:33  pecos
00470 NePSing framework
00471 
00472 Revision 1.6  2002/07/26 13:24:34  pecos
00473 Added Negative Binomial distribution
00474 
00475 Revision 1.1  2002/07/26 13:20:33  pecos
00476 *** empty log message ***
00477 
00478 Revision 1.5  2001/03/17 09:47:56  pecos
00479 Added default params for Pareto and Weibull
00480 
00481 Revision 1.4  2000/02/24 08:36:21  pecos
00482 no message
00483 
00484 Revision 1.3  1999/09/11 09:14:13  pecos
00485 *** empty log message ***
00486 
00487 Revision 1.2  1999/05/28 23:54:48  pecos
00488 no message
00489 
00490 Revision 1.1.1.1  1999/05/24 15:59:57  inesis
00491 INeSiS Project
00492 
00493 Revision 1.1.1.1  1999/05/24 15:17:20  inesis
00494 INeSiS Project
00495 
00496 Revision 1.2  1999/01/26 11:24:23  pecos
00497 *** empty log message ***
00498 
00499 Revision 1.2  1998/09/29 18:56:53  nanni
00500 *** empty log message ***
00501 
00502 Revision 1.1  1998/09/15 15:20:24  ronga
00503 Initial revision
00504 
00505 */
00506 

Generated on Wed Dec 22 23:23:48 2004 for NePSing by doxygen 1.3.9.1 ---- Hosted by SourceForge.net Logo