[3f9eba] | 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 |
|
---|
[081e5d] | 16 | #include "CodePatterns/Assert.hpp"
|
---|
| 17 |
|
---|
[3f9eba] | 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 |
|
---|
[9b3476] | 39 | #include "CodePatterns/Clone.hpp"
|
---|
[c9bc2b7] | 40 | #include "RandomNumberDistribution.hpp"
|
---|
| 41 |
|
---|
[9b3476] | 42 | class RandomNumberDistributionFactory;
|
---|
| 43 |
|
---|
[3f9eba] | 44 | /** Template class that encapsulates the random number distributions from
|
---|
| 45 | * random::boost.
|
---|
| 46 | *
|
---|
| 47 | *
|
---|
| 48 | * We need one template parameters:
|
---|
| 49 | * -# the distribution - generates uniform random numbers
|
---|
| 50 | */
|
---|
| 51 | template <class distribution>
|
---|
[1d5a871] | 52 | class RandomNumberDistribution_Encapsulation :
|
---|
| 53 | public RandomNumberDistribution,
|
---|
[9b3476] | 54 | public Clone<RandomNumberDistribution>
|
---|
[3f9eba] | 55 | {
|
---|
[9b3476] | 56 | /**
|
---|
| 57 | * Factory is friend such that it can access private cstor when filling its
|
---|
| 58 | * table
|
---|
| 59 | */
|
---|
| 60 | friend class RandomNumberDistributionFactory;
|
---|
| 61 |
|
---|
[3f9eba] | 62 | public:
|
---|
| 63 |
|
---|
[081e5d] | 64 | /** Getter for smallest value the engine produces.
|
---|
| 65 | *
|
---|
| 66 | * @return smallest value
|
---|
| 67 | */
|
---|
| 68 | double min() const {
|
---|
| 69 | ASSERT(0, "min() not implemented for "+name());
|
---|
| 70 | return -1.;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | /** Getter for largest value the engine produces.
|
---|
| 74 | *
|
---|
| 75 | * @return largest value
|
---|
| 76 | */
|
---|
| 77 | double max() const {
|
---|
| 78 | ASSERT(0, "max() not implemented for "+name());
|
---|
| 79 | return -1.;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /** Getter for bernoulli_distribution's probability p.
|
---|
| 83 | *
|
---|
| 84 | * @return p
|
---|
| 85 | */
|
---|
| 86 | double p() const {
|
---|
| 87 | ASSERT(0, "p() not implemented for "+name());
|
---|
| 88 | return -1.;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | /** Getter for binomial_distribution's parameter t.
|
---|
| 92 | *
|
---|
| 93 | * @return t
|
---|
| 94 | */
|
---|
| 95 | double t() const {
|
---|
| 96 | ASSERT(0, "t() not implemented for "+name());
|
---|
| 97 | return -1.;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | /** Getter for cauchy_distribution parameter median.
|
---|
| 101 | *
|
---|
| 102 | * @return median
|
---|
| 103 | */
|
---|
| 104 | double median() const {
|
---|
| 105 | ASSERT(0, "median() not implemented for "+name());
|
---|
| 106 | return -1.;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | /** Getter for cauchy_distribution parameter sigma.
|
---|
| 110 | *
|
---|
| 111 | * @return sigma
|
---|
| 112 | */
|
---|
| 113 | double sigma() const {
|
---|
| 114 | ASSERT(0, "sigma() not implemented for "+name());
|
---|
| 115 | return -1.;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | /** Getter for gamma_distribution parameter alpha.
|
---|
| 119 | *
|
---|
| 120 | * @return alpha
|
---|
| 121 | */
|
---|
| 122 | double alpha() const {
|
---|
| 123 | ASSERT(0, "alpha() not implemented for "+name());
|
---|
| 124 | return -1.;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | /** Getter for poisson_distribution's parameter mean.
|
---|
| 128 | *
|
---|
| 129 | * @return mean
|
---|
| 130 | */
|
---|
| 131 | double mean() const {
|
---|
| 132 | ASSERT(0, "mean() not implemented for "+name());
|
---|
| 133 | return -1.;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | /** Getter for triangle_distribution parameter a.
|
---|
| 137 | *
|
---|
| 138 | * @return a
|
---|
| 139 | */
|
---|
| 140 | double a() const {
|
---|
| 141 | ASSERT(0, "a() not implemented for "+name());
|
---|
| 142 | return -1.;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | /** Getter for triangle_distribution parameter b.
|
---|
| 146 | *
|
---|
| 147 | * @return b
|
---|
| 148 | */
|
---|
| 149 | double b() const {
|
---|
| 150 | ASSERT(0, "b() not implemented for "+name());
|
---|
| 151 | return -1.;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | /** Getter for triangle_distribution parameter c.
|
---|
| 155 | *
|
---|
| 156 | * @return c
|
---|
| 157 | */
|
---|
| 158 | double c() const {
|
---|
| 159 | ASSERT(0, "c() not implemented for "+name());
|
---|
| 160 | return -1.;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | /** Getter for exponential_distribution parameter lambda.
|
---|
| 164 | *
|
---|
| 165 | * @return lambda
|
---|
| 166 | */
|
---|
| 167 | double lambda() const {
|
---|
| 168 | ASSERT(0, "lambda() not implemented for "+name());
|
---|
| 169 | return -1.;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[3f9eba] | 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 |
|
---|
[9b3476] | 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 | MyClone = new RandomNumberDistribution_Encapsulation<distribution>();
|
---|
| 196 | return MyClone;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | protected:
|
---|
[3f9eba] | 200 | /** Constructor that instantiates a specific random number generator and
|
---|
| 201 | * distribution.
|
---|
| 202 | * @param _distribution_type instance of the desired distribution
|
---|
| 203 | */
|
---|
| 204 | RandomNumberDistribution_Encapsulation()
|
---|
| 205 | {}
|
---|
| 206 |
|
---|
| 207 | /** Destructor of the class.
|
---|
| 208 | *
|
---|
| 209 | */
|
---|
[c9bc2b7] | 210 | virtual ~RandomNumberDistribution_Encapsulation() {}
|
---|
[3f9eba] | 211 | private:
|
---|
| 212 | distribution distribution_type;
|
---|
| 213 | };
|
---|
| 214 |
|
---|
[081e5d] | 215 | // the following definitions prevents the compiler from instantiating the above
|
---|
| 216 | // template member functions for the desired cases.
|
---|
| 217 |
|
---|
| 218 | /* =============== min() ======================= */
|
---|
| 219 |
|
---|
| 220 | template <>
|
---|
| 221 | double RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::min() const;
|
---|
| 222 | template <>
|
---|
| 223 | double RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::min() const;
|
---|
| 224 | template <>
|
---|
| 225 | double RandomNumberDistribution_Encapsulation< boost::uniform_01<> >::min() const;
|
---|
| 226 | template <>
|
---|
| 227 | double RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::min() const;
|
---|
| 228 |
|
---|
| 229 |
|
---|
| 230 | /* =============== max() ======================= */
|
---|
| 231 |
|
---|
| 232 | template <>
|
---|
| 233 | double RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::max() const;
|
---|
| 234 | template <>
|
---|
| 235 | double RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::max() const;
|
---|
| 236 | template <>
|
---|
| 237 | double RandomNumberDistribution_Encapsulation< boost::uniform_01<> >::max() const;
|
---|
| 238 | template <>
|
---|
| 239 | double RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::max() const;
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | /* =============== p() ======================= */
|
---|
| 243 |
|
---|
| 244 | template <>
|
---|
| 245 | double RandomNumberDistribution_Encapsulation< boost::bernoulli_distribution<> >::p() const;
|
---|
| 246 | template <>
|
---|
| 247 | double RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::p() const;
|
---|
| 248 | template <>
|
---|
| 249 | double RandomNumberDistribution_Encapsulation< boost::geometric_distribution<> >::p() const;
|
---|
| 250 |
|
---|
| 251 |
|
---|
| 252 | /* =============== t() ======================= */
|
---|
| 253 |
|
---|
| 254 | template <>
|
---|
| 255 | double RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::t() const;
|
---|
| 256 |
|
---|
| 257 |
|
---|
| 258 | /* =============== median() ======================= */
|
---|
| 259 |
|
---|
| 260 | template <>
|
---|
| 261 | double RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::median() const;
|
---|
| 262 |
|
---|
| 263 |
|
---|
| 264 | /* =============== sigma() ======================= */
|
---|
| 265 |
|
---|
| 266 | template <>
|
---|
| 267 | double RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::sigma() const;
|
---|
| 268 | template <>
|
---|
| 269 | double RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::sigma() const;
|
---|
| 270 | template <>
|
---|
| 271 | double RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::sigma() const;
|
---|
| 272 |
|
---|
| 273 |
|
---|
| 274 | /* =============== alpha() ======================= */
|
---|
| 275 |
|
---|
| 276 | template <>
|
---|
| 277 | double RandomNumberDistribution_Encapsulation< boost::gamma_distribution<> >::alpha() const;
|
---|
| 278 |
|
---|
| 279 |
|
---|
| 280 | /* =============== mean() ======================= */
|
---|
| 281 |
|
---|
| 282 | template <>
|
---|
| 283 | double RandomNumberDistribution_Encapsulation< boost::poisson_distribution<> >::mean() const;
|
---|
| 284 | template <>
|
---|
| 285 | double RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::mean() const;
|
---|
| 286 | template <>
|
---|
| 287 | double RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::mean() const;
|
---|
| 288 |
|
---|
| 289 |
|
---|
| 290 | /* =============== a() ======================= */
|
---|
| 291 |
|
---|
| 292 | template <>
|
---|
| 293 | double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::a() const;
|
---|
| 294 |
|
---|
| 295 |
|
---|
| 296 | /* =============== b() ======================= */
|
---|
| 297 |
|
---|
| 298 | template <>
|
---|
| 299 | double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::b() const;
|
---|
| 300 |
|
---|
| 301 |
|
---|
| 302 | /* =============== c() ======================= */
|
---|
| 303 |
|
---|
| 304 | template <>
|
---|
| 305 | double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::c() const;
|
---|
| 306 |
|
---|
| 307 |
|
---|
| 308 | /* =============== lambda() ======================= */
|
---|
| 309 |
|
---|
| 310 | template <>
|
---|
| 311 | double RandomNumberDistribution_Encapsulation< boost::exponential_distribution<> >::lambda() const;
|
---|
| 312 |
|
---|
| 313 |
|
---|
| 314 |
|
---|
[3f9eba] | 315 | #endif /* RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_ */
|
---|