RMOL Logo Get Revenue Management Optimisation Library at SourceForge.net. Fast, secure and Free Open Source software downloads

Gaussian.cpp

Go to the documentation of this file.
00001 
00002 // //////////////////////////////////////////////////////////////////////
00003 // Import section
00004 // //////////////////////////////////////////////////////////////////////
00005 // GSL Random Number Distributions (GSL Reference Manual, version 1.7,
00006 // Chapter 19)
00007 #include <gsl/gsl_randist.h>
00008 // RMOL
00009 #include <rmol/bom/Gaussian.hpp>
00010 
00011 namespace RMOL {
00012 
00013   // //////////////////////////////////////////////////////////////////////
00014   Gaussian::Gaussian () :
00015     _rngTypePtr (gsl_rng_default), _rngPtr (NULL),
00016     _params (FldDistributionParameters()) {
00017     initRandomGenerator();
00018   }
00019   
00020   // //////////////////////////////////////////////////////////////////////
00021   Gaussian::Gaussian (const Gaussian& iGaussian) :
00022     _rngTypePtr (gsl_rng_default), _rngPtr (NULL),
00023     _params (iGaussian.getDistributionParameters()) {
00024     initRandomGenerator();
00025   }
00026 
00027   // //////////////////////////////////////////////////////////////////////
00028   Gaussian::Gaussian (const FldDistributionParameters& iParams) :
00029     _rngTypePtr (gsl_rng_default), _rngPtr (NULL),
00030     _params (FldDistributionParameters (iParams.getMean(), 
00031                                         iParams.getStandardDeviation())) {
00032     initRandomGenerator();
00033   }
00034   
00035   // //////////////////////////////////////////////////////////////////////
00036   Gaussian::~Gaussian() {
00037     // Release the memory for the random generator
00038     gsl_rng_free (_rngPtr);
00039   }
00040   
00041   // //////////////////////////////////////////////////////////////////////
00042   double Gaussian::getMean() const {
00043     return _params.getMean();
00044   }
00045   
00046   // //////////////////////////////////////////////////////////////////////
00047   double Gaussian::getStandardDeviation() const {
00048     return _params.getStandardDeviation();
00049   }
00050 
00051   
00052   // //////////////////////////////////////////////////////////////////////
00053   double Gaussian::getVariance() const {
00054     return _params.getVariance();
00055   }
00056 
00057   // //////////////////////////////////////////////////////////////////////
00058   void Gaussian::initRandomGenerator () {
00059     // Initialise the Random Generator
00060     gsl_rng_env_setup ();
00061 
00062     // Allocate the memory for the random generator
00063     _rngPtr = gsl_rng_alloc (_rngTypePtr);
00064   }
00065 
00066   // //////////////////////////////////////////////////////////////////////
00067   double Gaussian::generateVariate () const {
00068 
00069     const double mean = getMean();
00070     const double standardDeviation = getStandardDeviation();
00071     
00072     double result = gsl_ran_gaussian (_rngPtr, standardDeviation);
00073     result += mean;
00074     
00075     return result;
00076   }
00077 
00078 }
SourceForge Logo

Generated on Fri Sep 11 06:31:59 2009 for RMOL by Doxygen 1.5.8