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 |
|
---|
33 | #include "CodePatterns/ManipulableClone.hpp"
|
---|
34 | #include "RandomNumberEngine.hpp"
|
---|
35 |
|
---|
36 | class RandomNumberEngineFactory;
|
---|
37 |
|
---|
38 | #include "RandomNumberEngine_Parameters.hpp"
|
---|
39 |
|
---|
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>
|
---|
48 | class RandomNumberEngine_Encapsulation :
|
---|
49 | public RandomNumberEngine,
|
---|
50 | public ManipulableClone<RandomNumberEngine, RandomNumberEngine_Parameters>
|
---|
51 | {
|
---|
52 | /**
|
---|
53 | * Factory is friend such that it can access private cstor when filling its
|
---|
54 | * table
|
---|
55 | */
|
---|
56 | friend class RandomNumberEngineFactory;
|
---|
57 |
|
---|
58 | public:
|
---|
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 |
|
---|
70 | /** Set the engine's seed.
|
---|
71 | *
|
---|
72 | * @param _seed seed to set to
|
---|
73 | */
|
---|
74 | void seed(unsigned int _seed) {
|
---|
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;
|
---|
85 | }
|
---|
86 |
|
---|
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 |
|
---|
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 |
|
---|
118 | /** Clones the current instance.
|
---|
119 | *
|
---|
120 | * Implementation of Clone pattern.
|
---|
121 | *
|
---|
122 | * @return interface reference to cloned instance
|
---|
123 | */
|
---|
124 | RandomNumberEngine* clone() const {
|
---|
125 | RandomNumberEngine_Parameters *params = getParameterSet();
|
---|
126 | RandomNumberEngine* MyClone = new RandomNumberEngine_Encapsulation<engine>(*params);
|
---|
127 | //MyClone->seed(getseed());
|
---|
128 | return MyClone;
|
---|
129 | }
|
---|
130 |
|
---|
131 | /** Clones and manipulates the current instance.
|
---|
132 | *
|
---|
133 | * Implementation of ManipulableClone pattern.
|
---|
134 | *
|
---|
135 | * @param _params set of parameters to instantiate manipulated clone with
|
---|
136 | * @return interface reference to cloned&manipulated instance
|
---|
137 | */
|
---|
138 | ManipulableClone<RandomNumberEngine, RandomNumberEngine_Parameters>*
|
---|
139 | manipulatedclone(const RandomNumberEngine_Parameters &_params) const {
|
---|
140 | RandomNumberEngine_Encapsulation<engine>* MyClone = NULL;
|
---|
141 | MyClone = new RandomNumberEngine_Encapsulation<engine>();
|
---|
142 | MyClone->value_seed = _params.seed;
|
---|
143 | MyClone->seed(_params.seed);
|
---|
144 | return MyClone;
|
---|
145 | }
|
---|
146 |
|
---|
147 | protected:
|
---|
148 | /** Constructor that instantiates a specific random number generator and
|
---|
149 | * distribution.
|
---|
150 | * @param _engine_type instance of the desired engine
|
---|
151 | */
|
---|
152 | RandomNumberEngine_Encapsulation() :
|
---|
153 | value_seed(1)
|
---|
154 | {}
|
---|
155 |
|
---|
156 | /** Constructor that instantiates a specific random number generator and
|
---|
157 | * distribution.
|
---|
158 | * @param _engine_type instance of the desired engine
|
---|
159 | */
|
---|
160 | RandomNumberEngine_Encapsulation(const RandomNumberEngine_Parameters &_params) :
|
---|
161 | value_seed(_params.seed)
|
---|
162 | {}
|
---|
163 |
|
---|
164 | /** Destructor of the class.
|
---|
165 | *
|
---|
166 | */
|
---|
167 | virtual ~RandomNumberEngine_Encapsulation() {}
|
---|
168 | private:
|
---|
169 | engine engine_type;
|
---|
170 | unsigned int value_seed;
|
---|
171 | };
|
---|
172 |
|
---|
173 | #endif /* RANDOMNUMBERENGINE_ENCAPSULATION_HPP_ */
|
---|