1#ifndef CYCLUS_SRC_RNG_H
2#define CYCLUS_SRC_RNG_H
4#include <boost/random.hpp>
17typedef boost::random::variate_generator<
Generator&,
18 boost::random::normal_distribution<>>
23 friend class ::SimInitTest;
24 friend class ::RandomTest;
72 boost::random::normal_distribution<> dist(mean, std_dev);
92 double high = std::numeric_limits<double>::max());
97 int high = std::numeric_limits<int>::max());
102 typedef boost::shared_ptr<DoubleDistribution>
Ptr;
113 typedef boost::shared_ptr<FixedDoubleDist>
Ptr;
116 virtual double sample() {
return value; };
117 virtual double max() {
return value; };
122 boost::random::uniform_real_distribution<> dist;
125 typedef boost::shared_ptr<UniformDoubleDist>
Ptr;
128 virtual double sample() {
return dist(RandomNumberGenerator::gen_); }
129 virtual double max() {
return dist.max(); }
134 boost::random::normal_distribution<> dist;
139 typedef boost::shared_ptr<NormalDoubleDist>
Ptr;
142 : dist(mean, std_dev), min_(min), max_(
max) {
145 "Min and max cannot be equal for a normal distribution. Either use "
146 "FixedDoubleDist or change the min/max.");
148 if (max_ < (mean - 3 * std_dev) || min_ > (mean + 3 * std_dev)) {
150 "Dist is sampling from a tail of a truncated normal more than 3 "
151 "standard deviations from the mean. Drawing sampling may be "
156 virtual double max() {
return max_; }
162 boost::random::poisson_distribution<> dist;
166 typedef boost::shared_ptr<PoissonDoubleDist>
Ptr;
173 virtual double sample() {
return dist(RandomNumberGenerator::gen_); }
174 virtual double mean() {
return dist.mean(); }
180 boost::random::exponential_distribution<> dist;
184 typedef boost::shared_ptr<ExponentialDoubleDist>
Ptr;
191 virtual double sample() {
return dist(RandomNumberGenerator::gen_); }
192 virtual double lambda() {
return lambda_; }
198 boost::random::binomial_distribution<int> dist;
200 double choice_a_, choice_b_;
204 : dist(1, p_success), choice_a_(choice_a), choice_b_(choice_b) {
206 throw ValueError(
"Probability of choice A must be positive");
210 return dist(RandomNumberGenerator::gen_) ? choice_a_ : choice_b_;
212 virtual double p() {
return p_success_; }
217 typedef boost::shared_ptr<IntDistribution>
Ptr;
226 typedef boost::shared_ptr<FixedIntDist>
Ptr;
234 boost::random::uniform_int_distribution<> dist;
237 typedef boost::shared_ptr<UniformIntDist>
Ptr;
240 virtual int sample() {
return dist(RandomNumberGenerator::gen_); }
241 virtual int max() {
return dist.max(); }
246 boost::random::normal_distribution<> dist;
251 typedef boost::shared_ptr<NormalIntDist>
Ptr;
254 : dist(mean, std_dev), min_(min), max_(
max) {
257 "Min and max cannot be equal for a normal distribution. Either use "
258 "FixedIntDist or change the min/max.");
260 if (max_ < (mean - 3 * std_dev) || min_ > (mean + 3 * std_dev)) {
262 "Dist is sampling from a tail of a truncated normal more than 3 "
263 "standard deviations from the mean. Drawing sampling may be "
268 virtual int max() {
return max_; }
276 boost::random::binomial_distribution<int> dist;
281 typedef boost::shared_ptr<BinomialIntDist>
Ptr;
284 : dist(
trials, p_success), trials_(
trials), p_success_(p_success) {
286 throw ValueError(
"Max 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_; }
303 boost::random::negative_binomial_distribution<> dist;
308 typedef boost::shared_ptr<NegativeBinomialIntDist>
Ptr;
313 p_success_(p_success) {
315 throw ValueError(
"Successes must be positive and greater than zero");
317 if (p_success > 1 || p_success < 0) {
318 throw ValueError(
"Probability must be between zero and one");
321 virtual int sample() {
return dist(RandomNumberGenerator::gen_); }
323 virtual int p() {
return p_success_; }
329 boost::random::poisson_distribution<> dist;
333 typedef boost::shared_ptr<PoissonIntDist>
Ptr;
340 virtual int sample() {
return dist(RandomNumberGenerator::gen_); }
341 virtual double mean() {
return dist.mean(); }
347 boost::random::exponential_distribution<> dist;
351 typedef boost::shared_ptr<ExponentialIntDist>
Ptr;
358 virtual int sample() {
return dist(RandomNumberGenerator::gen_); }
359 virtual double lambda() {
return lambda_; }
365 boost::random::binomial_distribution<int> dist;
367 int choice_a_, choice_b_;
371 : dist(1, p_success), choice_a_(choice_a), choice_b_(choice_b) {
373 throw ValueError(
"Probability of choice A must be positive");
377 return dist(RandomNumberGenerator::gen_) ? choice_a_ : choice_b_;
379 virtual double p() {
return p_success_; }
BinaryDoubleDist(double p_success, double choice_a, double choice_b)
BinaryIntDist(double p_success, int choice_a, int choice_b)
boost::shared_ptr< BinomialIntDist > Ptr
BinomialIntDist(int trials, double p_success)
boost::shared_ptr< DoubleDistribution > Ptr
virtual double sample()=0
ExponentialDoubleDist(double lambda)
boost::shared_ptr< ExponentialDoubleDist > Ptr
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(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
boost::shared_ptr< PoissonDoubleDist > Ptr
PoissonDoubleDist(double mean)
boost::shared_ptr< PoissonIntDist > Ptr
PoissonIntDist(double mean)
A random number generator.
friend class FixedIntDist
friend class FixedDoubleDist
friend class UniformIntDist
double random_01()
wrappers for boost::random distributions
friend class PoissonIntDist
friend class BinomialIntDist
friend class UniformDoubleDist
int random_uniform_int(int low, int high)
generate a random integer between [low, high)
friend class BinaryDoubleDist
friend class NegativeBinomialIntDist
friend class BinaryIntDist
double random_uniform_real(double low, double high)
generate a random real number between [low, high)
void Initialize(SimInfo si)
Initialize from seed.
friend class ExponentialIntDist
friend class NormalIntDist
friend class NormalDoubleDist
friend class PoissonDoubleDist
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)
friend class ExponentialDoubleDist
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.