5#ifndef LINE_SOLVERS_CTMC_SOLVER_CTMC_WAITQ_H
6#define LINE_SOLVERS_CTMC_SOLVER_CTMC_WAITQ_H
91 std::vector<std::vector<std::size_t>>
buf;
98 std::vector<std::vector<std::vector<std::size_t>>>
buf;
101namespace waitq_detail {
113 std::vector<bool> member;
114 std::vector<double> ccap;
116 double memcap = -1.0;
117 std::vector<double> size;
120 std::vector<bool> iswaitq;
121 std::size_t lmax = 0;
122 std::vector<std::size_t> tokbound;
130bool tok_full(
const RegionCaps<T>& cap,
const std::vector<std::size_t>& buf, std::size_t cls, std::size_t K) {
132 for (std::size_t t : buf)
133 if ((t - 1) % K + 1 == cls) ++n;
134 return n >= (cls - 1 < cap.tokbound.size() ? cap.tokbound[cls - 1] : 0);
138std::vector<RegionCaps<T>> extract_caps(
const NetworkStruct<T>& sn) {
139 const std::size_t M = sn.stations.size(), K = sn.nclasses;
140 std::vector<RegionCaps<T>> out;
141 out.reserve(sn.regions.size());
142 for (std::size_t f = 0; f < sn.regions.size(); ++f) {
143 const typename NetworkStruct<T>::Region& rg = sn.regions[f];
145 c.member.assign(M,
false);
146 c.ccap.assign(K, -1.0);
147 c.size.assign(K, 1.0);
148 c.iswaitq.assign(K,
false);
149 for (std::size_t i = 0; i < M; ++i) {
150 if (i >= rg.members.size() || !rg.members[i])
continue;
154 for (std::size_t k = 0; k < K && k < rg.cap[i].size(); ++k)
155 if (rg.cap[i][k] != -1.0)
156 c.ccap[k] = c.ccap[k] == -1.0 ? rg.cap[i][k] : std::min(c.ccap[k], rg.cap[i][k]);
157 if (K < rg.cap[i].size() && rg.cap[i][K] != -1.0)
158 c.gcap = c.gcap == -1.0 ? rg.cap[i][K] : std::min(c.gcap, rg.cap[i][K]);
159 if (i < rg.maxmem.size() && rg.maxmem[i] != -1.0)
160 c.memcap = c.memcap == -1.0 ? rg.maxmem[i] : std::min(c.memcap, rg.maxmem[i]);
162 for (std::size_t k = 0; k < K; ++k) {
163 if (k < rg.size.size()) c.size[k] = num_traits<T>::to_double(rg.size[k]);
164 c.iswaitq[k] = k < rg.rule.size() && rg.rule[k] != DropStrategy::DROP;
175bool violates(
const RegionCaps<T>& c,
const std::vector<double>& x) {
176 double total = 0, memory = 0;
177 for (std::size_t k = 0; k < x.size(); ++k) {
179 memory += x[k] * c.size[k];
180 if (c.ccap[k] != -1.0 && x[k] > c.ccap[k] + 1e-9)
return true;
182 if (c.gcap != -1.0 && total > c.gcap + 1e-9)
return true;
183 if (c.memcap != -1.0 && memory > c.memcap + 1e-9)
return true;
184 for (std::size_t row = 0; row < c.A.rows() && row < c.b.size(); ++row) {
186 for (std::size_t k = 0; k < x.size() && k < c.A.cols(); ++k)
187 lhs += num_traits<T>::to_double(c.A(row, k)) * x[k];
188 if (lhs > num_traits<T>::to_double(c.b[row]) + 1e-9)
return true;
202std::vector<double> region_aggr(
const NetworkStruct<T>& sn,
const RegionCaps<T>& c,
203 const NetState<T>& net) {
204 const std::size_t K = sn.nclasses;
205 std::vector<double> x(K, 0.0);
206 for (std::size_t i = 0; i < c.member.size(); ++i) {
207 if (!c.member[i])
continue;
208 const std::size_t ind = sn.node_of_station(i + 1);
209 const std::size_t isf = sn.stateful_index(ind);
210 if (isf == 0)
continue;
212 for (std::size_t k = 0; k < K && k < mg.second.size(); ++k) {
213 const double v = num_traits<T>::to_double(mg.second[k]);
217 if (std::isfinite(v)) x[k] += v;
225std::vector<double> waitq_key(
const WaitqState<T>& ws) {
226 std::vector<double> key = ctmc_detail::state_key(ws.net);
227 for (std::size_t f = 0; f < ws.buf.size(); ++f) {
229 for (std::size_t j = 0; j < ws.buf[f].size(); ++j)
230 key.push_back(
static_cast<double>(ws.buf[f][j]));
246void resolve_lmax(
const NetworkStruct<T>& sn,
const std::vector<std::size_t>& cutoff,
247 std::vector<RegionCaps<T>>& caps) {
248 const std::size_t K = sn.nclasses;
249 const std::vector<double> N = sn.njobs();
250 std::vector<std::size_t> tokbound(K, 0);
251 for (std::size_t r = 0; r < K; ++r) {
253 for (std::size_t f = 0; f < caps.size(); ++f)
254 if (caps[f].iswaitq[r]) any =
true;
258 for (std::size_t c = 0; c < sn.nchains; ++c) {
260 for (std::size_t a = 0; a < sn.inchain[c].size(); ++a)
261 if (sn.inchain[c][a] == r + 1) holds =
true;
262 if (!holds)
continue;
263 for (std::size_t a = 0; a < sn.inchain[c].size(); ++a) {
264 const double nj = N[sn.inchain[c][a] - 1];
265 if (std::isfinite(nj))
271 tokbound[r] = finite ?
static_cast<std::size_t
>(chainpop)
272 : (r < cutoff.size() ? cutoff[r] : 0);
274 for (std::size_t f = 0; f < caps.size(); ++f) {
276 for (std::size_t r = 0; r < K; ++r)
277 if (caps[f].iswaitq[r]) s += tokbound[r];
279 caps[f].tokbound = tokbound;
321std::size_t max_row_width(
const NetworkStruct<T>& sn, std::size_t ind,
322 const std::vector<std::size_t>& cutoff) {
323 const std::size_t R = sn.nclasses;
324 const std::size_t ist = sn.nodes[ind - 1].station;
325 std::vector<std::size_t> ph(R, 1);
327 for (std::size_t r = 0; r < R; ++r) ph[r] = sn.phasessz_of(ist, r + 1);
332 if (ist == 0 || sn.stations[ist - 1].nodetype == NodeType::Source) {
335 throw UnsupportedError(ErrorKind{
"Model"},
"SolverCTMC: node '" + sn.nodes[ind - 1].name +
336 "' admits no state at all, so the WAITQ walk cannot start");
342 const std::vector<double> N = sn.njobs();
343 std::vector<std::size_t> bound(R, 0);
344 for (std::size_t r = 0; r < R; ++r) {
345 double b = std::isfinite(N[r]) ? N[r]
346 :
static_cast<double>(r < cutoff.size() ? cutoff[r] : 0);
347 const double cc = sn.classcap[ist - 1][r];
349 bound[r] = b > 0 ?
static_cast<std::size_t
>(b) : 0;
351 std::size_t total = 0;
352 for (std::size_t r = 0; r < R; ++r) total += bound[r];
353 const double tcap = sn.cap[ist - 1];
354 if (std::isfinite(tcap) && tcap <
static_cast<double>(total))
355 total = tcap > 0 ?
static_cast<std::size_t
>(tcap) : 0;
357 for (std::size_t t = total + 1; t-- > 0;) {
358 std::vector<std::size_t> n(R, 0);
359 std::size_t left = t;
360 for (std::size_t r = 0; r < R && left > 0; ++r) {
361 n[r] = std::min(left, bound[r]);
364 if (left > 0)
continue;
366 if (rows.empty())
continue;
372 const std::size_t percol = qn::state_detail::buffer_is_class_tag(sched) ? 1
373 : qn::state_detail::buffer_is_tag_phase_pairs(sched) ? 2 : 0;
376 if (holds_idle && percol > 0) {
377 std::size_t srvw = 0;
378 for (std::size_t r = 0; r < R; ++r) srvw += ph[r];
379 const std::size_t fixed = srvw + sn.nvars_of(ind);
380 const std::size_t bufw = rows[0].size() > fixed ? rows[0].size() - fixed : 0;
381 const std::size_t want = std::max<std::size_t>(t, 1) * percol;
382 if (want > bufw)
return rows[0].size() + (want - bufw);
384 return rows[0].size();
386 throw UnsupportedError(ErrorKind{
"Model"},
"SolverCTMC: station '" + sn.stations[ist - 1].name +
387 "' admits no state at all, so the WAITQ walk cannot start");
399NetState<T> wide_init_state(
const NetworkStruct<T>& sn,
400 const std::vector<std::size_t>& cutoff) {
402 if (!analyzer_detail::default_init_state(sn, init))
404 "SolverCTMC: the model's initial state admits no state at some node; check the class "
405 "populations against their reference stations");
406 for (std::size_t f = 0; f < sn.stateful_nodes.size() && f < init.local.size(); ++f) {
407 const std::size_t w = max_row_width(sn, sn.stateful_nodes[f], cutoff);
408 if (init.local[f].size() >= w)
continue;
409 init.local[f].insert(init.local[f].begin(), w - init.local[f].size(),
410 num_traits<T>::from_int(0));
426 std::vector<std::vector<std::size_t>> buf;
427 T w = num_traits<T>::from_int(0);
428 std::vector<std::pair<std::size_t, std::size_t>> arv;
429 std::size_t dep_isf = 0, dep_cls = 0;
431 std::size_t pcls = 0, pdest = 0;
434 bool admitted =
true;
441 std::vector<std::vector<std::size_t>> buf;
443 std::vector<std::pair<std::size_t, std::size_t>> arv;
444 std::size_t dep_isf = 0, dep_cls = 0;
445 std::size_t pf = 0, pcls = 0, pdest = 0;
447 bool admitted =
true;
448 std::vector<std::pair<std::size_t, std::size_t>> rel;
462 std::size_t sync = 0;
464 T w = num_traits<T>::from_int(0);
465 std::vector<std::pair<std::size_t, std::size_t>> arv;
466 std::size_t dep_isf = 0, dep_cls = 0;
474 bool admitted =
true;
475 std::vector<std::pair<std::size_t, std::size_t>> rel;
493void waitq_successors(
const NetworkStruct<T>& sn,
const std::vector<Sync<T>>& sync,
494 const std::vector<RegionCaps<T>>& caps,
const WaitqState<T>& ws,
495 std::vector<Successor<T>>& out) {
496 const std::size_t K = sn.nclasses;
497 const std::size_t F = caps.size();
498 const std::size_t local = sn.nodes.size() + 1;
499 const NetState<T>& net = ws.net;
500 const std::vector<std::vector<std::size_t>>& buf = ws.buf;
503 std::vector<std::vector<double>> xf(F);
504 for (std::size_t f = 0; f < F; ++f) xf[f] = region_aggr(sn, caps[f], net);
512 const bool sdr = sn.has_rtfun_routing();
524 const auto emit = [&](std::size_t a,
const Emission<T>& e) {
525 if (num_traits<T>::to_double(e.w) <= 0)
return;
526 std::deque<Work<T>> work;
530 w0.prob = num_traits<T>::from_int(1);
532 w0.dep_isf = e.dep_isf;
533 w0.dep_cls = e.dep_cls;
537 w0.pwaitq = e.pwaitq;
538 w0.admitted = e.admitted;
541 while (!work.empty()) {
542 const Work<T> it = work.front();
545 bool progressed =
false;
546 for (std::size_t f = 0; f < F && !progressed; ++f) {
547 if (it.buf[f].empty())
continue;
548 const std::size_t tok = it.buf[f][0];
549 const std::size_t dest = (tok - 1) / K + 1;
550 const std::size_t r = (tok - 1) % K + 1;
551 std::vector<double> x = region_aggr(sn, caps[f], it.net);
555 if (violates(caps[f], x))
continue;
556 const std::size_t isf_d = sn.stateful_index(dest);
557 if (isf_d == 0)
continue;
558 const qn::EventOutcome<T> od =
560 if (od.space.empty())
continue;
561 for (std::size_t
id = 0;
id < od.space.size(); ++id) {
562 if (num_traits<T>::to_double(od.prob[
id]) <= 0)
continue;
564 nx.net.local[isf_d - 1] = od.space[id];
565 nx.buf[f].erase(nx.buf[f].begin());
566 nx.prob = T(it.prob * od.prob[
id]);
567 nx.arv.push_back(std::make_pair(isf_d, r));
568 nx.rel.push_back(std::make_pair(dest, r));
573 if (progressed)
continue;
579 const std::size_t f = it.pf - 1;
580 std::vector<double> x = region_aggr(sn, caps[f], it.net);
581 x[it.pcls - 1] += 1.0;
585 if (violates(caps[f], x)) {
589 if (tok_full(caps[f], nx.buf[f], it.pcls, K))
continue;
590 nx.buf[f].push_back((it.pdest - 1) * K + it.pcls);
595 const std::size_t isf_d = sn.stateful_index(it.pdest);
596 bool admitted =
false;
599 sn, it.pdest, it.net.local[isf_d - 1], EventType::ARV, it.pcls);
600 for (std::size_t
id = 0;
id < od.space.size(); ++id) {
601 if (num_traits<T>::to_double(od.prob[
id]) <= 0)
continue;
603 ny.net.local[isf_d - 1] = od.space[id];
604 ny.prob = T(it.prob * od.prob[
id]);
605 ny.arv.push_back(std::make_pair(isf_d, it.pcls));
615 if (tok_full(caps[f], nx.buf[f], it.pcls, K))
continue;
616 nx.buf[f].push_back((it.pdest - 1) * K + it.pcls);
622 const T contrib = T(e.w * it.prob);
623 if (num_traits<T>::to_double(contrib) <= 0)
continue;
630 s.dep_isf = it.dep_isf;
631 s.dep_cls = it.dep_cls;
632 s.admitted = it.admitted;
638 for (std::size_t a = 0; a < sync.size(); ++a) {
639 const Sync<T>& sy = sync[a];
640 const std::size_t node_a = sy.active.node;
641 const std::size_t isf_a = sn.stateful_index(node_a);
642 if (isf_a == 0)
continue;
643 const std::size_t cls_a = sy.active.cls;
644 const std::size_t stat_a = sn.nodes[node_a - 1].station;
649 const qn::EventOutcome<T> oa =
650 qn::after_event(sn, node_a, net.local[isf_a - 1], sy.active.event, cls_a,
653 const bool rr_here = sy.active.event == EventType::DEP && sn.rr_var_slot(node_a, cls_a) != 0;
654 for (std::size_t ia = 0; ia < oa.space.size(); ++ia) {
656 const T rate = T(oa.rate[ia] * oa.prob[ia]);
657 if (num_traits<T>::to_double(rate) <= 0)
continue;
659 const std::size_t node_p = sy.passive.node;
660 if (node_p == local) {
663 e.net.local[isf_a - 1] = oa.space[ia];
669 const std::size_t isf_p = sn.stateful_index(node_p);
670 if (isf_p == 0)
continue;
671 const std::size_t cls_p = sy.passive.cls;
672 const std::size_t stat_p = sn.nodes[node_p - 1].station;
676 T proute = sy.passive.statedep ? rt_now(sy.passive.rt_row, sy.passive.rt_col) : sy.passive.prob;
678 const std::size_t nv = sn.nvars_of(node_a);
679 const std::vector<T>& arow = oa.space[ia];
680 std::size_t dest = 0;
681 if (arow.size() >= nv) {
682 const std::vector<T>
var(arow.end() - nv, arow.end());
683 dest = sn.rr_dest(node_a, cls_a, var);
685 proute = (dest == node_p && sy.passive.cls == cls_a) ? num_traits<T>::from_int(1)
686 : num_traits<T>::from_int(0);
688 const T w = T(rate * proute);
689 if (num_traits<T>::to_double(w) <= 0)
continue;
690 const std::size_t dep_isf = sy.active.event == EventType::DEP ? isf_a : 0;
695 std::size_t blockedf = 0, droppedf = 0;
696 if (sy.passive.event == EventType::ARV && stat_p != 0) {
697 for (std::size_t f = 0; f < F; ++f) {
698 if (!caps[f].member[stat_p - 1])
continue;
699 if (stat_a != 0 && caps[f].member[stat_a - 1])
continue;
700 std::vector<double> xn = xf[f];
701 xn[cls_p - 1] += 1.0;
702 if (!violates(caps[f], xn))
continue;
703 if (caps[f].iswaitq[cls_p - 1])
717 e.net.local[isf_a - 1] = oa.space[ia];
729 std::size_t switchf = 0;
730 if (blockedf == 0 && sy.passive.event == EventType::ARV && cls_p != cls_a &&
731 stat_a != 0 && stat_p != 0)
732 for (std::size_t f = 0; f < F; ++f)
733 if (caps[f].member[stat_a - 1] && caps[f].member[stat_p - 1]) {
741 e.net.local[isf_a - 1] = oa.space[ia];
749 e.pwaitq = caps[switchf - 1].iswaitq[cls_p - 1];
759 if (tok_full(caps[blockedf - 1], buf[blockedf - 1], cls_p, K))
continue;
762 e.net.local[isf_a - 1] = oa.space[ia];
764 e.buf[blockedf - 1].push_back((node_p - 1) * K + cls_p);
773 const std::vector<T>& psrc = node_p == node_a ? oa.space[ia] : net.local[isf_p - 1];
774 const qn::EventOutcome<T> op =
qn::after_event(sn, node_p, psrc, sy.passive.event, cls_p);
780 for (std::size_t ip = 0; ip < op.space.size(); ++ip) {
781 if (num_traits<T>::to_double(op.prob[ip]) <= 0)
continue;
784 e.net.local[isf_a - 1] = oa.space[ia];
785 e.net.local[isf_p - 1] = op.space[ip];
787 e.w = T(w * op.prob[ip]);
790 if (sy.passive.event == EventType::ARV)
791 e.arv.push_back(std::make_pair(isf_p, cls_p));
803 for (std::size_t f = 0; f <
sn.regions.size(); ++f)
804 for (std::size_t r = 0; r <
sn.regions[f].rule.size(); ++r)
805 if (
sn.regions[f].rule[r] != DropStrategy::DROP)
return true;
819 if (!
sn.transparam.empty())
821 "SolverCTMC: a WAITQ finite capacity region is not supported together with stochastic "
822 "Petri net transitions; a firing is atomic across its arcs and has no single "
823 "destination to park a refused token against");
830 for (std::size_t ind = 1; ind <=
sn.nodes.size(); ++ind) {
835 throw InputError(
"SolverCTMC: the WAITQ walk was handed station '" +
sn.nodes[ind - 1].name +
836 "', which declares " + what +
", without its CTMC station block; prepare "
837 "the struct with qn::ctmc_station_blocks first");
839 if (
sn.has_fork() || !
sn.fj.empty())
841 "SolverCTMC: a WAITQ finite capacity region is not supported together with fork-join; "
842 "a forked task refused entry would park without its siblings, and the join has no rule "
843 "for a sibling that never arrived");
844 for (std::size_t i = 0; i <
sn.nodes.size(); ++i) {
846 for (std::size_t r = 0; r < nd.
routing.size(); ++r) {
857 "SolverCTMC: a WAITQ finite capacity region is not supported together with the "
858 "routing strategy at node '" +
860 "'; the generator evaluates PROB, RAND, RROBIN, WRROBIN, SDR, JSQ and SQ routing only");
863 for (std::size_t f = 0; f <
sn.regions.size(); ++f)
864 for (std::size_t r = 0; r <
sn.regions[f].rule.size(); ++r) {
866 if (d == DropStrategy::DROP || d == DropStrategy::WAITQ)
continue;
868 "SolverCTMC: finite capacity region " + std::to_string(f + 1) +
869 " applies a blocking rule other than DROP or WAITQ to class " +
870 std::to_string(r + 1) +
871 "; BAS, BBS and RSRD hold the job AT ITS SERVER, which needs a blocked-server "
872 "marker column in the node state that this port does not allocate");
882 for (std::size_t i = 0; i <
sn.droprule.size() && i <
sn.stations.size(); ++i)
883 for (std::size_t r = 0; r <
sn.droprule[i].size(); ++r) {
885 if (d != DropStrategy::BAS && d != DropStrategy::BBS && d != DropStrategy::RSRD)
888 "SolverCTMC: station '" +
sn.stations[i].name +
889 "' applies true blocking (BAS/BBS/RSRD) to class " + std::to_string(r + 1) +
890 ", which holds the completing job at its server; this port allocates no "
891 "blocked-server marker in the node state, and voiding the departure instead would "
892 "let the server re-serve the same job and understate throughput");
908 const std::size_t K =
sn.nclasses;
909 const std::size_t NF =
sn.stateful_nodes.size();
912 const std::vector<Sync<T>> sync = refresh_sync(
sn);
913 std::vector<waitq_detail::RegionCaps<T>> caps = waitq_detail::extract_caps(
sn);
914 const std::size_t F = caps.size();
915 const std::vector<std::size_t> cutoff = analyzer_detail::resolve_cutoff(
sn,
opt);
916 waitq_detail::resolve_lmax(
sn, cutoff, caps);
923 init.
net = waitq_detail::wide_init_state(
sn, cutoff);
924 init.
buf.assign(F, std::vector<std::size_t>());
925 for (std::size_t f = 0; f < F; ++f)
926 if (waitq_detail::violates(caps[f], waitq_detail::region_aggr(
sn, caps[f], init.
net)))
928 "SolverCTMC: the initial state violates the constraints of finite capacity region " +
929 std::to_string(f + 1) +
"; the region cannot hold the model's initial population");
931 std::vector<WaitqState<T>> states;
932 states.push_back(init);
933 std::map<std::vector<double>, std::size_t> index;
934 index[waitq_detail::waitq_key(init)] = 0;
935 std::deque<std::size_t> frontier;
936 frontier.push_back(0);
941 std::vector<std::size_t> ta, ti, tj;
945 if constexpr (std::is_same<T, double>::value) collect =
opt.lal_collect.get();
946 std::vector<bool> tadm;
947 std::vector<std::vector<std::pair<std::size_t, std::size_t>>> trel;
948 std::vector<std::vector<std::vector<T>>> arv, dep;
949 arv.push_back(std::vector<std::vector<T>>(NF, std::vector<T>(K, zero)));
950 dep.push_back(std::vector<std::vector<T>>(NF, std::vector<T>(K, zero)));
954 const std::vector<double> key = waitq_detail::waitq_key(
ws);
955 const typename std::map<std::vector<double>, std::size_t>::const_iterator it =
957 if (it != index.end())
return it->second;
958 if (states.size() >=
opt.state_max)
960 "SolverCTMC: the WAITQ state space exceeds the cap of " +
961 std::to_string(
opt.state_max) +
962 " states; the region FIFO multiplies the space by its own occupancy");
963 states.push_back(
ws);
964 arv.push_back(std::vector<std::vector<T>>(NF, std::vector<T>(K, zero)));
965 dep.push_back(std::vector<std::vector<T>>(NF, std::vector<T>(K, zero)));
966 index[key] = states.size() - 1;
967 frontier.push_back(states.size() - 1);
968 return states.size() - 1;
976 std::vector<waitq_detail::Successor<T>> succ;
977 while (!frontier.empty()) {
978 const std::size_t s = frontier.front();
979 frontier.pop_front();
981 waitq_detail::waitq_successors(
sn, sync, caps,
ws, succ);
982 for (std::size_t e = 0; e < succ.size(); ++e) {
983 const waitq_detail::Successor<T>& su = succ[e];
984 const std::size_t dst = state_index(su.next);
985 ta.push_back(su.sync);
990 tadm.push_back(su.admitted);
991 trel.push_back(su.rel);
993 if (su.dep_isf != 0) dep[s][su.dep_isf - 1][su.dep_cls - 1] += su.w;
994 for (std::size_t q = 0; q < su.arv.size(); ++q)
995 arv[s][su.arv[q].first - 1][su.arv[q].second - 1] += su.w;
999 const std::size_t n = states.size();
1002 res.
chain.space.reserve(n);
1004 for (std::size_t s = 0; s < n; ++s) {
1005 res.
chain.space.push_back(states[s].net);
1006 res.
buf.push_back(states[s].buf);
1008 res.
chain.arv_rates = arv;
1009 res.
chain.dep_rates = dep;
1010 if (
opt.keep_filtration) res.
chain.filt.assign(sync.size(),
Matrix<T>(n, n, zero));
1011 for (std::size_t e = 0; e < tv.size(); ++e) {
1012 res.
chain.Q(ti[e], tj[e]) += tv[e];
1013 if (
opt.keep_filtration) res.
chain.filt[ta[e]](ti[e], tj[e]) += tv[e];
1022 if constexpr (std::is_same<T, double>::value) {
1024 std::map<std::tuple<std::size_t, bool, std::vector<std::pair<std::size_t, std::size_t>>>, std::size_t>
1028 const std::size_t local =
sn.nodes.size() + 1;
1029 for (std::size_t e = 0; e < tv.size(); ++e) {
1030 if (!(tv[e] > 0))
continue;
1031 const std::size_t a = ta[e];
1033 const bool parked = !tadm[e] && sync[a].passive.node != local;
1034 const auto key = std::make_tuple(a, parked, trel[e]);
1035 auto it = group.find(key);
1036 if (it == group.end()) {
1043 collect->
events.push_back(ev);
1044 it = group.emplace(key, collect->
events.size() - 1).first;
1046 collect->
events[it->second].arcs.push_back(std::make_tuple(ti[e], tj[e], tv[e]));
1048 collect->
sn = std::make_shared<const NetworkStruct<double>>(
sn);
1051 collect->
sync = sync;
1052 collect->
gsync.clear();
1074 const std::vector<T>& pi) {
1075 const std::size_t K =
sn.nclasses;
1077 for (std::size_t s = 0; s < r.
buf.size() && s < pi.size(); ++s)
1078 for (std::size_t f = 0; f < r.
buf[s].size(); ++f)
1079 for (std::size_t j = 0; j < r.
buf[s][f].size(); ++j) {
1080 const std::size_t cls = (r.
buf[s][f][j] - 1) % K + 1;
1081 out[cls - 1] += pi[s];
1090 std::vector<std::vector<std::vector<std::size_t>>>
buf;
1113 bool blk_reach =
false;
1116 if (blk) out.
sol.solved_sn = std::make_shared<const NetworkStruct<T>>(sn_blk);
1118 out.
sol.cutoff = analyzer_detail::resolve_cutoff(sw,
opt);
1120 if (
opt.lal_collect &&
opt.lal_collect->filled &&
opt.lal_collect->stop)
return out;
1125 out.
sol.chain = r.chain;
1126 out.
sol.actualmethod =
opt.method;
1136 std::vector<std::vector<std::vector<std::size_t>>>
buf;
1199#define LINE_SOLVERS_CTMC_SOLVER_CTMC_WAITQ_DONE
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
Steady-state distribution of a continuous-time Markov chain.
Port of matlab/src/solvers/CTMC/ctmc_stationary.m: the single entry point for the stationary distribu...
The exception types the port throws.
FES rates from a non-product-form solve of the isolated subnetwork.
Dense matrix and non-owning view.
CtmcSolution< T > solver_ctmc_analyzer(const NetworkStruct< T > &sn_in, const CtmcOptions &opt, const CtmcStationaryHook< T > &stationary=CtmcStationaryHook< T >())
Port of solver_ctmc_analyzer.m plus the fork-join wrapper of @@SolverCTMC/runAnalyzer....
void check_method(const std::string &method)
Port of runAnalyzerChecks' method gate.
void ctmc_check_support(const NetworkStruct< T > &sn)
void make_infgen(Matrix< T > &Q)
Port of ctmc_makeinfgen: turn an off-diagonal rate matrix into a generator.
mva::AvgResult< T > solver_ctmc_avg_table(const NetworkStruct< T > &sn, const CtmcSolution< T > &d, const std::string &method)
Port of @@SolverCTMC/runAnalyzer.m's result assembly: solve, then apply the metric filter @@NetworkSo...
CtmcAvg< T > solver_ctmc_avg_from_pi(const NetworkStruct< T > &sn, const CtmcResult< T > &r, const std::vector< T > &pivec, bool stationary=true)
Port of solver_ctmc_avg_from_pi: map a state distribution to mean metrics.
CtmcAnySolution< T > solver_ctmc_analyzer_any(const NetworkStruct< T > &sn, const CtmcOptions &opt)
The entry point a caller who does not know which path a model needs should use: pick the WAITQ walk w...
CtmcStationaryResult< T > ctmc_stationary(const Matrix< T > &Q, std::size_t init_index=static_cast< std::size_t >(-1))
std::vector< T > ctmc_waitq_parked(const NetworkStruct< T > &sn, const WaitqResult< T > &r, const std::vector< T > &pi)
The mean number of parked jobs per class, over a stationary law.
WaitqSolution< T > solver_ctmc_waitq_analyzer(const NetworkStruct< T > &sn, const CtmcOptions &opt)
Build the WAITQ chain, solve it, and map it onto the same means every other CTMC path reports.
WaitqResult< T > solver_ctmc_waitq(const NetworkStruct< T > &sn, const CtmcOptions &opt)
Port of the reachability walk of solver_ctmc_fcr_waitq.m.
bool ctmc_has_waitq_region(const NetworkStruct< T > &sn)
True when the model declares a region that applies anything other than DROP.
mva::AvgResult< T > solver_ctmc_run_analyzer_any(const NetworkStruct< T > &sn, const CtmcOptions &opt)
Solve on whichever path applies and format, mirroring solver_ctmc_run_analyzer.
void ctmc_check_waitq_support(const NetworkStruct< T > &sn)
The combinations the reference gates, plus the two this port cannot represent.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
DropStrategy
Blocking and loss rules, with the values of MATLAB DropStrategy.
RoutingStrategy
Routing strategies, with the values of MATLAB RoutingStrategy.
@ SDR
Krzesinski (1987) product-form state-dependent routing.
double var(const std::vector< double > &x)
Sample variance with the n - 1 denominator.
std::vector< std::vector< T > > from_marginal_node(const NetworkStruct< T > &sn, std::size_t ind, const std::vector< std::size_t > &n, const std::vector< std::size_t > &phases)
Port of State.fromMarginal at its OWN signature: the reference indexes by NODE, not by station,...
bool from_marginal_node_first(const NetworkStruct< T > &sn, std::size_t ind, const std::vector< std::size_t > &n, const std::vector< std::size_t > &phases, std::vector< T > &out)
The FIRST row from_marginal_node emits, BUILT rather than enumerated.
bool immfeed_self_loop(const NetworkStruct< T > &sn, const Sync< T > &sy)
True when a synchronization is an IMMEDIATE-FEEDBACK SELF-LOOP: a departure whose passive half is an ...
AttemptsLayout attempts_layout(const NetworkStruct< T > &sn, std::size_t ind)
The finite-attempt retrial of node ind as the model declares it, active or not.
FeatureSet ctmc_feature_set(const std::string &method)
SolverCTMC.getFeatureSet, the reference's 104 MATLAB names in full.
SetupInfo< T > setup_layout(const NetworkStruct< T > &sn, std::size_t ind)
The setup/delay-off layout of node ind as the model declares it, whether or not the block is active.
bool ctmc_station_blocks(const NetworkStruct< T > &in, NetworkStruct< T > &out, bool &reachable)
Prepare the copy SolverCTMC solves: validate the setup/delay-off, finite-attempt and server-paralleli...
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::vector< double > parallelism_of(const NetworkStruct< T > &sn, std::size_t ind)
Per-class server degrees n_r (all >= 1) of node ind, or empty when every class seizes one server (pyt...
void feature_gate(const std::string &solver, const FeatureSet &declared, const NetworkStruct< T > &sn, const std::string &requested_method="", const std::string &resolved_method="")
runAnalyzerChecks: refuse a model the solver does not declare, by name.
std::pair< T, std::vector< T > > to_marginal_aggr(const NetworkStruct< T > &sn, std::size_t ind, const std::vector< T > &state_i)
Port of State.toMarginalAggr: the job counts of one node's state row, without the per-phase detail to...
std::size_t ctmc_tail_width(const NetworkStruct< T > &sn, std::size_t ind)
Width of the CTMC station block of node ind (1-based), 0 when it has none.
Matrix< T > rt_state(const NetworkStruct< T > &sn, const std::vector< std::vector< T > > &local)
Port of sn.rtfun: the routing over the stateful nodes AT ONE STATE.
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
Port of solver_ctmc.m: the infinitesimal generator of a queueing network, assembled from the enumerat...
Port of solver_ctmc_analyzer.m and the parts of @@SolverCTMC/runAnalyzer.m that surround one solve: t...
Finite Capacity Regions in SolverCTMC: the DROP rule, as a filter on the enumerated state space,...
The DECLARED side of the gate: one feature set per solver.
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....
A CTMC solve routed to whichever path the model's region rules require.
std::vector< T > parked
mean parked jobs per class; empty off the WAITQ path
std::vector< std::vector< std::vector< std::size_t > > > buf
empty off the WAITQ path
The SolverCTMC knobs this port honours.
The generator, the state space it is indexed by, and the event rates.
Everything one CTMC solve produces.
The internal collect sink of the LAL embedding (python options.collect).
std::vector< qn::Sync< double > > sync
std::size_t initial_index
std::vector< LalCollectedEvent > events
std::shared_ptr< const qn::NetworkStruct< double > > sn
std::vector< std::vector< std::vector< std::size_t > > > buf
The region FIFOs of each state, per region (WaitqState::buf), when the chain is the WAITQ region walk...
std::vector< qn::FjSync< double > > fjsync
std::vector< qn::GlobalSync< double > > gsync
std::vector< qn::NetState< double > > space
std::vector< std::size_t > vanishing
One per-event arc set collected for the LAL embedding of a Network.
bool parked
Region records of a Sync event built by the WAITQ region walk (solver_ctmc_waitq, python RegionArriva...
std::vector< std::pair< std::size_t, std::size_t > > released
The chain the WAITQ walk produces, alongside the FIFOs its states carry.
std::vector< std::vector< std::vector< std::size_t > > > buf
per state, per region
CtmcResult< T > chain
Q, the net halves, rates, filt.
A solved WAITQ model: the usual CTMC solution, plus what the FIFOs hold.
std::vector< std::vector< std::vector< std::size_t > > > buf
std::vector< T > parked
mean parked jobs per class
One augmented state: the network state, plus the token FIFO of every region.
std::vector< std::vector< std::size_t > > buf
The metrics getAvg returns, after filtering.
One network state: the per-stateful-node local rows it is composed of.
std::vector< RoutingStrategy > routing
sn.routing, per class.