RandomEngine.h

Go to the documentation of this file.
00001 #ifndef RANDOMENGINE_H_
00002 #define RANDOMENGINE_H_
00003 
00011 #ifdef _MSC_VER
00012 # pragma warning(disable:4244) // warning C4244: 'initializing' : conversion from 'boost::uint64_t' to 'boost::uint32_t', possible loss of data
00013 #endif
00014 
00015 #include <boost/date_time/posix_time/posix_time.hpp>
00016 using namespace boost::posix_time;
00017 
00018 #include <boost/random.hpp>
00019 
00020 #ifdef _MSC_VER
00021 # undef min
00022 # undef max
00023 #endif
00024 
00026 
00027 class RandomEngine
00028 {
00029 
00030 public:
00032     typedef double result_type;
00033 
00035     virtual ~RandomEngine() {};
00036 
00038     virtual double operator()() = 0;
00039 
00041     virtual void seed( unsigned s ) = 0;
00042 
00044     void seed( )
00045     {
00046         return seed( unsigned(microsec_clock::local_time().time_of_day().total_microseconds()) );
00047     };
00048 
00050     double min() { return 0; };
00051 
00053     double max() { return 1; };
00054 };
00055 
00056 #include <iostream>
00057 using std::cerr;
00058 using std::endl;
00059 
00061 template< typename boost_engine >
00062 class RandomEngineBoostImplementation : public RandomEngine
00063 {
00064 public:
00065 
00066     RandomEngineBoostImplementation() :  m_rng( boost_engine() )
00067     {
00068         m_rng.base().seed( unsigned(microsec_clock::local_time().time_of_day().total_microseconds()) );
00069     };
00070 
00071     virtual ~RandomEngineBoostImplementation() {};
00072 
00073     virtual double operator()()
00074     {
00075         return m_rng();
00076     };
00077 
00078     virtual void seed( unsigned s )
00079     {
00080         m_rng.base().seed( s );
00081     };
00082 
00083 
00084 private:
00086     boost::uniform_01< boost_engine, double > m_rng;
00087 };
00088 
00089 // Here are several random number generator instantions
00090 class MersenneTwister19937 : public RandomEngineBoostImplementation< boost::mt19937 > {};
00091 class MersenneTwister11213b : public RandomEngineBoostImplementation< boost::mt11213b > {};
00092 class LaggedFibonacci607 : public RandomEngineBoostImplementation< boost::lagged_fibonacci607 > {};
00093 class LaggedFibonacci1279 : public RandomEngineBoostImplementation< boost::lagged_fibonacci1279 > {};
00094 class LaggedFibonacci2281 : public RandomEngineBoostImplementation< boost::lagged_fibonacci2281 > {};
00095 class LaggedFibonacci3217 : public RandomEngineBoostImplementation< boost::lagged_fibonacci3217 > {};
00096 class LaggedFibonacci4423 : public RandomEngineBoostImplementation< boost::lagged_fibonacci4423 > {};
00097 class LaggedFibonacci9689 : public RandomEngineBoostImplementation< boost::lagged_fibonacci9689 > {};
00098 class LaggedFibonacci19937 : public RandomEngineBoostImplementation< boost::lagged_fibonacci19937 > {};
00099 class LaggedFibonacci23209 : public RandomEngineBoostImplementation< boost::lagged_fibonacci23209 > {};
00100 class LaggedFibonacci44497 : public RandomEngineBoostImplementation< boost::lagged_fibonacci44497 > {};
00101 
00102 #ifdef _MSC_VER
00103 # pragma warning(default:4244) // warning C4244: 'initializing' : conversion from 'boost::uint64_t' to 'boost::uint32_t', possible loss of data
00104 #endif
00105 
00106 
00107 #endif /*RANDOMENGINE_H_*/

Generated on Wed Jul 9 16:34:39 2008 for PCSIM by  doxygen 1.5.5