1 | /*
|
---|
2 | * RandomNumberDistribution_Encapsulation.hpp
|
---|
3 | *
|
---|
4 | * Created on: Jan 01, 2011
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_
|
---|
9 | #define RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include "CodePatterns/Assert.hpp"
|
---|
17 |
|
---|
18 | #include <typeinfo>
|
---|
19 |
|
---|
20 | #include <boost/nondet_random.hpp>
|
---|
21 | #include <boost/random.hpp>
|
---|
22 | #include <boost/random/bernoulli_distribution.hpp>
|
---|
23 | #include <boost/random/binomial_distribution.hpp>
|
---|
24 | #include <boost/random/cauchy_distribution.hpp>
|
---|
25 | #include <boost/random/exponential_distribution.hpp>
|
---|
26 | #include <boost/random/gamma_distribution.hpp>
|
---|
27 | #include <boost/random/geometric_distribution.hpp>
|
---|
28 | #include <boost/random/linear_congruential.hpp>
|
---|
29 | #include <boost/random/lognormal_distribution.hpp>
|
---|
30 | #include <boost/random/normal_distribution.hpp>
|
---|
31 | #include <boost/random/poisson_distribution.hpp>
|
---|
32 | #include <boost/random/triangle_distribution.hpp>
|
---|
33 | #include <boost/random/uniform_01.hpp>
|
---|
34 | #include <boost/random/uniform_int.hpp>
|
---|
35 | #include <boost/random/uniform_on_sphere.hpp>
|
---|
36 | #include <boost/random/uniform_real.hpp>
|
---|
37 | #include <boost/random/uniform_smallint.hpp>
|
---|
38 |
|
---|
39 | #include "CodePatterns/ManipulableClone.hpp"
|
---|
40 | #include "RandomNumberDistribution.hpp"
|
---|
41 |
|
---|
42 | #include "RandomNumberDistribution_Parameters.hpp"
|
---|
43 |
|
---|
44 | class RandomNumberDistributionFactory;
|
---|
45 |
|
---|
46 | /** Template class that encapsulates the random number distributions from
|
---|
47 | * random::boost.
|
---|
48 | *
|
---|
49 | *
|
---|
50 | * We need one template parameters:
|
---|
51 | * -# the distribution - generates uniform random numbers
|
---|
52 | */
|
---|
53 | template <class distribution>
|
---|
54 | class RandomNumberDistribution_Encapsulation :
|
---|
55 | public RandomNumberDistribution,
|
---|
56 | public ManipulableClone<RandomNumberDistribution, RandomNumberDistribution_Parameters>
|
---|
57 | {
|
---|
58 | /**
|
---|
59 | * Factory is friend such that it can access private cstor when filling its
|
---|
60 | * table
|
---|
61 | */
|
---|
62 | friend class RandomNumberDistributionFactory;
|
---|
63 |
|
---|
64 | public:
|
---|
65 | /** Getter for the whole set of possible parameters.
|
---|
66 | *
|
---|
67 | * @return filled instance of RandomNumberDistribution_Parameters
|
---|
68 | */
|
---|
69 | RandomNumberDistribution_Parameters* getParameterSet() const
|
---|
70 | {
|
---|
71 | RandomNumberDistribution_Parameters *params = new RandomNumberDistribution_Parameters();
|
---|
72 | params->getParameters(this);
|
---|
73 | return params;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /** Getter for smallest value the uniform_... engines produces.
|
---|
77 | *
|
---|
78 | * @return smallest value
|
---|
79 | */
|
---|
80 | double min() const {
|
---|
81 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /** Getter for largest value the uniform_... engines produces.
|
---|
85 | *
|
---|
86 | * @return largest value
|
---|
87 | */
|
---|
88 | double max() const {
|
---|
89 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /** Getter for bernoulli_distribution's probability p.
|
---|
93 | *
|
---|
94 | * @return p
|
---|
95 | */
|
---|
96 | double p() const {
|
---|
97 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /** Getter for binomial_distribution's parameter t.
|
---|
101 | *
|
---|
102 | * @return t
|
---|
103 | */
|
---|
104 | double t() const {
|
---|
105 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
106 | }
|
---|
107 |
|
---|
108 | /** Getter for cauchy_distribution parameter median.
|
---|
109 | *
|
---|
110 | * @return median
|
---|
111 | */
|
---|
112 | double median() const {
|
---|
113 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
114 | }
|
---|
115 |
|
---|
116 | /** Getter for cauchy_distribution parameter sigma.
|
---|
117 | *
|
---|
118 | * @return sigma
|
---|
119 | */
|
---|
120 | double sigma() const {
|
---|
121 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
122 | }
|
---|
123 |
|
---|
124 | /** Getter for gamma_distribution parameter alpha.
|
---|
125 | *
|
---|
126 | * @return alpha
|
---|
127 | */
|
---|
128 | double alpha() const {
|
---|
129 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
130 | }
|
---|
131 |
|
---|
132 | /** Getter for poisson_distribution's parameter mean.
|
---|
133 | *
|
---|
134 | * @return mean
|
---|
135 | */
|
---|
136 | double mean() const {
|
---|
137 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
138 | }
|
---|
139 |
|
---|
140 | /** Getter for triangle_distribution parameter a.
|
---|
141 | *
|
---|
142 | * @return a
|
---|
143 | */
|
---|
144 | double a() const {
|
---|
145 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
146 | }
|
---|
147 |
|
---|
148 | /** Getter for triangle_distribution parameter b.
|
---|
149 | *
|
---|
150 | * @return b
|
---|
151 | */
|
---|
152 | double b() const {
|
---|
153 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
154 | }
|
---|
155 |
|
---|
156 | /** Getter for triangle_distribution parameter c.
|
---|
157 | *
|
---|
158 | * @return c
|
---|
159 | */
|
---|
160 | double c() const {
|
---|
161 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
162 | }
|
---|
163 |
|
---|
164 | /** Getter for exponential_distribution parameter lambda.
|
---|
165 | *
|
---|
166 | * @return lambda
|
---|
167 | */
|
---|
168 | double lambda() const {
|
---|
169 | return RandomNumberDistribution_Parameters::noset_value;
|
---|
170 | }
|
---|
171 |
|
---|
172 | /** Getter for the type name of the internal distribution.
|
---|
173 | *
|
---|
174 | */
|
---|
175 | std::string name() {
|
---|
176 | return typeid(distribution_type).name();
|
---|
177 | }
|
---|
178 |
|
---|
179 | /** Getter for the distribution instance.
|
---|
180 | *
|
---|
181 | * @return reference to instance
|
---|
182 | */
|
---|
183 | distribution& getDistribution() {
|
---|
184 | return distribution_type;
|
---|
185 | }
|
---|
186 |
|
---|
187 | /** Clones the current instance.
|
---|
188 | *
|
---|
189 | * Implementation of Clone pattern.
|
---|
190 | *
|
---|
191 | * @return interface reference to cloned instance
|
---|
192 | */
|
---|
193 | RandomNumberDistribution* clone() const {
|
---|
194 | RandomNumberDistribution* MyClone = NULL;
|
---|
195 | RandomNumberDistribution_Parameters *params = getParameterSet();
|
---|
196 | MyClone = new RandomNumberDistribution_Encapsulation<distribution>(*params);
|
---|
197 | delete params;
|
---|
198 | return MyClone;
|
---|
199 | }
|
---|
200 |
|
---|
201 | /** Clones and manipulates the current instance.
|
---|
202 | *
|
---|
203 | * Implementation of ManipulableClone pattern.
|
---|
204 | *
|
---|
205 | * @param _params set of parameters to instantiate manipulated clone with
|
---|
206 | * @return interface reference to cloned&manipulated instance
|
---|
207 | */
|
---|
208 | ManipulableClone<RandomNumberDistribution, RandomNumberDistribution_Parameters>*
|
---|
209 | manipulatedclone(const RandomNumberDistribution_Parameters&_params) const
|
---|
210 | {
|
---|
211 | RandomNumberDistribution_Encapsulation<distribution>* newproto =
|
---|
212 | new RandomNumberDistribution_Encapsulation<distribution>(_params);
|
---|
213 | return newproto;
|
---|
214 | }
|
---|
215 |
|
---|
216 | protected:
|
---|
217 | /** Constructor that instantiates a specific random number generator and
|
---|
218 | * distribution.
|
---|
219 | * @param _distribution_type instance of the desired distribution
|
---|
220 | */
|
---|
221 | RandomNumberDistribution_Encapsulation()
|
---|
222 | {}
|
---|
223 |
|
---|
224 | /** Constructor that instantiates a specific random number generator and
|
---|
225 | * distribution.
|
---|
226 | *
|
---|
227 | * @param _params set of parameters to instantiate manipulated clone with
|
---|
228 | * @param _distribution_type instance of the desired distribution
|
---|
229 | */
|
---|
230 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params)
|
---|
231 | {}
|
---|
232 |
|
---|
233 | /** Destructor of the class.
|
---|
234 | *
|
---|
235 | */
|
---|
236 | virtual ~RandomNumberDistribution_Encapsulation() {}
|
---|
237 | private:
|
---|
238 | distribution distribution_type;
|
---|
239 | };
|
---|
240 |
|
---|
241 | // the following definitions prevents the compiler from instantiating the above
|
---|
242 | // template member functions for the desired cases.
|
---|
243 |
|
---|
244 | /* ========= manipulatedclone() ================ */
|
---|
245 |
|
---|
246 | template <>
|
---|
247 | RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::
|
---|
248 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
249 |
|
---|
250 | template <>
|
---|
251 | RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::
|
---|
252 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
253 |
|
---|
254 | template <>
|
---|
255 | RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::
|
---|
256 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
257 |
|
---|
258 | template <>
|
---|
259 | RandomNumberDistribution_Encapsulation< boost::bernoulli_distribution<> >::
|
---|
260 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
261 |
|
---|
262 | template <>
|
---|
263 | RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::
|
---|
264 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
265 |
|
---|
266 | template <>
|
---|
267 | RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::
|
---|
268 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
269 |
|
---|
270 | template <>
|
---|
271 | RandomNumberDistribution_Encapsulation< boost::gamma_distribution<> >::
|
---|
272 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
273 |
|
---|
274 | template <>
|
---|
275 | RandomNumberDistribution_Encapsulation< boost::poisson_distribution<> >::
|
---|
276 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
277 |
|
---|
278 | template <>
|
---|
279 | RandomNumberDistribution_Encapsulation< boost::geometric_distribution<> >::
|
---|
280 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
281 |
|
---|
282 | template <>
|
---|
283 | RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::
|
---|
284 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
285 |
|
---|
286 | template <>
|
---|
287 | RandomNumberDistribution_Encapsulation< boost::exponential_distribution<> >::
|
---|
288 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
289 |
|
---|
290 | template <>
|
---|
291 | RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::
|
---|
292 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
293 |
|
---|
294 | template <>
|
---|
295 | RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::
|
---|
296 | RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params);
|
---|
297 |
|
---|
298 | /* =============== min() ======================= */
|
---|
299 |
|
---|
300 | template <>
|
---|
301 | double RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::min() const;
|
---|
302 | template <>
|
---|
303 | double RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::min() const;
|
---|
304 | template <>
|
---|
305 | double RandomNumberDistribution_Encapsulation< boost::uniform_01<> >::min() const;
|
---|
306 | template <>
|
---|
307 | double RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::min() const;
|
---|
308 |
|
---|
309 |
|
---|
310 | /* =============== max() ======================= */
|
---|
311 |
|
---|
312 | template <>
|
---|
313 | double RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::max() const;
|
---|
314 | template <>
|
---|
315 | double RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::max() const;
|
---|
316 | template <>
|
---|
317 | double RandomNumberDistribution_Encapsulation< boost::uniform_01<> >::max() const;
|
---|
318 | template <>
|
---|
319 | double RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::max() const;
|
---|
320 |
|
---|
321 |
|
---|
322 | /* =============== p() ======================= */
|
---|
323 |
|
---|
324 | template <>
|
---|
325 | double RandomNumberDistribution_Encapsulation< boost::bernoulli_distribution<> >::p() const;
|
---|
326 | template <>
|
---|
327 | double RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::p() const;
|
---|
328 | template <>
|
---|
329 | double RandomNumberDistribution_Encapsulation< boost::geometric_distribution<> >::p() const;
|
---|
330 |
|
---|
331 |
|
---|
332 | /* =============== t() ======================= */
|
---|
333 |
|
---|
334 | template <>
|
---|
335 | double RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::t() const;
|
---|
336 |
|
---|
337 |
|
---|
338 | /* =============== median() ======================= */
|
---|
339 |
|
---|
340 | template <>
|
---|
341 | double RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::median() const;
|
---|
342 |
|
---|
343 |
|
---|
344 | /* =============== sigma() ======================= */
|
---|
345 |
|
---|
346 | template <>
|
---|
347 | double RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::sigma() const;
|
---|
348 | template <>
|
---|
349 | double RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::sigma() const;
|
---|
350 | template <>
|
---|
351 | double RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::sigma() const;
|
---|
352 |
|
---|
353 |
|
---|
354 | /* =============== alpha() ======================= */
|
---|
355 |
|
---|
356 | template <>
|
---|
357 | double RandomNumberDistribution_Encapsulation< boost::gamma_distribution<> >::alpha() const;
|
---|
358 |
|
---|
359 |
|
---|
360 | /* =============== mean() ======================= */
|
---|
361 |
|
---|
362 | template <>
|
---|
363 | double RandomNumberDistribution_Encapsulation< boost::poisson_distribution<> >::mean() const;
|
---|
364 | template <>
|
---|
365 | double RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::mean() const;
|
---|
366 | template <>
|
---|
367 | double RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::mean() const;
|
---|
368 |
|
---|
369 |
|
---|
370 | /* =============== a() ======================= */
|
---|
371 |
|
---|
372 | template <>
|
---|
373 | double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::a() const;
|
---|
374 |
|
---|
375 |
|
---|
376 | /* =============== b() ======================= */
|
---|
377 |
|
---|
378 | template <>
|
---|
379 | double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::b() const;
|
---|
380 |
|
---|
381 |
|
---|
382 | /* =============== c() ======================= */
|
---|
383 |
|
---|
384 | template <>
|
---|
385 | double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::c() const;
|
---|
386 |
|
---|
387 |
|
---|
388 | /* =============== lambda() ======================= */
|
---|
389 |
|
---|
390 | template <>
|
---|
391 | double RandomNumberDistribution_Encapsulation< boost::exponential_distribution<> >::lambda() const;
|
---|
392 |
|
---|
393 |
|
---|
394 |
|
---|
395 | #endif /* RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_ */
|
---|