BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
RandomDistributionFactory.h
Go to the documentation of this file.
1#ifndef BPMNOS_Model_RandomDistributionFactory_H
2#define BPMNOS_Model_RandomDistributionFactory_H
3
4#include <string>
5#include <random>
6#include <map>
7#include <functional>
8#include <nlohmann/json.hpp>
9#include <limex.h>
10
11namespace BPMNOS {
12
13using RandomGenerator = std::mt19937;
14using RandomDistribution = std::function<double(RandomGenerator &)>;
15
16template <class DistributionType, class... Parameters>
17RandomDistribution make_distribution_impl(nlohmann::json const &input, Parameters... parameters) {
18 return DistributionType{input.at(parameters)...};
19}
20
21RandomDistribution make_distribution(const std::string& jsonString);
22RandomDistribution make_distribution(const nlohmann::json& input);
23
24/**
25 * @brief Factory for random distribution functions in LIMEX expressions.
26 *
27 * Registers random functions (uniform, normal, etc.) with a LIMEX handle.
28 * Before evaluating expressions containing random functions, setCurrentRng()
29 * must be called to provide the RNG context.
30 */
32public:
33 /**
34 * @brief Register all random distribution functions with the given LIMEX handle.
35 *
36 * Supported functions:
37 * - uniform(min, max): Uniform real distribution
38 * - uniform_int(min, max): Uniform integer distribution
39 * - normal(mean, stddev): Normal/Gaussian distribution
40 * - exponential(rate): Exponential distribution
41 * - poisson(mean): Poisson distribution
42 * - bernoulli(p): Bernoulli (0 or 1)
43 * - binomial(n, p): Binomial distribution
44 * - gamma(shape, scale): Gamma distribution
45 * - lognormal(logscale, shape): Log-normal distribution
46 * - geometric(p): Geometric distribution
47 */
48 void registerFunctions(LIMEX::Handle<double>& handle);
49
50 /**
51 * @brief Set the current RNG to use for expression evaluation.
52 *
53 * Must be called before evaluating any expression containing random functions.
54 * @param rng Pointer to the RNG to use, or nullptr to clear.
55 */
56 void setCurrentRng(std::mt19937* rng) { currentRng = rng; }
57
58 /**
59 * @brief Get the current RNG.
60 */
61 std::mt19937* getCurrentRng() const { return currentRng; }
62
63private:
64 std::mt19937* currentRng = nullptr;
65};
66
67} // namespace BPMNOS
68
69#endif // BPMNOS_Model_RandomDistributionFactory_H
Factory for random distribution functions in LIMEX expressions.
std::mt19937 * getCurrentRng() const
Get the current RNG.
void registerFunctions(LIMEX::Handle< double > &handle)
Register all random distribution functions with the given LIMEX handle.
void setCurrentRng(std::mt19937 *rng)
Set the current RNG to use for expression evaluation.
std::mt19937 RandomGenerator
std::function< double(RandomGenerator &)> RandomDistribution
RandomDistribution make_distribution(const std::string &jsonString)
RandomDistribution make_distribution_impl(nlohmann::json const &input, Parameters... parameters)