/* * RandomNumberDistribution_Encapsulation.hpp * * Created on: Jan 01, 2011 * Author: heber */ #ifndef RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_ #define RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/Assert.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "CodePatterns/ManipulableClone.hpp" #include "RandomNumberDistribution.hpp" #include "RandomNumberDistribution_Parameters.hpp" class RandomNumberDistributionFactory; /** Template class that encapsulates the random number distributions from * random::boost. * * * We need one template parameters: * -# the distribution - generates uniform random numbers */ template class RandomNumberDistribution_Encapsulation : public RandomNumberDistribution, public ManipulableClone { /** * Factory is friend such that it can access private cstor when filling its * table */ friend class RandomNumberDistributionFactory; public: /** Getter for the whole set of possible parameters. * * @return filled instance of RandomNumberDistribution_Parameters */ RandomNumberDistribution_Parameters* getParameterSet() const { RandomNumberDistribution_Parameters *params = new RandomNumberDistribution_Parameters(); params->getParameters(this); return params; } /** Getter for smallest value the uniform_... engines produces. * * @return smallest value */ double min() const { return RandomNumberDistribution_Parameters::noset_value; } /** Getter for largest value the uniform_... engines produces. * * @return largest value */ double max() const { return RandomNumberDistribution_Parameters::noset_value; } /** Getter for bernoulli_distribution's probability p. * * @return p */ double p() const { return RandomNumberDistribution_Parameters::noset_value; } /** Getter for binomial_distribution's parameter t. * * @return t */ double t() const { return RandomNumberDistribution_Parameters::noset_value; } /** Getter for cauchy_distribution parameter median. * * @return median */ double median() const { return RandomNumberDistribution_Parameters::noset_value; } /** Getter for cauchy_distribution parameter sigma. * * @return sigma */ double sigma() const { return RandomNumberDistribution_Parameters::noset_value; } /** Getter for gamma_distribution parameter alpha. * * @return alpha */ double alpha() const { return RandomNumberDistribution_Parameters::noset_value; } /** Getter for poisson_distribution's parameter mean. * * @return mean */ double mean() const { return RandomNumberDistribution_Parameters::noset_value; } /** Getter for triangle_distribution parameter a. * * @return a */ double a() const { return RandomNumberDistribution_Parameters::noset_value; } /** Getter for triangle_distribution parameter b. * * @return b */ double b() const { return RandomNumberDistribution_Parameters::noset_value; } /** Getter for triangle_distribution parameter c. * * @return c */ double c() const { return RandomNumberDistribution_Parameters::noset_value; } /** Getter for exponential_distribution parameter lambda. * * @return lambda */ double lambda() const { return RandomNumberDistribution_Parameters::noset_value; } /** Getter for the type name of the internal distribution. * */ std::string name() { return typeid(distribution_type).name(); } /** Getter for the distribution instance. * * @return reference to instance */ distribution& getDistribution() { return distribution_type; } /** Clones the current instance. * * Implementation of Clone pattern. * * @return interface reference to cloned instance */ RandomNumberDistribution* clone() const { RandomNumberDistribution* MyClone = NULL; RandomNumberDistribution_Parameters *params = getParameterSet(); MyClone = new RandomNumberDistribution_Encapsulation(*params); delete params; return MyClone; } /** Clones and manipulates the current instance. * * Implementation of ManipulableClone pattern. * * @param _params set of parameters to instantiate manipulated clone with * @return interface reference to cloned&manipulated instance */ ManipulableClone* manipulatedclone(const RandomNumberDistribution_Parameters&_params) const { RandomNumberDistribution_Encapsulation* newproto = new RandomNumberDistribution_Encapsulation(_params); return newproto; } protected: /** Constructor that instantiates a specific random number generator and * distribution. * @param _distribution_type instance of the desired distribution */ RandomNumberDistribution_Encapsulation() {} /** Constructor that instantiates a specific random number generator and * distribution. * * @param _params set of parameters to instantiate manipulated clone with * @param _distribution_type instance of the desired distribution */ RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params) {} /** Destructor of the class. * */ virtual ~RandomNumberDistribution_Encapsulation() {} private: distribution distribution_type; }; // the following definitions prevents the compiler from instantiating the above // template member functions for the desired cases. /* ========= manipulatedclone() ================ */ template <> RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); template <> RandomNumberDistribution_Encapsulation< boost::uniform_int<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); template <> RandomNumberDistribution_Encapsulation< boost::uniform_real<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); template <> RandomNumberDistribution_Encapsulation< boost::bernoulli_distribution<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); template <> RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); template <> RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); template <> RandomNumberDistribution_Encapsulation< boost::gamma_distribution<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); template <> RandomNumberDistribution_Encapsulation< boost::poisson_distribution<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); template <> RandomNumberDistribution_Encapsulation< boost::geometric_distribution<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); template <> RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); template <> RandomNumberDistribution_Encapsulation< boost::exponential_distribution<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); template <> RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); template <> RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >:: RandomNumberDistribution_Encapsulation(const RandomNumberDistribution_Parameters&_params); /* =============== min() ======================= */ template <> double RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::min() const; template <> double RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::min() const; template <> double RandomNumberDistribution_Encapsulation< boost::uniform_01<> >::min() const; template <> double RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::min() const; /* =============== max() ======================= */ template <> double RandomNumberDistribution_Encapsulation< boost::uniform_smallint<> >::max() const; template <> double RandomNumberDistribution_Encapsulation< boost::uniform_int<> >::max() const; template <> double RandomNumberDistribution_Encapsulation< boost::uniform_01<> >::max() const; template <> double RandomNumberDistribution_Encapsulation< boost::uniform_real<> >::max() const; /* =============== p() ======================= */ template <> double RandomNumberDistribution_Encapsulation< boost::bernoulli_distribution<> >::p() const; template <> double RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::p() const; template <> double RandomNumberDistribution_Encapsulation< boost::geometric_distribution<> >::p() const; /* =============== t() ======================= */ template <> double RandomNumberDistribution_Encapsulation< boost::binomial_distribution<> >::t() const; /* =============== median() ======================= */ template <> double RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::median() const; /* =============== sigma() ======================= */ template <> double RandomNumberDistribution_Encapsulation< boost::cauchy_distribution<> >::sigma() const; template <> double RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::sigma() const; template <> double RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::sigma() const; /* =============== alpha() ======================= */ template <> double RandomNumberDistribution_Encapsulation< boost::gamma_distribution<> >::alpha() const; /* =============== mean() ======================= */ template <> double RandomNumberDistribution_Encapsulation< boost::poisson_distribution<> >::mean() const; template <> double RandomNumberDistribution_Encapsulation< boost::normal_distribution<> >::mean() const; template <> double RandomNumberDistribution_Encapsulation< boost::lognormal_distribution<> >::mean() const; /* =============== a() ======================= */ template <> double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::a() const; /* =============== b() ======================= */ template <> double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::b() const; /* =============== c() ======================= */ template <> double RandomNumberDistribution_Encapsulation< boost::triangle_distribution<> >::c() const; /* =============== lambda() ======================= */ template <> double RandomNumberDistribution_Encapsulation< boost::exponential_distribution<> >::lambda() const; #endif /* RANDOMNUMBERDISTRIBUTION_ENCAPSULATION_HPP_ */