| [3f9eba] | 1 | /*
 | 
|---|
 | 2 |  * RandomNumberEngine_Encapsulation.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Jan 01, 2011
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef RANDOMNUMBERENGINE_ENCAPSULATION_HPP_
 | 
|---|
 | 9 | #define RANDOMNUMBERENGINE_ENCAPSULATION_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | #include <typeinfo>
 | 
|---|
 | 17 | 
 | 
|---|
 | 18 | #include <boost/nondet_random.hpp>
 | 
|---|
 | 19 | #include <boost/random.hpp>
 | 
|---|
 | 20 | #include <boost/random/additive_combine.hpp>
 | 
|---|
 | 21 | #include <boost/random/discard_block.hpp>
 | 
|---|
 | 22 | #include <boost/random/inversive_congruential.hpp>
 | 
|---|
 | 23 | #include <boost/random/lagged_fibonacci.hpp>
 | 
|---|
 | 24 | #include <boost/random/linear_congruential.hpp>
 | 
|---|
 | 25 | #include <boost/random/linear_feedback_shift.hpp>
 | 
|---|
 | 26 | #include <boost/random/mersenne_twister.hpp>
 | 
|---|
 | 27 | #include <boost/random/random_number_generator.hpp>
 | 
|---|
 | 28 | #include <boost/random/ranlux.hpp>
 | 
|---|
 | 29 | #include <boost/random/shuffle_output.hpp>
 | 
|---|
 | 30 | #include <boost/random/subtract_with_carry.hpp>
 | 
|---|
 | 31 | #include <boost/random/xor_combine.hpp>
 | 
|---|
 | 32 | 
 | 
|---|
| [0275ad] | 33 | #include "CodePatterns/ManipulableClone.hpp"
 | 
|---|
| [c9bc2b7] | 34 | #include "RandomNumberEngine.hpp"
 | 
|---|
 | 35 | 
 | 
|---|
| [9b3476] | 36 | class RandomNumberEngineFactory;
 | 
|---|
 | 37 | 
 | 
|---|
| [0275ad] | 38 | #include "RandomNumberEngine_Parameters.hpp"
 | 
|---|
 | 39 | 
 | 
|---|
| [3f9eba] | 40 | /** Template class that encapsulates the random number engines from
 | 
|---|
 | 41 |  *  random::boost.
 | 
|---|
 | 42 |  *
 | 
|---|
 | 43 |  *
 | 
|---|
 | 44 |  * We need one template parameters:
 | 
|---|
 | 45 |  * -# the engine - generates uniform random numbers
 | 
|---|
 | 46 |  */
 | 
|---|
 | 47 | template <class engine>
 | 
|---|
| [1d5a871] | 48 | class RandomNumberEngine_Encapsulation :
 | 
|---|
 | 49 |   public RandomNumberEngine,
 | 
|---|
| [0275ad] | 50 |   public ManipulableClone<RandomNumberEngine, RandomNumberEngine_Parameters>
 | 
