5#ifndef LINE_SOLVERS_CTMC_SOLVER_CTMC_ANALYZER_H
6#define LINE_SOLVERS_CTMC_SOLVER_CTMC_ANALYZER_H
238 return {
"default",
"exact",
"gpu",
"mdd",
"cftp",
"cftp.approx"};
243 return method ==
"mdd" || method ==
"cftp" || method ==
"cftp.approx";
266 if (std::find(valid.begin(), valid.end(), method) == valid.end())
268 "' method is unsupported by this solver");
271 "' method does not enumerate a state space and is served by its "
272 "own analyzer, not by solver_ctmc_analyzer");
277 if (method !=
"gpu")
return std::string();
278 return "ctmc_solve: GPU either not available or execution failed. Switching to default "
308 if (
sn.has_immediate_feedback())
310 "SolverCTMC: immediate feedback (setImmediateFeedback) is not ported. The reference "
311 "keeps the server across the fed-back service through State.afterEvent's immfeed "
312 "self-loop, which this port's event generator has no arc for, so the chain would "
313 "release and re-queue the job instead; use SolverMVA or SolverNC, which warn and "
322 if (
sn.has_breakdown())
324 "SolverCTMC: server breakdowns (setBreakdown) are not ported. The reference carries "
325 "the up/down status in the station's trailing local-state column and fires FAILURE "
326 "and REPAIR against it (State.afterEventStation); this port allocates that column for "
327 "a cache, a polling controller or the BAS blocked marker only, so the chain would be "
328 "built as though the server never failed; use SolverLDES, whose native engine "
329 "simulates the outage");
336 for (std::size_t i = 0; i <
sn.stations.size(); ++i) {
337 if (
sn.stations[i].cdscaling &&
sn.stations[i].cdscalingpeak.empty())
339 "SolverCTMC: station '" +
sn.stations[i].name +
340 "' declares class-dependent service without a peak rate. Utilization at a "
341 "class-dependent station is reported as T/mu/peak, so pass the peak to "
342 "setClassDependence");
343 if (
sn.stations[i].jdscaling &&
sn.stations[i].jdscalingpeak.empty())
345 "SolverCTMC: station '" +
sn.stations[i].name +
346 "' declares joint-dependent service without a peak rate; pass the peak to "
347 "setJointDependence");
369namespace analyzer_detail {
387std::vector<std::size_t> resolve_cutoff(
const NetworkStruct<T>&
sn,
const CtmcOptions&
opt) {
388 const std::size_t M =
sn.nstations, K =
sn.nclasses;
389 std::vector<std::size_t> cut(K, 0);
390 bool any_open =
false;
391 for (std::size_t k = 0; k < K; ++k)
392 if (!std::isfinite(
sn.njobs()[k])) any_open =
true;
393 if (!any_open)
return cut;
395 if (!
opt.cutoff_mat.empty()) {
399 if (
opt.cutoff_mat.size() != M)
400 throw InputError(
"SolverCTMC: the cutoff matrix must have one row per station");
401 for (std::size_t k = 0; k < K; ++k) {
402 if (std::isfinite(
sn.njobs()[k]))
continue;
403 for (std::size_t i = 0; i < M; ++i) {
404 if (
opt.cutoff_mat[i].size() != K)
406 "SolverCTMC: the cutoff matrix must have one column per class");
407 cut[k] = std::max(cut[k],
opt.cutoff_mat[i][k]);
412 if (!opt.cutoff_vec.empty()) {
413 if (opt.cutoff_vec.size() != K)
414 throw InputError(
"SolverCTMC: the per-class cutoff must have one entry per class");
415 return opt.cutoff_vec;
418 if (opt.cutoff > 0 && std::isfinite(opt.cutoff)) {
419 c =
static_cast<std::size_t
>(opt.cutoff);
420 }
else if (opt.cutoff < 0) {
423 const double e = 1.0 /
static_cast<double>(M * K);
424 c =
static_cast<std::size_t
>(std::ceil(std::pow(6000.0, e)));
427 for (std::size_t k = 0; k < K; ++k)
428 if (!std::isfinite(sn.njobs()[k])) cut[k] = c;
445bool set_retrieval_truncation(
const NetworkStruct<T>& sn,
const std::vector<std::size_t>& cutoff,
446 NetworkStruct<T>& out) {
448 for (
typename std::map<std::size_t, qn::CacheParam<T>>::const_iterator ci =
449 sn.nodeparam.begin();
450 ci != sn.nodeparam.end(); ++ci)
451 if (ci->second.retrieval_capacity > 0 && !ci->second.retrieval_classes.empty()) any =
true;
452 if (!any)
return false;
454 if (sn.nclosedjobs() > 0) {
455 lvl =
static_cast<long>(sn.nclosedjobs()) - 1;
458 for (std::size_t k = 0; k < cutoff.size(); ++k) mx = std::max(mx, cutoff[k]);
459 lvl =
static_cast<long>(mx) - 1;
461 if (lvl < 0) lvl = 0;
463 for (
typename std::map<std::size_t, qn::CacheParam<T>>::iterator ci = out.nodeparam.begin();
464 ci != out.nodeparam.end(); ++ci)
465 if (ci->second.retrieval_capacity > 0) ci->second.max_pending_retrieval = lvl;
493bool annihilate_signal_capacity(
const NetworkStruct<T>& sn, NetworkStruct<T>& out) {
494 std::vector<bool> annihilated(sn.nclasses,
false);
496 for (std::size_t k = 0; k < sn.nclasses && k < sn.issignal.size(); ++k) {
497 if (!sn.issignal[k])
continue;
499 annihilated[k] =
true;
502 if (!any)
return false;
504 for (std::size_t i = 0; i < out.stations.size() && i < out.classcap.size(); ++i) {
507 if (out.stations[i].sched == SchedStrategy::EXT)
continue;
508 for (std::size_t k = 0; k < annihilated.size() && k < out.classcap[i].size(); ++k)
509 if (annihilated[k]) out.classcap[i][k] = 0.0;
538solvers::CacheMetrics<T> cache_metrics(
const NetworkStruct<T>& sn,
const CtmcResult<T>& r,
539 const std::vector<T>& pi) {
540 solvers::CacheMetrics<T> out =
542 std::vector<T>(), Matrix<T>(), Matrix<T>(), std::vector<T>());
543 if (out.caches.empty() || r.space.empty())
return out;
544 const std::size_t K = sn.nclasses, ns = r.space.size();
545 const double dnan = std::numeric_limits<double>::quiet_NaN();
547 for (std::size_t c = 0; c < out.caches.size(); ++c) {
548 solvers::CacheNodeMetrics<T>& m = out.caches[c];
549 const std::size_t isf = sn.stateful_index(m.node);
550 if (isf == 0)
continue;
551 const qn::CacheParam<T>& cp = sn.nodeparam.find(m.node)->second;
553 std::vector<double> tn(K, 0.0);
554 for (std::size_t s = 0; s < ns && s < pi.size(); ++s) {
555 const double p = num_traits<T>::to_double(pi[s]);
556 if (p == 0)
continue;
557 if (isf - 1 >= r.dep_rates[s].size())
continue;
558 for (std::size_t k = 0; k < K && k < r.dep_rates[s][isf - 1].size(); ++k)
559 tn[k] += p * num_traits<T>::to_double(r.dep_rates[s][isf - 1][k]);
562 const std::size_t n = cp.nitems;
564 for (std::size_t l = 0; l < cp.itemcap.size(); ++l)
565 if (cp.itemcap[l] > 0) tcc +=
static_cast<std::size_t
>(cp.itemcap[l]);
566 std::vector<std::size_t> rcl, rci, rco;
568 const std::size_t lvw = r.space[0].local[isf - 1].size();
569 const bool retr = !rcl.empty() && lvw >= tcc + n + rcl.size();
570 std::vector<double> drate(K, 0.0);
579 const std::size_t tail = cp.retrieval_capacity > 0 ? n + rcl.size() : 0;
580 if (n > 0 && tcc > 0 && lvw >= tcc + tail) {
581 const std::size_t coff = lvw - (tcc + tail);
582 const std::size_t h = cp.itemcap.size();
583 Matrix<T> ip(n, h + 1);
584 std::vector<double> acc(n * h, 0.0);
585 std::vector<char> present(n, 0);
586 for (std::size_t s = 0; s < ns && s < pi.size(); ++s) {
587 const double p = num_traits<T>::to_double(pi[s]);
588 if (p == 0)
continue;
589 const std::vector<T>& lv = r.space[s].local[isf - 1];
590 std::size_t off = coff;
591 for (std::size_t l = 0; l < h; ++l) {
592 const std::size_t cap =
593 cp.itemcap[l] > 0 ?
static_cast<std::size_t
>(cp.itemcap[l]) : 0;
594 std::fill(present.begin(), present.end(), 0);
595 for (std::size_t q = 0; q < cap; ++q) {
596 const long it =
static_cast<long>(num_traits<T>::to_double(lv[off + q]));
597 if (it >= 1 &&
static_cast<std::size_t
>(it) <= n)
598 present[
static_cast<std::size_t
>(it) - 1] = 1;
600 for (std::size_t i = 0; i < n; ++i)
601 if (present[i]) acc[i * h + l] += p;
605 for (std::size_t i = 0; i < n; ++i) {
607 for (std::size_t l = 0; l < h; ++l) {
608 const double v = acc[i * h + l];
609 ip(i, l + 1) = num_traits<T>::from_double(v);
612 ip(i, 0) = num_traits<T>::from_double(miss);
618 const std::size_t aoff = lvw - (n + rcl.size()), boff = aoff + n;
619 std::vector<double> phi(n, 0.0), d1(n, 0.0);
620 for (std::size_t s = 0; s < ns && s < pi.size(); ++s) {
621 const double p = num_traits<T>::to_double(pi[s]);
622 if (p == 0)
continue;
623 const std::vector<T>& lv = r.space[s].local[isf - 1];
624 for (std::size_t i = 0; i < n; ++i)
625 if (num_traits<T>::to_double(lv[aoff + i]) != 0) phi[i] += p;
626 for (std::size_t j = 0; j < rcl.size(); ++j)
627 d1[rci[j] - 1] += p * num_traits<T>::to_double(lv[boff + j]);
629 m.delayedhitqlen.assign(n, num_traits<T>::from_int(0));
630 m.delayedhitqlenfull.assign(n, num_traits<T>::from_int(0));
631 for (std::size_t i = 0; i < n; ++i) {
632 m.delayedhitqlen[i] = num_traits<T>::from_double(d1[i]);
633 m.delayedhitqlenfull[i] = num_traits<T>::from_double(d1[i] + phi[i]);
635 for (std::size_t s = 0; s < ns && s < pi.size(); ++s) {
636 const double p = num_traits<T>::to_double(pi[s]);
637 if (p == 0)
continue;
638 const std::vector<T>& lv = r.space[s].local[isf - 1];
639 for (std::size_t j = 0; j < rcl.size(); ++j) {
640 const std::size_t i = rci[j] - 1;
641 const double held = num_traits<T>::to_double(lv[boff + j]);
642 if (held <= 0 || num_traits<T>::to_double(lv[aoff + i]) == 0)
continue;
643 double completes = 0.0;
644 for (std::size_t b = 0; b < ns; ++b) {
645 if (b == s)
continue;
646 const double q = num_traits<T>::to_double(r.Q(s, b));
647 if (q == 0)
continue;
648 if (num_traits<T>::to_double(r.space[b].local[isf - 1][aoff + i]) == 0)
651 if (rco[j] - 1 < K) drate[rco[j] - 1] += p * held * completes;
656 m.hitprob.assign(K, num_traits<T>::from_double(dnan));
657 m.missprob.assign(K, num_traits<T>::from_double(dnan));
658 if (retr) m.delayedprob.assign(K, num_traits<T>::from_double(dnan));
659 for (std::size_t k = 0; k < K; ++k) {
660 if (k >= cp.hitclass.size() || k >= cp.missclass.size())
continue;
661 const std::size_t h = cp.hitclass[k], mi = cp.missclass[k];
662 if (h == 0 || mi == 0 || h > K || mi > K)
continue;
663 const double denom = tn[h - 1] + tn[mi - 1];
664 if (denom <= 0)
continue;
668 const double d = retr ? std::min(drate[k], tn[h - 1]) : 0.0;
669 m.hitprob[k] = num_traits<T>::from_double((tn[h - 1] - d) / denom);
670 m.missprob[k] = num_traits<T>::from_double(tn[mi - 1] / denom);
671 if (retr) m.delayedprob[k] = num_traits<T>::from_double(d / denom);
698void strip_reference_source_column(
const NetworkStruct<T>& sn, std::size_t ind,
699 std::vector<T>& row) {
700 const std::size_t ist = sn.nodes[ind - 1].station;
701 if (ist == 0 || ist > sn.stations.size())
return;
702 if (sn.stations[ist - 1].nodetype != NodeType::Source &&
703 sn.stations[ist - 1].sched != SchedStrategy::EXT)
706 for (std::size_t r = 0; r < sn.nclasses; ++r) w += sn.phasessz_of(ist, r + 1);
710 if (row.size() == w + 1) row.erase(row.begin());
725bool default_init_state(
const NetworkStruct<T>& sn, NetState<T>& init) {
726 const std::size_t R = sn.nclasses;
727 const std::vector<std::size_t>& sfn = sn.stateful_nodes;
728 init.local.assign(sfn.size(), std::vector<T>());
729 for (std::size_t f = 0; f < sfn.size(); ++f) {
730 const std::size_t ind = sfn[f];
739 const typename std::map<std::size_t, Matrix<T>>::const_iterator sp =
740 sn.statespace.find(ind);
741 if (sp != sn.statespace.end() && sp->second.rows() == 1 && sp->second.cols() > 0) {
742 std::vector<T> row(sp->second.cols());
743 for (std::size_t c = 0; c < sp->second.cols(); ++c) row[c] = sp->second(0, c);
744 strip_reference_source_column(sn, ind, row);
758 std::vector<std::size_t> marg(R, 0), mph(R, 1);
759 const std::size_t mist = sn.nodes[ind - 1].station;
760 bool rebuilt =
false;
761 if (row.size() == R && mist != 0) {
762 for (std::size_t r = 0; r < R; ++r) {
763 const double v = num_traits<T>::to_double(row[r]);
764 marg[r] = v > 0.0 ?
static_cast<std::size_t
>(v + 0.5) : 0;
765 mph[r] = sn.phasessz_of(mist, r + 1);
767 std::vector<T> built;
769 init.local[f] = built;
773 if (!rebuilt) init.local[f] = row;
776 const std::size_t ist = sn.nodes[ind - 1].station;
777 std::vector<std::size_t> nmarg(R, 0), ph(R, 1);
779 for (std::size_t r = 0; r < R; ++r) ph[r] = sn.phasessz_of(ist, r + 1);
780 if (sn.stations[ist - 1].nodetype == NodeType::Source) {
788 for (std::size_t r = 0; r < R; ++r)
789 if (!sn.disabled[ist - 1][r]) nmarg[r] = 1;
791 for (std::size_t r = 0; r < R; ++r) {
792 const double nj = sn.njobs()[r];
793 if (std::isfinite(nj) && sn.classes[r].refstat == ist)
794 nmarg[r] =
static_cast<std::size_t
>(nj);
805 for (std::size_t r = 0; r < R; ++r) {
807 if (m0 > nmarg[r]) nmarg[r] = m0;
818std::size_t init_state_index(
const NetworkStruct<T>& sn,
const std::vector<NetState<T>>& space) {
819 const std::size_t npos =
static_cast<std::size_t
>(-1);
820 if (space.empty())
return npos;
822 if (!default_init_state(sn, init))
return npos;
823 for (std::size_t f = 0; f < init.local.size(); ++f) {
826 const std::size_t w = space[0].local[f].size();
827 if (init.local[f].size() > w)
return npos;
828 if (init.local[f].size() < w)
829 init.local[f].insert(init.local[f].begin(), w - init.local[f].size(),
830 num_traits<T>::from_int(0));
832 const std::vector<double> key = ctmc_detail::state_key(init);
833 for (std::size_t s = 0; s < space.size(); ++s)
834 if (ctmc_detail::state_key(space[s]) == key)
return s;
858bool init_state_distribution(
const NetworkStruct<T>& sn,
const std::vector<NetState<T>>& space,
859 std::vector<T>& pi0) {
860 const std::size_t npos =
static_cast<std::size_t
>(-1);
861 pi0.assign(space.size(), num_traits<T>::from_int(0));
862 if (space.empty())
return false;
864 if (!default_init_state(sn, base))
return false;
865 const std::vector<std::size_t>& sfn = sn.stateful_nodes;
869 std::vector<std::vector<std::vector<T>>> rows(sfn.size());
870 std::vector<std::vector<double>> wts(sfn.size());
871 for (std::size_t f = 0; f < sfn.size(); ++f) {
872 const typename std::map<std::size_t, Matrix<T>>::const_iterator ss =
873 sn.statespace.find(sfn[f]);
874 const typename std::map<std::size_t, std::vector<T>>::const_iterator sp =
875 sn.stateprior.find(sfn[f]);
876 if (ss == sn.statespace.end() || sp == sn.stateprior.end() || ss->second.rows() == 0 ||
877 ss->second.rows() != sp->second.size()) {
878 rows[f].push_back(base.local[f]);
879 wts[f].push_back(1.0);
882 for (std::size_t r = 0; r < ss->second.rows(); ++r) {
883 const double w = num_traits<T>::to_double(sp->second[r]);
884 if (!(w > 0.0))
continue;
885 std::vector<T> row(ss->second.cols());
886 for (std::size_t c = 0; c < ss->second.cols(); ++c) row[c] = ss->second(r, c);
887 strip_reference_source_column(sn, sfn[f], row);
888 rows[f].push_back(row);
891 if (rows[f].empty())
return false;
894 std::vector<std::size_t> pick(sfn.size(), 0);
897 NetState<T> cand = base;
899 for (std::size_t f = 0; f < sfn.size(); ++f) {
900 cand.local[f] = rows[f][pick[f]];
901 w *= wts[f][pick[f]];
904 const std::size_t wd = space[0].local[f].size();
905 if (cand.local[f].size() > wd)
return false;
906 if (cand.local[f].size() < wd)
907 cand.local[f].insert(cand.local[f].begin(), wd - cand.local[f].size(),
908 num_traits<T>::from_int(0));
910 std::size_t idx = npos;
911 const std::vector<double> key = ctmc_detail::state_key(cand);
912 for (std::size_t s = 0; s < space.size() && idx == npos; ++s)
913 if (ctmc_detail::state_key(space[s]) == key) idx = s;
914 if (idx == npos)
return false;
915 pi0[idx] = T(pi0[idx] + num_traits<T>::from_double(w));
919 for (; f < sfn.size(); ++f) {
920 if (++pick[f] < rows[f].size())
break;
923 if (f == sfn.size())
break;
925 if (!(total > 0.0))
return false;
935std::vector<std::size_t> weak_components(
const Matrix<T>& Q, std::size_t& ncomp) {
936 const std::size_t n = Q.rows();
937 const std::size_t npos =
static_cast<std::size_t
>(-1);
938 std::vector<std::size_t> comp(n, npos);
940 for (std::size_t s = 0; s < n; ++s) {
941 if (comp[s] != npos)
continue;
942 std::vector<std::size_t> stack{s};
944 while (!stack.empty()) {
945 const std::size_t u = stack.back();
947 for (std::size_t v = 0; v < n; ++v) {
948 if (comp[v] != npos)
continue;
951 if (v == u)
continue;
952 if (num_traits<T>::to_double(Q(u, v)) != 0 ||
953 num_traits<T>::to_double(Q(v, u)) != 0) {
966CtmcResult<T> restrict_to(
const CtmcResult<T>& r,
const std::vector<std::size_t>& wset) {
968 out.Q =
Matrix<T>(wset.size(), wset.size(), num_traits<T>::from_int(0));
969 for (std::size_t a = 0; a < wset.size(); ++a)
970 for (std::size_t b = 0; b < wset.size(); ++b) out.Q(a, b) = r.Q(wset[a], wset[b]);
971 out.space.reserve(wset.size());
972 out.arv_rates.reserve(wset.size());
973 out.dep_rates.reserve(wset.size());
974 for (std::size_t a = 0; a < wset.size(); ++a) {
975 out.space.push_back(r.space[wset[a]]);
976 out.arv_rates.push_back(r.arv_rates[wset[a]]);
977 out.dep_rates.push_back(r.dep_rates[wset[a]]);
983 out.filt.reserve(r.filt.size());
984 for (std::size_t f = 0; f < r.filt.size(); ++f) {
985 Matrix<T> F(wset.size(), wset.size(), num_traits<T>::from_int(0));
986 for (std::size_t a = 0; a < wset.size(); ++a)
987 for (std::size_t b = 0; b < wset.size(); ++b) F(a, b) = r.filt[f](wset[a], wset[b]);
988 out.filt.push_back(F);
1015 out.
cutoff = analyzer_detail::resolve_cutoff(sn_in,
opt);
1019 const bool retr = analyzer_detail::set_retrieval_truncation(sn_in, out.
cutoff, sn_trunc);
1025 const bool sig = analyzer_detail::annihilate_signal_capacity(sn_r, sn_sig);
1043 const std::vector<Sync<T>> sync = refresh_sync(
sn);
1044 const std::vector<qn::GlobalSync<T>> gsync = refresh_global_sync(
sn);
1060 std::vector<NetState<T>> space;
1061 if (!gsync.empty() || !fjsync.empty()) {
1063 if (!analyzer_detail::default_init_state(
sn, init))
1065 "SolverCTMC: the model's initial marking admits no state; check the Place "
1066 "populations against the class reference stations");
1073 space = space_generator(
sn, out.
cutoff,
opt.state_max,
opt.cutoff_mat);
1077 "SolverCTMC: the state space is empty; no state satisfies the model's capacities");
1094 const std::size_t npos =
static_cast<std::size_t
>(-1);
1097 std::size_t init = analyzer_detail::init_state_index(
sn, r.
space);
1099 std::size_t ncomp = 0;
1100 const std::vector<std::size_t> comp = analyzer_detail::weak_components(r.
Q, ncomp);
1109 std::vector<std::size_t> sizes(ncomp, 0);
1110 for (std::size_t s = 0; s < comp.size(); ++s) ++sizes[comp[s]];
1111 pick =
static_cast<std::size_t
>(
1112 std::max_element(sizes.begin(), sizes.end()) - sizes.begin());
1114 std::vector<std::size_t> wset;
1115 for (std::size_t s = 0; s < comp.size(); ++s)
1116 if (comp[s] == pick) wset.push_back(s);
1119 std::size_t moved = npos;
1121 for (std::size_t k = 0; k < wset.size(); ++k)
1122 if (wset[k] == init) {
1127 r = analyzer_detail::restrict_to(r, wset);
1137 static_cast<std::size_t
>(r.
Q.rows()));
1150 out.
cache = analyzer_detail::cache_metrics(
sn, r, out.
pi);
1234 const std::string& method) {
1235 const std::size_t M =
sn.nstations, K =
sn.nclasses;
1237 std::vector<std::vector<bool>> srcmask(M, std::vector<bool>(K,
false));
1238 for (std::size_t i = 0; i < M; ++i)
1239 if (
sn.stations[i].nodetype == NodeType::Source)
1240 for (std::size_t k = 0; k < K; ++k) srcmask[i][k] =
true;
1286 sub.chain_aggregation =
false;
1305 sub.load_concealment =
false;
1309 opt.method,
opt.transform_iter_max);
1337 const std::size_t M =
sn.nstations, K =
sn.nclasses;
1338 const std::vector<std::size_t>& subset =
opt.fes_stations;
1339 if (subset.size() < 2)
1341 "options.config.fes_stations must name at least two stations: collapsing one "
1342 "station into a flow-equivalent server saves nothing.");
1343 if (subset.size() >= M)
1345 "options.config.fes_stations names every station: there is no complement left "
1347 for (std::size_t i : subset)
1349 throw InputError(
"options.config.fes_stations must be 1-based station indices in 1.." +
1350 std::to_string(M) +
".");
1357 sub.fes_stations.clear();
1364 const std::size_t fesIst = snRed.
nodes[info.
fesNode - 1].station;
1365 std::size_t tableSize = 1;
1366 for (
int c : info.
cutoffs) tableSize *=
static_cast<std::size_t
>(c + 1);
1367 std::vector<double> Pn(tableSize, 0.0);
1368 for (std::size_t r = 0; r < SSq.
rows(); ++r) {
1369 std::vector<int> nvec(K, 0);
1370 for (std::size_t k = 0; k < K; ++k)
1371 nvec[k] =
static_cast<int>(
1389 for (std::size_t k = 0; k < K; ++k) {
1390 out.
QN(i, k) = redAvg.
QN(a, k);
1391 out.
UN(i, k) = redAvg.
UN(a, k);
1392 out.
TN(i, k) = redAvg.
TN(a, k);
1397 Matrix<T> Qsub(Msub, K, zero), Usub(Msub, K, zero);
1398 for (std::size_t idx = 0; idx < tableSize; ++idx) {
1399 if (!(Pn[idx] > 0.0))
continue;
1401 for (std::size_t a = 0; a < Msub && a < cm.
QN[idx].rows(); ++a)
1402 for (std::size_t k = 0; k < K; ++k) {
1403 Qsub(a, k) += T(w * cm.
QN[idx](a, k));
1404 Usub(a, k) += T(w * cm.
UN[idx](a, k));
1407 for (std::size_t a = 0; a < Msub; ++a) {
1409 for (std::size_t k = 0; k < K; ++k) {
1410 out.
QN(i, k) = Qsub(a, k);
1411 out.
UN(i, k) = Usub(a, k);
1415 for (std::size_t c = 0; c <
sn.nchains; ++c) {
1416 const std::size_t isf =
sn.stateful_of_station(i + 1) - 1;
1418 if (isf <
sn.visits[c].rows() && isfFes < snRed.
visits[c].rows() &&
1419 snRed.
visits[c](isfFes, k) > zero)
1420 ratio += T(
sn.visits[c](isf, k) / snRed.
visits[c](isfFes, k));
1422 out.
TN(i, k) = T(redAvg.
TN(fesIst - 1, k) * ratio);
1426 out.
CN.assign(K, zero);
1428 for (std::size_t i = 0; i < M; ++i)
1429 for (std::size_t k = 0; k < K; ++k) {
1430 if (out.
TN(i, k) > zero) out.
RN(i, k) = T(out.
QN(i, k) / out.
TN(i, k));
1431 out.
CN[k] += out.
RN(i, k);
1445 if (
opt.chain_aggregation &&
sn.nchains <
sn.nclasses)
What a solver observed about the Cache nodes of a model.
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
std::size_t stateful_of_station(std::size_t st) const
std::vector< NodeDef > nodes
every node, in creation order
std::vector< Matrix< T > > visits
(nchains) each (nstateful x nclasses)
static void step(const char *fmt,...)
Write one progress line.
Host-aware memory pre-gate for SolverCTMC.
Steady-state distribution of a continuous-time Markov chain.
Worst-case log-size of the CTMC state space induced by a NetworkStruct.
Port of matlab/src/solvers/CTMC/ctmc_stationary.m: the single entry point for the stationary distribu...
The exception types the port throws.
Flow-equivalent-server aggregation: replace a station subset by one station.
Per-station metrics of the ISOLATED subnetwork at every population state, the companion of fes_comput...
Port of matlab/src/api/fj/sn_fj_validate.m and matlab/src/io/@@ModelAdapter/fjtag....
Running progress log of a LINE solver run (the "solver console").
Dense matrix and non-owning view.
bool sn_has_nonmarkov(const qn::NetworkStruct< T > &sn, bool preserve_det=false)
Whether any law in the struct would be replaced, so a caller can skip copying the struct when there i...
@ Ph
Bernstein density fit: a genuine phase-type, shape-carrying.
void sn_nonmarkov_toph(qn::NetworkStruct< T > &sn, const NonmarkovOptions &opts=NonmarkovOptions())
Replace every non-Markovian service and firing law by a Markovian surrogate.
mva::AvgResult< T > solver_ctmc_fes_aggregation(const NetworkStruct< T > &sn, const CtmcOptions &opt)
Solve with a station subset replaced by a FLOW-EQUIVALENT SERVER, then recover the collapsed stations...
void ctmc_eliminate_vanishing(CtmcResult< T > &res)
Port of the "now remove immediate transitions" block of solver_ctmc.m (:812-870): eliminate the vanis...
mva::AvgResult< T > solver_ctmc_chain_aggregation(const NetworkStruct< T > &sn, const CtmcOptions &opt)
Solve the CHAIN-AGGREGATED model and map its metrics back to the classes.
void check_method(const std::string &method)
Port of runAnalyzerChecks' method gate.
std::vector< std::string > list_valid_methods()
Port of SolverCTMC.listValidMethods.
void ctmc_check_support(const NetworkStruct< T > &sn)
Refuse the constructs this port generates a chain for but does not MODEL.
CtmcAvg< T > solver_ctmc_avg_from_pi(const NetworkStruct< T > &sn, const CtmcResult< T > &r, const std::vector< T > &pivec)
Port of solver_ctmc_avg_from_pi: map a state distribution to mean metrics.
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...
mva::AvgResult< T > solver_ctmc_load_concealment(const NetworkStruct< T > &sn, const CtmcOptions &opt)
Solve by LOAD CONCEALMENT, the iterated transformation.
std::vector< NetState< T > > ctmc_filter_regions(const NetworkStruct< T > &sn, const std::vector< NetState< T > > &space)
The states of space a DROP region admits, in their original order.
CtmcResult< T > solver_ctmc(const NetworkStruct< T > &sn, const std::vector< NetState< T > > &space, const std::vector< Sync< T > > &sync, const std::vector< qn::GlobalSync< T > > &gsync=std::vector< qn::GlobalSync< T > >(), bool want_filtration=false, const std::vector< qn::FjSync< T > > &fjsync=std::vector< qn::FjSync< T > >())
Port of the generator assembly of solver_ctmc.m.
CtmcSolution< T > solve_struct(const NetworkStruct< T > &sn_in, const CtmcOptions &opt, const std::vector< qn::FjSync< T > > &fjsync)
Build the chain of ONE struct, solve it, reduce it.
std::string method_fallback_warning(const std::string &method)
The reference's fallback warning, or empty when the method needs none.
CtmcSolution< T > solver_ctmc_analyzer(const NetworkStruct< T > &sn_in, const CtmcOptions &opt)
Port of solver_ctmc_analyzer.m plus the fork-join wrapper of @@SolverCTMC/runAnalyzer....
mva::AvgResult< T > solver_ctmc_run_analyzer(const NetworkStruct< T > &sn, const CtmcOptions &opt)
Solve and format in one call, for a caller with no use for the chain.
CtmcStationaryResult< T > ctmc_stationary(const Matrix< T > &Q, std::size_t init_index=static_cast< std::size_t >(-1))
constexpr std::size_t CTMC_DEFAULT_CUTOFF
SolverOptions.m:107: the per-class state-space cutoff SolverCTMC defaults an open or mixed model to.
bool is_stateless_method(const std::string &method)
True for a method whose analyzer is not the explicit-generator one.
Matrix< T > ctmc_state_space_aggr(const NetworkStruct< T > &sn, const std::vector< NetState< T > > &space)
Port of StateSpaceAggr: the per-(station, class) job counts of every state, as an (nstates x nstation...
std::vector< NetState< T > > reachable_space_generator(const NetworkStruct< T > &sn, const NetState< T > &init, const std::vector< Sync< T > > &sync, const std::vector< qn::GlobalSync< T > > &gsync=std::vector< qn::GlobalSync< T > >(), std::size_t maxst=3000000, const std::vector< qn::FjSync< T > > &fjsync=std::vector< qn::FjSync< T > >(), const std::vector< std::size_t > &cutoff=std::vector< std::size_t >(), const std::vector< std::vector< std::size_t > > &cutoff_mat=std::vector< std::vector< std::size_t > >())
Port of State.reachableSpaceGenerator: the states reachable from init.
std::size_t ljd_linearize(const std::vector< int > &nvec, const std::vector< int > &cutoffs)
Linearized index of a per-class population vector, for Limited Joint Dependence (LJD) tables.
FesConditionalMetrics< T > fes_compute_metrics(const Matrix< T > &L, const std::vector< int > &mi, const std::vector< bool > &isDelay, const std::vector< int > &cutoffs)
Per-station metrics of the ISOLATED subnetwork at every population state, the companion of fes_comput...
FesAggregateResult< T > fes_aggregate(const qn::NetworkStruct< T > &sn, const std::vector< std::size_t > &subsetIndices, const FesOptions &options=FesOptions())
Flow-equivalent-server aggregation: replace a station subset by one station.
@ REPLY
completes a synchronous call, releasing a held server
constexpr double CTMC_DEFAULT_SAFETY_FRACTION
Fraction of available memory the solver may target.
CtmcGateResult ctmc_memory_gate(double log_nstates, bool force=false, double safety_fraction=CTMC_DEFAULT_SAFETY_FRACTION)
Decide whether a state space of log-size log_nstates can be solved here.
double ctmc_state_space_logsize(const qn::NetworkStruct< T > &sn, const CtmcSizeOptions &opt=CtmcSizeOptions())
Worst-case log state-space size of sn.
Matrix< T > sn_get_residt_from_respt(const qn::NetworkStruct< T > &L, const Matrix< T > &RN)
Port of sn_get_residt_from_respt: the per-JOB residence time.
Matrix< T > filter_metric(const qn::NetworkStruct< T > &L, const Matrix< T > &metric, MetricKind kind, const std::vector< std::vector< bool > > *zero_mask)
Port of filterMetric: what @@NetworkSolver/getAvg does between the analyzer and the caller.
Matrix< T > sn_get_arvr_from_tput(const qn::NetworkStruct< T > &L, const Matrix< T > &TN)
void cache_retrieval_class_map(const CacheParam< T > &cp, std::vector< std::size_t > &rc_list, std::vector< std::size_t > &rc_items, std::vector< std::size_t > &rc_orig)
Port of State.cacheRetrievalClassMap: the canonical order of a cache's retrieval classes,...
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.
std::size_t state_initial_occupancy(const NetworkStruct< T > &sn, std::size_t ind, std::size_t r)
Port of State.initialOccupancy: the class-r jobs node ind holds in the DECLARED initial state,...
FeatureSet ctmc_feature_set(const std::string &method)
SolverCTMC.getFeatureSet, the reference's 104 MATLAB names in full.
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.
FjTagged< T > fj_tag(const NetworkStruct< T > &sn)
Port of ModelAdapter.fjtag.
CacheMetrics< T > cache_metrics_of(const qn::NetworkStruct< T > &sn, const std::vector< T > &hitprob, const std::vector< T > &missprob, const std::vector< T > &delayedprob, const std::vector< T > &latency, const Matrix< T > &hitproblist, const Matrix< T > &itemprob, const std::vector< T > &listcost)
Assemble CacheMetrics from what a cache analyzer returned.
mva::AvgResult< T > transform_solve_lc(const qn::NetworkStruct< T > &sn, InnerSolve inner_solve, const std::string &method, std::size_t iter_max=1000)
LOAD CONCEALMENT (Birman-Kogan Algorithm 2) as a transformation, and the first ITERATED one.
void fj_foldback(const qn::NetworkStruct< T > &sn, Avg &a, const std::vector< std::size_t > &fjclassmap, std::size_t korig)
Reduce the augmented metrics onto the original classes.
mva::AvgResult< T > transform_solve_chains(const qn::NetworkStruct< T > &sn, InnerSolve inner_solve, const std::string &method)
Chain aggregation: collapse every chain onto a single class, solve, and map the chain metrics back on...
bool has_fork_join(const qn::NetworkStruct< T > &sn)
Whether the model needs the tag augmentation at all.
A queueing network and its refreshed NetworkStruct.
Collapse every chain onto one class, port of ModelAdapter.aggregateChains.
Replace every non-Markovian service and firing law by a Markovian surrogate.
Port of solver_ctmc.m: the infinitesimal generator of a queueing network, assembled from the enumerat...
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.
The SolverMVA class surface: @@SolverMVA/runAnalyzer.m and the gates around it.
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...
options.config.nonmkv and friends.
std::size_t order
nonmkvorder, the phase budget
PhFit phfit
which surrogate family
The mean performance metrics a stationary vector maps to.
The SolverCTMC knobs this port honours.
bool force
options.force: downgrade the memory pre-gate's refusal to a warning.
double memory_safety_fraction
options.memorySafetyFraction: share of available memory a solve may target.
std::vector< std::size_t > cutoff_vec
per-class override, or empty
std::size_t nonmkv_order
options.config.nonmkvorder: the phase budget sn_nonmarkov_toph spends on a non-Markovian service law.
bool load_concealment
options.config.transform='lc': solve by LOAD CONCEALMENT.
std::size_t transform_iter_max
Sweep cap for an iterated transformation; the kernel's own default.
std::vector< std::vector< std::size_t > > cutoff_mat
options.cutoff AS A (station x class) MATRIX, or empty.
std::vector< std::size_t > fes_stations
options.config.fes_stations: 1-BASED station indices to collapse into a flow-equivalent server before...
std::size_t state_max
refuse a space larger than this
double fau_delta
options.config.fau_delta: occupancy below which a state is dropped.
double cutoff
< 0 = not given
double timestep
options.timestep: the FIXED OUTPUT STEP of a transient analysis.
std::string transient_method
options.config.transient_method: "ode" (the default) integrates the forward equation,...
std::size_t fau_ngrid
options.config.fau_ngrid: output grid size when timestep is unset.
bool chain_aggregation
options.config.chain_aggregation: solve the CHAIN-AGGREGATED model.
double fau_epsilon
options.config.fau_epsilon: total probability mass the whole grid may discard under "fau".
bool keep_filtration
Keep the per-synchronization EVENT FILTRATION alongside Q.
The generator, the state space it is indexed by, and the event rates.
std::vector< NetState< T > > space
row i of Q is space[i]
Matrix< T > Q
(n x n) infinitesimal generator
Everything one CTMC solve produces.
std::string warning
Set when the chain is a reducible mixture solved from an invented seed.
std::vector< std::size_t > cutoff
the per-class cutoff actually used
solvers::CacheMetrics< T > cache
What the chain says about the model's Cache nodes: exact, since the hit and miss shares are read off ...
std::vector< std::size_t > fjclassmap
fjclassmap when the model was fork-join, empty otherwise: the ORIGINAL class of each auxiliary siblin...
std::vector< T > pi
stationary distribution over chain.space
std::vector< T > pi
stationary distribution, length N
std::string warning
Empty unless the chain is an UNSEEDED reducible mixture.
What fes_aggregate returns.
The per-population tables the conditional sum is taken over.
std::vector< Matrix< T > > QN
Indexed by the 0-based linearized population state; each (M_sub x K).
std::vector< Matrix< T > > UN
Indexed by the 0-based linearized population state; each (M_sub x K).
Everything needed to map an FES result back onto the original model.
Matrix< T > isolatedDemands
(M_sub x K)
std::vector< std::size_t > subsetIndices
1-based, as given
std::vector< std::size_t > complementIndices
1-based
std::vector< bool > isolatedIsDelay
std::vector< int > isolatedServers
std::size_t fesNode
1-based node index of the FES in the new model
std::vector< int > cutoffs
The gate verdict, plus the message the caller reports either way.
Options the estimator reads; only the cutoff matters.
double cutoff
< 0 or non-finite = not given, take the solver default
The metrics getAvg returns, after filtering.
Matrix< T > RN
response time, per visit
Matrix< T > UN
utilization
Matrix< T > WN
residence time, per job
std::string method
the method asked for
std::string actualmethod
the algorithm that ran
Matrix< T > QN
queue length
std::vector< T > CN
system response time per class
std::vector< T > XN
system throughput per class
solvers::CacheMetrics< T > cache
What the cache branches observed, EMPTY on a model with no Cache node and on every solver that does n...
Matrix< T > AN
arrival rate
One fork firing synchronization: sn.fjsync{k}.
The augmented struct and everything needed to read its results back.
std::vector< FjSync< T > > fjsync
std::vector< std::size_t > fjclassmap
fjclassmap[a-1] is the ORIGINAL class of auxiliary class a, 0 for originals.
One network state: the per-stateful-node local rows it is composed of.
Every Cache node of the model, in node order; empty on a model with none.