1#ifndef CYCLUS_SRC_RNG_H
2#define CYCLUS_SRC_RNG_H
4#include <boost/random.hpp>
17typedef boost::random::variate_generator<Generator&, boost::random::normal_distribution<> >
NormalDist;
21 friend class ::SimInitTest;
22 friend class ::RandomTest;
68 boost::random::normal_distribution<> dist(mean, std_dev);
88 double high=std::numeric_limits<double>::max());
93 int high=std::numeric_limits<int>::max());
99 typedef boost::shared_ptr<DoubleDistribution>
Ptr;
109 typedef boost::shared_ptr<FixedDoubleDist>
Ptr;
112 virtual double sample() {
return value; };
113 virtual double max() {
return value; };
118 boost::random::uniform_real_distribution<> dist;
120 typedef boost::shared_ptr<UniformDoubleDist>
Ptr;
123 virtual double sample() {
return dist(RandomNumberGenerator::gen_); }
124 virtual double max() {
return dist.max(); }
129 boost::random::normal_distribution<> dist;
133 typedef boost::shared_ptr<NormalDoubleDist>
Ptr;
137 throw ValueError(
"Min and max cannot be equal for a normal distribution. Either use FixedDoubleDist or change the min/max.");
139 if (max_ < (mean - 3*std_dev) || min_ > (mean + 3*std_dev)) {
140 Warn<VALUE_WARNING>(
"Dist is sampling from a tail of a truncated normal more than 3 standard deviations from the mean. Drawing sampling may be inefficient");
144 virtual double max() {
return max_; }
150 boost::random::poisson_distribution<> dist;
153 typedef boost::shared_ptr<PoissonDoubleDist>
Ptr;
160 virtual double sample() {
return dist(RandomNumberGenerator::gen_); }
161 virtual double mean() {
return dist.mean(); }
167 boost::random::exponential_distribution<> dist;
170 typedef boost::shared_ptr<ExponentialDoubleDist>
Ptr;
177 virtual double sample() {
return dist(RandomNumberGenerator::gen_); }
178 virtual double lambda() {
return lambda_; }
185 boost::random::binomial_distribution<int> dist;
187 double choice_a_, choice_b_;
191 dist(1, p_success),choice_a_(choice_a), choice_b_(choice_b) {
193 throw ValueError(
"Probability of choice A must be positive");
197 return dist(RandomNumberGenerator::gen_) ? choice_a_ : choice_b_; }
198 virtual double p() {
return p_success_; }
203 typedef boost::shared_ptr<IntDistribution>
Ptr;
211 typedef boost::shared_ptr<FixedIntDist>
Ptr;
219 boost::random::uniform_int_distribution<> dist;
221 typedef boost::shared_ptr<UniformIntDist>
Ptr;
224 virtual int sample() {
return dist(RandomNumberGenerator::gen_); }
225 virtual int max() {
return dist.max(); }
230 boost::random::normal_distribution<> dist;
234 typedef boost::shared_ptr<NormalIntDist>
Ptr;
236 NormalIntDist(
double mean,
double std_dev,
int min=0,
int max=1) : dist(mean, std_dev), min_(min), max_(
max) {
238 throw ValueError(
"Min and max cannot be equal for a normal distribution. Either use FixedIntDist or change the min/max.");
240 if (max_ < (mean - 3*std_dev) || min_ > (mean + 3*std_dev)) {
241 Warn<VALUE_WARNING>(
"Dist is sampling from a tail of a truncated normal more than 3 standard deviations from the mean. Drawing sampling may be inefficient");
245 virtual int max() {
return max_; }
253 boost::random::binomial_distribution<int> dist;
257 typedef boost::shared_ptr<BinomialIntDist>
Ptr;
261 throw ValueError(
"Max must be positive and greater than zero");
263 if (p_success_ > 1 || p_success_ < 0) {
264 throw ValueError(
"Probability must be between zero and one");
267 virtual int sample() {
return dist(RandomNumberGenerator::gen_); }
269 virtual int p() {
return p_success_; }
278 boost::random::negative_binomial_distribution<> dist;
282 typedef boost::shared_ptr<NegativeBinomialIntDist>
Ptr;
286 throw ValueError(
"Successes must be positive and greater than zero");
288 if (p_success > 1 || p_success < 0) {
289 throw ValueError(
"Probability must be between zero and one");
292 virtual int sample() {
return dist(RandomNumberGenerator::gen_); }
294 virtual int p() {
return p_success_; }
300 boost::random::poisson_distribution<> dist;
303 typedef boost::shared_ptr<PoissonIntDist>
Ptr;
310 virtual int sample() {
return dist(RandomNumberGenerator::gen_); }
311 virtual double mean() {
return dist.mean(); }
317 boost::random::exponential_distribution<> dist;
320 typedef boost::shared_ptr<ExponentialIntDist>
Ptr;
327 virtual int sample() {
return dist(RandomNumberGenerator::gen_); }
328 virtual double lambda() {
return lambda_; }
334 boost::random::binomial_distribution<int> dist;
336 int choice_a_, choice_b_;
340 dist(1, p_success),choice_a_(choice_a), choice_b_(choice_b) {
342 throw ValueError(
"Probability of choice A must be positive");
346 return dist(RandomNumberGenerator::gen_) ? choice_a_ : choice_b_; }
347 virtual double p() {
return p_success_; }
Binary distribution requires twp options and a probability.
BinaryDoubleDist(double p_success, double choice_a, double choice_b)
Binary distribution requires twp options and a probability.
BinaryIntDist(double p_success, int choice_a, int choice_b)
Binomial distribution requries an integer number of trials and a probability of success for each tria...
boost::shared_ptr< BinomialIntDist > Ptr
BinomialIntDist(int trials, double p_success)
boost::shared_ptr< DoubleDistribution > Ptr
virtual double sample()=0
Exponential distribution requires lambda.
ExponentialDoubleDist(double lambda)
boost::shared_ptr< ExponentialDoubleDist > Ptr
Exponential distribution requires lambda.
ExponentialIntDist(double lambda)
boost::shared_ptr< ExponentialIntDist > Ptr
FixedDoubleDist(double value_)
boost::shared_ptr< FixedDoubleDist > Ptr
boost::shared_ptr< FixedIntDist > Ptr
boost::shared_ptr< IntDistribution > Ptr
NegativeBinomialIntDist takes the number of successes desired and a probability of success on a singl...
NegativeBinomialIntDist(int successes, double p_success)
boost::shared_ptr< NegativeBinomialIntDist > Ptr
boost::shared_ptr< NormalDoubleDist > Ptr
NormalDoubleDist(double mean, double std_dev, double min=0, double max=1)
NormalIntDist(double mean, double std_dev, int min=0, int max=1)
boost::shared_ptr< NormalIntDist > Ptr
Poisson distribution requires a mean.
boost::shared_ptr< PoissonDoubleDist > Ptr
PoissonDoubleDist(double mean)
Poisson distribution requires a mean.
boost::shared_ptr< PoissonIntDist > Ptr
PoissonIntDist(double mean)
A random number generator.
double random_01()
wrappers for boost::random distributions
int random_uniform_int(int low, int high)
generate a random integer between [low, high)
double random_uniform_real(double low, double high)
generate a random real number between [low, high)
void Initialize(SimInfo si)
Initialize from seed.
double random_normal_real(double mean, double std_dev, double low=0, double high=std::numeric_limits< double >::max())
generate a double from a normal distribution, with truncation at low and high
int random_normal_int(double mean, double std_dev, int low=0, int high=std::numeric_limits< int >::max())
generates an integer from a normal distribution, with truncation uses rounding to convert double to i...
static NormalDist makeNormalDist(double mean, double std_dev, double min, double max)
Container for a static simulation-global parameters that both describe the simulation and affect its ...
For values that are too big, too small, etc.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
boost::random::mt19937 Generator
boost::random::variate_generator< Generator &, boost::random::normal_distribution<> > NormalDist
void Warn(const std::string &msg)
Issue a warning with the approriate message, accoring to the current warning settings.