Transit Planner  1.0
An experiment on transfer patterns robustness
src/Random.h
00001 // Copyright 2011: Eugen Sawin, Philip Stahl, Jonas Sternisko
00002 #ifndef SRC_RANDOM_H_
00003 #define SRC_RANDOM_H_
00004 
00005 #include <boost/random/linear_congruential.hpp>
00006 #include <boost/random/mersenne_twister.hpp>
00007 #include <boost/random/uniform_int.hpp>
00008 #include <boost/random/uniform_real.hpp>
00009 #include <boost/random/variate_generator.hpp>
00010 #include <boost/generator_iterator.hpp>
00011 
00012 using boost::minstd_rand;
00013 using boost::uniform_int;
00014 using boost::uniform_real;
00015 
00016 // Generator for random int sequences.
00017 class RandomGen {
00018  public:
00019   typedef boost::variate_generator<minstd_rand&, uniform_int<> >  Generator;
00020 
00021   // Construct a random generator with given min, max and seed.
00022   RandomGen(const int minValue, const int maxValue, const int seed);
00023 
00024   // Construct a random generator with given min, max and arbitrary seed.
00025   RandomGen(const int minValue, const int maxValue);
00026 
00027   // Returns the next "random" number in sequence.
00028   int next();
00029 
00030   // Returns the seed used.
00031   int seed() const;
00032 
00033  private:
00034   int _seed;
00035   minstd_rand _base;
00036   uniform_int<> _dist;
00037   Generator _gen;
00038 };
00039 
00040 
00041 // Generator for random float sequences.
00042 class RandomFloatGen {
00043   typedef boost::variate_generator<minstd_rand&, uniform_real<> >  Generator;
00044  public:
00045   // Construct a random generator for numbers in [min, max) with seed.
00046   RandomFloatGen(const float min, const float max, const int seed);
00047 
00048   // Construct a random generator for numbers in [min, max) with automatic seed.
00049   RandomFloatGen(const float min, const float max);
00050 
00051   // Returns the next "random" number in sequence.
00052   float next();
00053   // Returns the seed used.
00054   int seed() const;
00055 
00056  private:
00057   int _seed;
00058   minstd_rand _base;
00059   uniform_real<> _distribution;
00060   Generator _generator;
00061 };
00062 
00063 
00064 // Generator for random samples from the exponential distribution with mean 1/b.
00065 // p(x) = b * exp(-bx)
00066 class ExpDistribution : public RandomFloatGen {
00067  public:
00068   ExpDistribution(const int seed, const float beta);
00069   float sample();
00070  private:
00071   float _beta;
00072 };
00073 
00074 #endif  // SRC_RANDOM_H_
 All Classes