BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
RandomDistributionFactory.cpp
Go to the documentation of this file.
2#include <exception>
3
4using namespace BPMNOS;
5
6RandomDistribution BPMNOS::make_distribution(const std::string& jsonString) {
7 nlohmann::json input = nlohmann::json::parse(jsonString);
8 return make_distribution(input);
9}
10
11RandomDistribution BPMNOS::make_distribution(const nlohmann::json& input) {
12 const std::string& distributionName = input.at("distribution");
13
14 // https://en.cppreference.com/w/cpp/numeric/random/
15 // all distributions implement min() and max()
16
17 if (distributionName == "uniform_int_distribution") {
18 // Produces integer values evenly distributed across a given range.
20 }
21
22 if (distributionName == "uniform_real_distribution") {
23 // Produces real values evenly distributed across a given range.
25 }
26
27 if (distributionName == "bernoulli_distribution") {
28 // Produces bool values with a given probability of a true outcome.
29 return make_distribution_impl<std::bernoulli_distribution>(input, "probability");
30 }
31
32 if (distributionName == "binomial_distribution") {
33 // The result obtained is the number of successes in a given number of trials, each of which succeeds with a given probability.
34 return make_distribution_impl<std::binomial_distribution<int>>(input, "trials", "probability");
35 }
36
37 if (distributionName == "negative_binomial_distribution") {
38 // The results represents the number of failures in a series of independent yes/no trials (each succeeds with a given probability), before exactly the given number of successes occur.
39 return make_distribution_impl<std::negative_binomial_distribution<int>>(input, "successes", "probability");
40 }
41
42 if (distributionName == "geometric_distribution") {
43 // The results represents the number of failures in a series of independent yes/no trials (each succeeds with probability p), before exactly 1 success occurs.
45 }
46
47 if (distributionName == "poisson_distribution") {
48 // The result obtained is the number of occurrences of a random event for a given mean indicating the number of its occurrences under the same conditions (on the same time/space interval).
50 }
51
52 if (distributionName == "exponential_distribution") {
53 // The result obtained is the time/distance until the next random event if random events occur at given rate per unit of time/distance.
55 }
56
57 if (distributionName == "gamma_distribution") {
58 // For shape parameter α, the value obtained is the sum of α independent exponentially distributed random variables, each of which has a mean of the scale parameter β.
59 return make_distribution_impl<std::gamma_distribution<double>>(input, "shape", "scale");
60 }
61
62 // weibull_distribution and extreme_value_distribution skipped
63
64 if (distributionName == "normal_distribution") {
65 // Generates random numbers according to the Normal (or Gaussian) random number distribution with given mean and standard deviation.
66 return make_distribution_impl<std::normal_distribution<double>>(input, "mean", "stddev");
67 }
68
69 if (distributionName == "lognormal_distribution") {
70 // Generates random numbers according to the Log-normal random number distribution with given log-scale and shape parameter.
71 return make_distribution_impl<std::normal_distribution<double>>(input, "log-scale", "shape");
72 }
73
74 // chi_squared_distribution, cauchy_distribution, fisher_f_distribution, and student_t_distribution skipped
75
76 if (distributionName == "discrete_distribution") {
77 // Produces a result with probabilities based on the given weights.
79 // result must be linked to outcomes (default outcomes are 0, 1, ..., n where n is the number of weights)
80 }
81
82 // piecewise_constant_distribution and piecewise_linear_distribution skipped because
83 // they require input manipulation to obtain iterators
84
85 throw std::runtime_error("Unknown distribution " + distributionName);
86}
87
std::function< double(RandomGenerator &)> RandomDistribution
RandomDistribution make_distribution(const std::string &jsonString)
RandomDistribution make_distribution_impl(nlohmann::json const &input, Parameters... parameters)