5#ifndef LINE_SOLVERS_SSA_SSA_TYPES_H
6#define LINE_SOLVERS_SSA_SSA_TYPES_H
46template <
class T,
class Outcome>
47inline void add_tag_rates(std::vector<std::vector<double>>& start,
48 std::vector<std::vector<double>>& preempt,
49 const T& sn, std::size_t node,
const Outcome& oc, std::size_t row,
51 if (!(w != 0) || node == 0 || node > sn.nodes.size())
return;
52 const std::size_t isf = sn.stateful_index(node);
53 if (isf == 0 || isf > start.size())
return;
54 if (row < oc.start.size())
55 for (std::size_t j = 0; j < oc.start[row].size(); ++j) {
56 const std::size_t cls = oc.start[row][j];
57 if (cls >= 1 && cls <= start[isf - 1].size()) start[isf - 1][cls - 1] += w;
59 if (row < oc.preempt.size())
60 for (std::size_t j = 0; j < oc.preempt[row].size(); ++j) {
61 const std::size_t cls = oc.preempt[row][j];
62 if (cls >= 1 && cls <= preempt[isf - 1].size()) preempt[isf - 1][cls - 1] += w;
75 unsigned long seed = 23000;
131 explicit SsaRng(
unsigned long seed) : g_(static_cast<std::uint_fast32_t>(seed)) {}
134 const std::uint64_t a = g_() >> 5, b = g_() >> 6;
135 return (
static_cast<double>(a) * 67108864.0 +
static_cast<double>(b) + 0.5) /
141 if (n == 0)
return 0;
142 const std::size_t k =
static_cast<std::size_t
>(
uniform() *
static_cast<double>(n));
143 return k < n ? k : n - 1;
150 std::size_t
draw(
const std::vector<double>& p) {
152 for (
double x : p) tot += x;
153 if (!(tot > 0.0))
return 0;
154 const double u =
uniform() * tot;
156 for (std::size_t i = 0; i < p.size(); ++i) {
158 if (acc > u)
return i;
std::size_t draw(const std::vector< double > &p)
Index drawn from the unnormalized nonnegative weights p, the reference's drawFromDist: an all-zero we...
std::size_t index(std::size_t n)
Uniform index in [0, n), the reference's 1 + floor(rand*n).
SsaRng(unsigned long seed)
Dense matrix and non-owning view.
Controls, defaulting to SolverOptions('SSA') in the reference.
std::size_t samples
Reaction firings to simulate; options.samples in the reference.
double warmupfrac
options.config.warmupfrac: the leading fraction of the path discarded before the means are taken.
std::string state_space_gen
options.config.state_space_gen of solver_ssa_analyzer_nrm.m: which of the two NRM engines runs.
std::string method
default and nrm both select the Next Reaction Method here.
unsigned long seed
options.seed; LINE's own default is 23000.
What the analyzer returns, in the same shape as the MVA and fluid results.
Matrix< double > StartN
The DERIVED rates, (nstations x nclasses): how often per unit time a class-r service STARTS at statio...
double simulated_time
Simulated time the metrics are averaged over; the reference's totalTime.
std::size_t samples
Reaction firings actually performed.
std::string method
The concrete algorithm, as the reference's method.
Matrix< double > PreemptN