5#ifndef LINE_SOLVERS_SSA_SOLVER_SSA_NRM_SPACE_H
6#define LINE_SOLVERS_SSA_SOLVER_SSA_NRM_SPACE_H
138 std::vector<std::vector<double>>* arv =
nullptr,
139 std::vector<std::vector<double>>* dep =
nullptr) {
140 const std::size_t local =
sn.nodes.size() + 1;
141 const std::size_t R =
sn.nclasses;
142 const std::size_t NF =
sn.stateful_nodes.size();
143 std::vector<EnabledEvent<T>> out;
144 if (arv) arv->assign(NF, std::vector<double>(R, 0.0));
145 if (dep) dep->assign(NF, std::vector<double>(R, 0.0));
147 for (std::size_t a = 0; a < sync.size(); ++a) {
149 const std::size_t isf_a =
sn.stateful_index(sy.
active.node);
150 if (isf_a == 0)
continue;
151 const std::size_t isf_p =
153 if (sy.
passive.node != local && isf_p == 0)
continue;
158 for (std::size_t ia = 0; ia < oa.
space.size(); ++ia) {
161 if (!(rate > 0) || !(pa > 0))
continue;
163 if (sy.
passive.node == local) {
175 const std::vector<T>& src =
182 for (std::size_t ip = 0; ip < op.
space.size(); ++ip) {
184 if (!(pp > 0))
continue;
188 if (!(e.
rate > 0))
continue;
199 if (dep) (*dep)[isf_a - 1][sy.
active.cls - 1] += fired;
200 if (arv && isf_p != 0) (*arv)[isf_p - 1][sy.
passive.cls - 1] += fired;
204 for (std::size_t g = 0; g < gsync.size(); ++g) {
206 for (std::size_t
io = 0;
io < go.
space.size(); ++
io) {
209 if (!(w > 0))
continue;
211 e.
sync = sync.size() + g;
216 for (std::size_t j = 0; j < gsync[g].passive.size(); ++j) {
218 const std::size_t pisf =
sn.stateful_index(pev.
node);
219 if (pisf == 0 || pev.
cls == 0 || pev.
cls > R)
continue;
221 (*dep)[pisf - 1][pev.
cls - 1] += w;
223 (*arv)[pisf - 1][pev.
cls - 1] += w;
258 std::vector<double>
n;
259 std::vector<std::vector<std::size_t>>
buf;
268 std::vector<double>
pi;
295namespace space_detail {
323 : sn_(
sn), opt_(
opt), rng_(
opt.seed) {
327 build_dependencies();
328 build_initial_state();
346 std::size_t
nslots()
const {
return NS_; }
350 std::vector<double> A(nrx_, 0.0);
351 for (std::size_t k = 0; k < nrx_; ++k) A[k] = propensity(k, s);
362 std::size_t I_ = 0, K_ = 0, M_ = 0, NS_ = 0, nrx_ = 0;
363 std::vector<bool> is_station_;
364 std::vector<std::size_t> to_station_;
365 std::vector<SchedStrategy> sched_;
366 std::vector<double> mi_;
367 std::vector<std::vector<double>> rate_;
371 std::vector<std::size_t> rx_node_, rx_class_, rx_from_, rx_det_dest_;
372 std::vector<std::vector<std::size_t>> rx_to_;
373 std::vector<std::vector<double>> rx_cdf_;
374 std::vector<std::size_t> rx_nnzp_;
375 std::vector<std::vector<std::size_t>> D_;
381 void build_reactions();
382 void build_dependencies();
383 void build_initial_state();
385 double class_pop(
const std::vector<double>& X, std::size_t ind, std::size_t r)
const {
386 return X[ind * K_ + r];
388 double node_pop(
const std::vector<double>& X, std::size_t ind)
const {
390 for (std::size_t r = 0; r < K_; ++r) s += X[ind * K_ + r];
393 double propensity(std::size_t j,
const NrmSpaceState& s)
const;
394 void update_buffers(std::size_t kfire,
const std::vector<double>& n,
395 std::vector<std::vector<std::size_t>>& bufs, std::size_t dest_pos,
396 bool have_dest)
const;
398 static constexpr std::size_t npos =
static_cast<std::size_t
>(-1);
409void NrmSpaceEngine<T>::check() {
410 for (std::size_t i = 0; i < sn_.
nstations; ++i) {
412 if (s == SchedStrategy::INF || s == SchedStrategy::EXT || s == SchedStrategy::PS ||
413 s == SchedStrategy::FCFS || s == SchedStrategy::LCFS)
416 "solver_ssa_nrm_space: station '" + sn_.
stations[i].name +
"' uses '" +
418 "' scheduling, which has no rate law in the explicit state-space variant. Its "
419 "propensity switch covers EXT, INF, PS, FCFS and LCFS only; use method='nrm', whose "
420 "engine carries the full set");
422 for (std::size_t i = 0; i < sn_.
nstations; ++i)
423 for (std::size_t r = 0; r < sn_.
nclasses; ++r) {
430 "solver_ssa_nrm_space: class '" + sn_.
classes[r].name +
431 "' has non-exponential service at station '" + sn_.
stations[i].name +
432 "'. The explicit state-space variant carries no phase dimension -- its state is "
433 "the (node, class) population vector and it reads sn.rates alone -- so a "
434 "phase-type process cannot be represented; use method='nrm', which expands it");
436 for (std::size_t r = 0; r < sn_.
nclasses; ++r)
437 if (!std::isfinite(sn_.
classes[r].population))
439 "solver_ssa_nrm_space: class '" + sn_.
classes[r].name +
440 "' is open. In the aggregate reaction network a Sink has no outgoing routing and "
441 "a Source's slot is a fictitious token that every arrival consumes, so the "
442 "aggregate state space of an open model is unbounded: every firing would add a "
443 "row to the table and pi would become the uniform law over the trace. Use "
444 "method='nrm', which integrates the metrics and stores no states");
447 for (std::size_t i = 0; i < sn_.
nstations; ++i)
450 "solver_ssa_nrm_space: station '" + sn_.
stations[i].name +
451 "' declares a class- or joint-dependent scaling. The explicit state-space "
452 "variant builds its propensities from sn.rates without evaluating the handle; "
453 "use method='nrm', whose engine applies it");
456 "solver_ssa_nrm_space: the model declares a finite capacity region. The explicit "
457 "state-space variant carries no region gate and no WAITQ FIFO; use method='nrm', "
458 "whose engine carries both");
459 for (
const qn::NodeDef& nd : sn_.
nodes) {
460 switch (nd.nodetype) {
463 "solver_ssa_nrm_space: node '" + nd.name +
464 "' is a Cache. The aggregate reaction network is built from sn.rtnodes and "
465 "sn.rates alone and carries no cache contents, so the hit/miss class switch "
466 "cannot be resolved at firing time");
470 "solver_ssa_nrm_space: node '" + nd.name +
471 "' makes this model a stochastic Petri net. A firing is atomic across every "
472 "arc it touches and is not a (node, class) departure, which is the only "
473 "reaction shape this variant builds");
477 "solver_ssa_nrm_space: node '" + nd.name +
478 "' makes this a fork-join model. A fork emits on several branches at once, "
479 "which no single-destination reaction can express, and the NRM does not "
480 "handle fork-join in any codebase");
491void NrmSpaceEngine<T>::build_layout() {
497 is_station_.assign(I_,
false);
498 to_station_.assign(I_, npos);
499 for (std::size_t i = 0; i < I_; ++i)
500 if (sn_.
nodes[i].station != 0) {
501 is_station_[i] =
true;
502 to_station_[i] = sn_.
nodes[i].station - 1;
504 sched_.assign(M_, SchedStrategy::FCFS);
505 for (std::size_t i = 0; i < M_; ++i) sched_[i] = sn_.
stations[i].sched;
511 rate_.assign(I_, std::vector<double>(K_, 0.0));
512 for (std::size_t i = 0; i < I_; ++i) {
513 if (is_station_[i]) {
514 const std::size_t ist = to_station_[i];
515 mi_[i] = sn_.
stations[ist].nservers;
517 for (std::size_t r = 0; r < K_; ++r)
519 rate_[i][r] = num_traits<T>::to_double(sn_.
rates(ist, r));
536void NrmSpaceEngine<T>::build_reactions() {
538 rx_node_.assign(nrx_, 0);
539 rx_class_.assign(nrx_, 0);
540 rx_from_.assign(nrx_, 0);
541 rx_det_dest_.assign(nrx_, npos);
542 rx_to_.assign(nrx_, std::vector<std::size_t>());
543 rx_cdf_.assign(nrx_, std::vector<double>());
544 rx_nnzp_.assign(nrx_, 0);
545 S_ = Matrix<double>(NS_, nrx_, 0.0);
547 for (std::size_t ind = 0; ind < I_; ++ind)
548 for (std::size_t r = 0; r < K_; ++r) {
549 const std::size_t k = ind * K_ + r;
554 for (std::size_t jnd = 0; jnd < I_; ++jnd)
555 for (std::size_t s = 0; s < K_; ++s) {
557 num_traits<T>::to_double(sn_.
rtnodes(ind * K_ + r, jnd * K_ + s));
558 if (!(p > 0.0))
continue;
559 S_(jnd * K_ + s, k) += p;
566 for (std::size_t k = 0; k < nrx_; ++k) {
567 std::vector<double> Pcol(NS_, 0.0);
568 for (std::size_t i = 0; i < NS_; ++i) {
569 const double v = S_(i, k);
570 Pcol[i] = v < 0.0 ? v + 1.0 : v;
571 if (v > 0.0 && rx_det_dest_[k] == npos) rx_det_dest_[k] = i;
573 for (std::size_t i = 0; i < NS_; ++i)
574 if (Pcol[i] != 0.0) ++rx_nnzp_[k];
582 if (rx_nnzp_[k] == 1 && rx_det_dest_[k] == npos && Pcol[rx_from_[k]] != 0.0)
583 rx_det_dest_[k] = rx_from_[k];
584 if (rx_nnzp_[k] > 1) {
586 for (std::size_t i = 0; i < NS_; ++i)
587 if (Pcol[i] != 0.0) {
588 rx_to_[k].push_back(i);
590 rx_cdf_[k].push_back(acc);
604void NrmSpaceEngine<T>::build_dependencies() {
605 D_.assign(nrx_, std::vector<std::size_t>());
606 for (std::size_t k = 0; k < nrx_; ++k) {
607 std::vector<bool> touched(I_,
false);
608 for (std::size_t i = 0; i < NS_; ++i)
609 if (S_(i, k) != 0.0) touched[i / K_] =
true;
610 for (std::size_t ind = 0; ind < I_; ++ind) {
611 if (!touched[ind])
continue;
612 for (std::size_t r = 0; r < K_; ++r) D_[k].push_back(ind * K_ + r);
614 std::sort(D_[k].begin(), D_[k].end());
615 D_[k].erase(std::unique(D_[k].begin(), D_[k].end()), D_[k].end());
629void NrmSpaceEngine<T>::build_initial_state() {
630 init_.
n.assign(NS_, 0.0);
631 init_.
buf.assign(I_, std::vector<std::size_t>());
632 for (std::size_t r = 0; r < K_; ++r) {
633 const double pop = sn_.
classes[r].population;
634 if (!(pop > 0.0))
continue;
635 const std::size_t rs = sn_.
classes[r].refstat;
636 if (rs < 1 || rs > M_)
638 "' has no reference station");
644 for (std::size_t ind = 0; ind < I_; ++ind) {
645 if (!is_station_[ind] || !space_detail::space_sched_buffered(sched_[to_station_[ind]]))
647 double waiting = std::max(0.0, node_pop(init_.
n, ind) - mi_[ind]);
648 for (std::size_t r = 0; r < K_ && waiting > 0.0; ++r) {
649 const double take = std::min(waiting, init_.
n[ind * K_ + r]);
650 for (std::size_t c = 0; c < static_cast<std::size_t>(take); ++c)
651 init_.
buf[ind].push_back(r);
659double NrmSpaceEngine<T>::propensity(std::size_t j,
const NrmSpaceState& st)
const {
660 const std::size_t ind = rx_node_[j], r = rx_class_[j];
661 const std::vector<double>& X = st.n;
662 if (!is_station_[ind]) {
666 return rate_[ind][r] * std::min(1.0, class_pop(X, ind, r));
668 const std::size_t ist = to_station_[ind];
670 switch (sched_[ist]) {
671 case SchedStrategy::EXT:
672 return rate_[ind][r];
673 case SchedStrategy::INF:
674 return rate_[ind][r] * class_pop(X, ind, r);
675 case SchedStrategy::PS: {
676 if (K_ == 1)
return rate_[ind][r] * std::min(mi_[ind], class_pop(X, ind, r));
677 const double tot = node_pop(X, ind);
678 return rate_[ind][r] * (class_pop(X, ind, r) / (eps +
tot)) *
679 std::min(mi_[ind], eps + tot);
681 case SchedStrategy::FCFS:
682 case SchedStrategy::LCFS: {
686 double waiting = 0.0;
687 for (std::size_t c : st.buf[ind])
688 if (c == r) waiting += 1.0;
689 return rate_[ind][r] * std::max(0.0, class_pop(X, ind, r) - waiting);
693 "solver_ssa_nrm_space: the scheduling policy '" +
695 sn_.
stations[ist].name +
"' has no rate law in the explicit state-space variant");
709void NrmSpaceEngine<T>::update_buffers(std::size_t kfire,
const std::vector<double>& n,
710 std::vector<std::vector<std::size_t>>& bufs,
711 std::size_t dest_pos,
bool have_dest)
const {
712 const std::size_t ind = rx_node_[kfire];
713 if (is_station_[ind] && !bufs[ind].empty()) {
715 if (s == SchedStrategy::FCFS) bufs[ind].pop_back();
716 else if (s == SchedStrategy::LCFS) bufs[ind].erase(bufs[ind].begin());
718 if (!have_dest || dest_pos == npos)
return;
719 const std::size_t jnd = dest_pos / K_, s = dest_pos % K_;
720 if (!is_station_[jnd] || !space_detail::space_sched_buffered(sched_[to_station_[jnd]]))
return;
721 if (node_pop(n, jnd) > mi_[jnd]) bufs[jnd].insert(bufs[jnd].begin(), s);
724namespace space_detail {
727inline std::vector<double> space_key(
const NrmSpaceState& s) {
728 std::vector<double> key = s.n;
729 for (std::size_t i = 0; i < s.buf.size(); ++i) {
733 for (std::size_t j = 0; j < s.buf[i].size(); ++j)
734 key.push_back(
static_cast<double>(s.buf[i][j]) + 1.0);
743 std::vector<NrmSpaceState> out;
744 std::map<std::vector<double>, std::size_t> seen;
745 std::vector<std::size_t> stack;
746 seen[space_detail::space_key(init_)] = 0;
747 out.push_back(init_);
750 std::size_t expanded = 0;
751 while (!stack.empty()) {
754 if ((++expanded & 1023u) == 0)
756 const std::size_t si = stack.back();
759 for (std::size_t k = 0; k < nrx_; ++k) {
760 if (!(propensity(k, st) > 0.0))
continue;
764 std::vector<std::size_t> dests;
765 if (rx_nnzp_[k] > 1) dests = rx_to_[k];
766 else if (rx_det_dest_[k] != npos) dests.push_back(rx_det_dest_[k]);
767 else dests.push_back(npos);
768 for (std::size_t d = 0; d < dests.size(); ++d) {
770 ns.
n[rx_from_[k]] -= 1.0;
771 if (dests[d] != npos) ns.
n[dests[d]] += 1.0;
772 update_buffers(k, ns.
n, ns.
buf, dests[d], dests[d] != npos);
773 const std::vector<double> key = space_detail::space_key(ns);
774 if (seen.find(key) != seen.end())
continue;
775 if (out.size() >= opt_.state_max)
777 "solver_ssa_nrm_space: the reachable aggregate state space exceeds the "
778 "cap of " + std::to_string(opt_.state_max) +
779 " states. The explicit state-space variant tabulates one row per state, "
780 "so a larger space is refused rather than truncated: a pi normalized over "
781 "the states that happened to fit is the law of a different chain. Raise "
782 "state_max, or use method='nrm', which stores no states");
783 seen[key] = out.size();
785 stack.push_back(out.size() - 1);
799 "solver_ssa_nrm_space: the Next Reaction Method draws its clocks as -log(u), "
800 "which needs transcendental arithmetic");
803 out.
seed = opt_.seed;
804 if (nrx_ == 0)
return out;
807 std::vector<double> Ak(nrx_, 0.0), Pk(nrx_, 0.0), Tk(nrx_, 0.0), tau(nrx_, 0.0);
808 for (std::size_t k = 0; k < nrx_; ++k) {
809 Ak[k] = propensity(k, cur);
810 Pk[k] = -std::log(rng_.uniform());
811 tau[k] = Ak[k] > 0.0 ? (Pk[k] - Tk[k]) / Ak[k] : std::numeric_limits<double>::infinity();
816 std::map<std::vector<double>, std::size_t> index;
817 std::vector<std::vector<double>> cached;
818 double total_time = 0.0;
821 out.
tran_rx.reserve(opt_.samples);
825 bool time_stopped =
false;
826 for (std::size_t n = 0; n < opt_.samples; ++n) {
833 std::size_t kfire = 0;
834 double dt = std::numeric_limits<double>::infinity();
835 for (std::size_t k = 0; k < nrx_; ++k)
842 "solver_ssa_nrm_space: deadlock -- every reaction has propensity zero, so the "
843 "sample path cannot advance");
847 const std::vector<double> key = space_detail::space_key(cur);
848 const std::map<std::vector<double>, std::size_t>::const_iterator it = index.find(key);
850 if (it != index.end()) {
853 if (out.
space.size() >= opt_.state_max)
855 "solver_ssa_nrm_space: the path has visited more than the cap of " +
856 std::to_string(opt_.state_max) +
857 " distinct states. The explicit state-space variant tabulates one row per "
858 "state, so it is refused rather than truncated: a pi normalized over the "
859 "states that happened to fit is the law of a different chain. Raise "
860 "state_max, or use method='nrm', which stores no states");
861 si = out.
space.size();
863 out.
space.push_back(cur);
864 out.
pi.push_back(0.0);
865 cached.push_back(Ak);
867 if (n >= n_warm) out.
pi[si] += dt;
873 std::size_t dest = npos;
874 if (rx_nnzp_[kfire] > 1) {
877 const double u = rng_.uniform();
878 std::size_t sel = rx_cdf_[kfire].size() - 1;
879 for (std::size_t i = 0; i < rx_cdf_[kfire].size(); ++i)
880 if (rx_cdf_[kfire][i] > u) {
884 dest = rx_to_[kfire][sel];
885 cur.
n[rx_from_[kfire]] -= 1.0;
888 for (std::size_t i = 0; i < NS_; ++i)
889 if (S_(i, kfire) != 0.0) cur.
n[i] += S_(i, kfire);
890 dest = rx_det_dest_[kfire];
892 update_buffers(kfire, cur.
n, cur.
buf, dest, dest != npos);
894 for (std::size_t k = 0; k < nrx_; ++k) Tk[k] += Ak[k] * dt;
903 for (std::size_t k : D_[kfire]) Ak[k] = propensity(k, cur);
904 if (is_station_[rx_node_[kfire]] &&
905 space_detail::space_sched_buffered(sched_[to_station_[rx_node_[kfire]]]))
906 for (std::size_t k = 0; k < nrx_; ++k) Ak[k] = propensity(k, cur);
908 Pk[kfire] -= std::log(rng_.uniform());
909 for (std::size_t k = 0; k < nrx_; ++k)
911 Ak[k] > 0.0 ? (Pk[k] - Tk[k]) / Ak[k] : std::numeric_limits<double>::infinity();
916 if (time_stopped && out.
samples <= n_warm)
918 "solver_ssa_nrm_space: the wall-clock time budget (options.timeout) "
919 "ran out inside the warmup, before any sample was collected");
922 for (std::size_t s = 0; s < out.
pi.size(); ++s) tot += out.
pi[s];
924 for (std::size_t s = 0; s < out.
pi.size(); ++s) out.
pi[s] /= tot;
930 for (std::size_t s = 0; s < out.
space.size(); ++s)
931 for (std::size_t k = 0; k < nrx_; ++k)
932 out.
dep_rates(s, rx_from_[k]) += cached[s][k];
971 if constexpr (!std::is_same<T, double>::value) {
975 "solver_ssa_nrm_space: an SSA sample path is generated from exponential clocks, which "
976 "are logarithms of uniform draws; there is no exact value to compute and a wider "
977 "float carries no information the Monte Carlo error does not swamp. Rerun with "
981 const std::size_t M =
sn.nstations, K =
sn.nclasses;
1000 for (std::size_t k = 0; k < K; ++k) {
1001 const std::size_t refnd =
sn.station_to_node[
sn.classes[k].refstat - 1];
1002 for (std::size_t s = 0; s < r.
space.size(); ++s)
1006 for (std::size_t ist = 0; ist < M; ++ist) {
1007 const std::size_t ind =
sn.station_to_node[ist];
1008 for (std::size_t k = 0; k < K; ++k)
1009 for (std::size_t s = 0; s < r.
space.size(); ++s) {
1010 a.
TN(ist, k) += r.
pi[s] * r.
dep_rates(s, (ind - 1) * K + k);
1011 a.
QN(ist, k) += r.
pi[s] * r.
space[s].n[(ind - 1) * K + k];
1014 const SchedStrategy sched =
sn.stations[ist].sched;
1015 if (sched == SchedStrategy::EXT ||
1017 for (std::size_t k = 0; k < K; ++k) a.
QN(ist, k) = 0.0;
1020 if (sched == SchedStrategy::INF) {
1021 for (std::size_t k = 0; k < K; ++k) a.
UN(ist, k) = a.
QN(ist, k);
1027 const bool is_cd =
static_cast<bool>(
sn.stations[ist].cdscaling);
1028 const bool is_jd =
static_cast<bool>(
sn.stations[ist].jdscaling);
1029 for (std::size_t k = 0; k < K; ++k) {
1030 if (
sn.disabled[ist][k])
continue;
1032 if (!(mu > 0))
continue;
1036 double sdiv =
sn.stations[ist].nservers;
1037 if (is_cd || is_jd) {
1039 const std::vector<T>* pks[2] = {&
sn.stations[ist].cdscalingpeak,
1040 &
sn.stations[ist].jdscalingpeak};
1041 const char* names[2] = {
"setClassDependence",
"setJointDependence"};
1042 const bool on[2] = {is_cd, is_jd};
1043 for (std::size_t h = 0; h < 2; ++h) {
1044 if (!on[h])
continue;
1045 const std::vector<T>& pk = *pks[h];
1048 "solver_ssa_nrm_space: station '" +
sn.stations[ist].name +
1049 "' declares a dependent scaling with no declared peak rate. "
1050 "Utilization there is T/mu/peak, so pass the peak to " + names[h]);
1054 a.
UN(ist, k) = sdiv > 0 ? a.
TN(ist, k) / mu / sdiv : 0.0;
1058 for (std::size_t k = 0; k < K; ++k) {
1059 for (std::size_t ist = 0; ist < M; ++ist)
1060 a.
RN(ist, k) = a.
TN(ist, k) > 0 ? a.
QN(ist, k) / a.
TN(ist, k) : 0.0;
1061 if (a.
XN[k] > 0) a.
CN[k] =
sn.classes[k].population / a.
XN[k];
NumericError(const std::string &what)
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
std::size_t nof_nodes() const
std::vector< std::vector< Distrib< T > > > service
service[i][r], 0-based station and class; a disabled entry marks a pair never visited.
std::vector< std::vector< bool > > disabled
std::vector< JobClass > classes
std::vector< Station< T > > stations
stations[k-1] is the k-th station
Matrix< T > rates
(nstations x nclasses) service rates and SCVs, with a PARALLEL disabled flag instead of MATLAB's NaN ...
std::vector< NodeDef > nodes
every node, in creation order
std::vector< std::size_t > station_to_node
(nstations) 1-based node index
std::vector< Region > regions
The aggregate NRM engine of solver_ssa_nrm_space.m.
NrmSpaceEngine(const qn::NetworkStruct< T > &sn, const SsaNrmSpaceOptions &opt)
std::vector< double > propensities(const NrmSpaceState &s) const
The whole propensity vector at a state, the reference's reactCache entry.
SsaNrmSpaceRun< T > run()
Run opt.samples firings and return the tabulated path.
std::vector< NrmSpaceState > enumerate_space() const
The reachable aggregate state space, closed forward from the initial state over the REACTIONS alone.
std::size_t nreactions() const
std::size_t nslots() const
const NrmSpaceState & initial() const
The uniform source, MATLAB's rand.
What refreshProcessRepresentations and refreshLST compute FROM a distribution: the (D0,...
The exception types the port throws.
options.timeout: one wall-clock budget per top-level solve, on a per-THREAD deadline stack.
Dense matrix and non-owning view.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
@ POST
produce to a place or queue buffer
@ PRE
consume from a place or queue buffer, no server effect
ProcessType
Distribution kinds, with the values of MATLAB ProcessType.
const char * sched_to_text(SchedStrategy s)
NodeType
Node kinds, with the values of MATLAB NodeType.
double tot(const std::vector< double > &pops)
SchedStrategy
The three scheduling disciplines the AMVA and Schmidt recursions branch on.
GlobalOutcome< T > after_global_event(const NetworkStruct< T > &sn, const NetState< T > &glspace, const GlobalSync< T > &gl)
Port of State.afterGlobalEvent: an SPN mode ENABLEs or FIREs.
EventOutcome< T > after_event(const NetworkStruct< T > &sn, std::size_t ind, const std::vector< T > &inspace, EventType event, std::size_t cls, bool no_promote=false, const T &aux_rate=num_traits< T >::from_int(0))
Port of State.afterEvent: the successors of one event at one NODE.
std::size_t ssa_warmup_firings(double warmupfrac, std::size_t samples)
Firings whose tallies an engine discards: floor(warmupfrac * samples), with an unset (negative) fract...
std::vector< EnabledEvent< T > > ssa_find_enabled(const qn::NetworkStruct< T > &sn, const std::vector< qn::Sync< T > > &sync, const std::vector< qn::GlobalSync< T > > &gsync, const qn::NetState< T > &state, std::vector< std::vector< double > > *arv=nullptr, std::vector< std::vector< double > > *dep=nullptr)
Port of solver_ssa_findenabled.m: every synchronization that can fire in state, with the arrival and ...
SsaNrmSpaceSolution< T > solver_ssa_nrm_space_analyzer(const qn::NetworkStruct< T > &sn, const SsaNrmSpaceOptions &opt)
Port of the else branch of solver_ssa_analyzer_nrm.m, the one state_space_gen selects: the means as p...
SsaNrmSpaceRun< T > solver_ssa_nrm_space(const qn::NetworkStruct< T > &sn, const SsaNrmSpaceOptions &opt)
solver_ssa_nrm_space.m: run the tabulating engine.
bool timeout_exceeded()
The checkpoint: true when the innermost budget has run out, marking it tripped.
void timeout_check(const char *where)
The raising checkpoint, for a computation with no valid partial result: throws LINE:numerical:Timeout...
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
Controls, results and the random source of SolverSSA.
Port of the MATLAB +State package: the encoding that turns a station's state row into marginal job co...
Port of the event half of MATLAB's +State package: the successor states an event produces at one node...
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
static constexpr double Immediate
Rate of an Immediate distribution; its mean is 1/Immediate = 1e-8.
static constexpr double Zero
static constexpr double MaxInt
Stand-in for an unbounded COUNT, MATLAB GlobalConstants.MaxInt.
What one event produces at one node: the successor rows, their rates and their probabilities,...
std::vector< T > prob
per-row probability of the choice
std::vector< std::vector< T > > space
successor local state rows
std::vector< T > rate
per-row rate, -1 on a passive half
What one global event produces: a whole network state per outcome.
std::vector< NetState< T > > space
A GLOBAL synchronization: an SPN mode event and the place arcs it drives.
One half of a GLOBAL synchronization: a mode event at a node.
std::size_t node
1-based node index (a Transition, or a place)
std::size_t cls
1-based class the arc moves
One network state: the per-stateful-node local rows it is composed of.
std::vector< std::vector< T > > local
local[isf] is that node's state row
One synchronization: an ACTIVE event and the PASSIVE event it drives.
One transition the enabled scan found: where it goes, and at what rate.
qn::NetState< T > next
enabled_next_states{act}: the whole network state after it fires.
double rate
enabled_rates: rate * p_active * p_route * p_passive.
std::size_t sync
enabled_sync: index into sync, or sync.size() + g for a global one.
One state of the aggregate chain: the (node, class) populations, and the ordered buffer contents of e...
std::vector< std::vector< std::size_t > > buf
The knobs the space variant reads.
What solver_ssa_nrm_space.m returns, plus what makes it a measurement.
std::vector< double > tran_time
t: the cumulative time at each firing.
std::vector< double > pi
pi: the fraction of simulated time spent in each of them.
std::vector< std::size_t > tran_rx
kfires: which reaction fired.
Matrix< double > dep_rates
depRates, (states x nnodes*nclasses): the departure rate of each (node, class) in each state,...
std::vector< NrmSpaceState > space
outspace: the distinct states visited, in first-visit order.
The metric table, the table it came from, and the stream that produced it.
Controls, defaulting to SolverOptions('SSA') in the reference.
What the analyzer returns, in the same shape as the MVA and fluid results.
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.