|---|
| [3f9eba] | 51 | {
 | 
|---|
| [9b3476] | 52 |     /**
 | 
|---|
 | 53 |      * Factory is friend such that it can access private cstor when filling its
 | 
|---|
 | 54 |      * table
 | 
|---|
 | 55 |      */
 | 
|---|
 | 56 |     friend class RandomNumberEngineFactory;
 | 
|---|
 | 57 | 
 | 
|---|
| [3f9eba] | 58 | public:
 | 
|---|
| [0275ad] | 59 |   /** Getter for the whole set of possible parameters.
 | 
|---|
 | 60 |    *
 | 
|---|
 | 61 |    * @return filled instance of RandomNumberEngine_Parameters
 | 
|---|
 | 62 |    */
 | 
|---|
 | 63 |     RandomNumberEngine_Parameters* getParameterSet() const
 | 
|---|
 | 64 |   {
 | 
|---|
 | 65 |     RandomNumberEngine_Parameters *params = new RandomNumberEngine_Parameters();
 | 
|---|
 | 66 |     params->getParameters(this);
 | 
|---|
 | 67 |     return params;
 | 
|---|
 | 68 |   }
 | 
|---|
 | 69 | 
 | 
|---|
| [3f9eba] | 70 |   /** Set the engine's seed.
 | 
|---|
 | 71 |    *
 | 
|---|
 | 72 |    * @param _seed seed to set to
 | 
|---|
 | 73 |    */
 | 
|---|
 | 74 |   void seed(unsigned int _seed) {
 | 
|---|
| [9b3476] | 75 |     value_seed = _seed;
 | 
|---|
 | 76 |     engine_type.seed(value_seed);
 | 
|---|
 | 77 |   }
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 |   /** Getter for the engine's seed.
 | 
|---|
 | 80 |    *
 | 
|---|
 | 81 |    * @return seed
 | 
|---|
 | 82 |    */
 | 
|---|
 | 83 |   unsigned int getseed() const {
 | 
|---|
 | 84 |     return value_seed;
 | 
|---|
| [3f9eba] | 85 |   }
 | 
|---|
 | 86 | 
 | 
|---|
| [081e5d] | 87 |   /** Getter for smallest value the engine produces.
 | 
|---|
 | 88 |    *
 | 
|---|
 | 89 |    * @return smallest value
 | 
|---|
 | 90 |    */
 | 
|---|
 | 91 |   double min() const {
 | 
|---|
 | 92 |     return engine_type.min();
 | 
|---|
 | 93 |   }
 | 
|---|
 | 94 | 
 | 
|---|
 | 95 |   /** Getter for largest value the engine produces.
 | 
|---|
 | 96 |    *
 | 
|---|
 | 97 |    * @return largest value
 | 
|---|
 | 98 |    */
 | 
|---|
 | 99 |   double max() const {
 | 
|---|
 | 100 |     return engine_type.max();
 | 
|---|
 | 101 |   }
 | 
|---|
 | 102 | 
 | 
|---|
| [3f9eba] | 103 |   /** Getter for the type name of the internal engine.
 | 
|---|
 | 104 |    *
 | 
|---|
 | 105 |    */
 | 
|---|
 | 106 |   std::string name() {
 | 
|---|
 | 107 |     return typeid(engine_type).name();
 | 
|---|
 | 108 |   }
 | 
|---|
 | 109 | 
 | 
|---|
 | 110 |   /** Getter for the engine instance.
 | 
|---|
 | 111 |    *
 | 
|---|
 | 112 |    * @return reference to instance
 | 
|---|
 | 113 |    */
 | 
|---|
 | 114 |   engine& getEngine() {
 | 
|---|
 | 115 |     return engine_type;
 | 
|---|
 | 116 |   }
 | 
|---|
 | 117 | 
 | 
|---|
| [9b3476] | 118 |   /** Clones the current instance.
 | 
|---|
 | 119 |    *
 | 
|---|
 | 120 |    * Implementation of Clone pattern.
 | 
|---|
 | 121 |    *
 | 
|---|
 | 122 |    * @return interface reference to cloned instance
 | 
|---|
 | 123 |    */
 | 
|---|
 | 124 |   RandomNumberEngine* clone() const {
 | 
|---|
| [0275ad] | 125 |     RandomNumberEngine_Parameters *params = getParameterSet();
 | 
|---|
 | 126 |     RandomNumberEngine* MyClone = new RandomNumberEngine_Encapsulation<engine>(*params);
 | 
|---|
| [7d46e3] | 127 |     delete params;
 | 
|---|
| [0932c2] | 128 |     MyClone->seed(getseed());
 | 
|---|
| [0275ad] | 129 |     return MyClone;
 | 
|---|
 | 130 |   }
 | 
|---|
 | 131 | 
 | 
|---|
 | 132 |   /** Clones and manipulates the current instance.
 | 
|---|
 | 133 |    *
 | 
|---|
 | 134 |    * Implementation of ManipulableClone pattern.
 | 
|---|
 | 135 |    *
 | 
|---|
 | 136 |    * @param _params set of parameters to instantiate manipulated clone with
 | 
|---|
 | 137 |    * @return interface reference to cloned&manipulated instance
 | 
|---|
 | 138 |    */
 | 
|---|
 | 139 |   ManipulableClone<RandomNumberEngine, RandomNumberEngine_Parameters>*
 | 
|---|
 | 140 |   manipulatedclone(const RandomNumberEngine_Parameters &_params) const {
 | 
|---|
 | 141 |     RandomNumberEngine_Encapsulation<engine>* MyClone = NULL;
 | 
|---|
| [9b3476] | 142 |     MyClone = new RandomNumberEngine_Encapsulation<engine>();
 | 
|---|
| [0275ad] | 143 |     MyClone->value_seed = _params.seed;
 | 
|---|
 | 144 |     MyClone->seed(_params.seed);
 | 
|---|
| [9b3476] | 145 |     return MyClone;
 | 
|---|
 | 146 |   }
 | 
|---|
 | 147 | 
 | 
|---|
 | 148 | protected:
 | 
|---|
| [3f9eba] | 149 |   /** Constructor that instantiates a specific random number generator and
 | 
|---|
 | 150 |    * distribution.
 | 
|---|
 | 151 |    * @param _engine_type instance of the desired engine
 | 
|---|
 | 152 |    */
 | 
|---|
| [9b3476] | 153 |   RandomNumberEngine_Encapsulation() :
 | 
|---|
 | 154 |     value_seed(1)
 | 
|---|
| [3f9eba] | 155 |   {}
 | 
|---|
 | 156 | 
 | 
|---|
| [0275ad] | 157 |   /** Constructor that instantiates a specific random number generator and
 | 
|---|
 | 158 |    * distribution.
 | 
|---|
 | 159 |    * @param _engine_type instance of the desired engine
 | 
|---|
 | 160 |    */
 | 
|---|
 | 161 |   RandomNumberEngine_Encapsulation(const RandomNumberEngine_Parameters &_params) :
 | 
|---|
 | 162 |     value_seed(_params.seed)
 | 
|---|
 | 163 |   {}
 | 
|---|
 | 164 | 
 | 
|---|
| [3f9eba] | 165 |   /** Destructor of the class.
 | 
|---|
 | 166 |    *
 | 
|---|
 | 167 |    */
 | 
|---|
| [c9bc2b7] | 168 |   virtual ~RandomNumberEngine_Encapsulation() {}
 | 
|---|
| [3f9eba] | 169 | private:
 | 
|---|
 | 170 |   engine engine_type;
 | 
|---|
| [9b3476] | 171 |   unsigned int value_seed;
 | 
|---|
| [3f9eba] | 172 | };
 | 
|---|
 | 173 | 
 | 
|---|
 | 174 | #endif /* RANDOMNUMBERENGINE_ENCAPSULATION_HPP_ */
 | 
|---|