5#ifndef LINE_SOLVERS_CTMC_SOLVER_CTMC_ANALYZER_H
6#define LINE_SOLVERS_CTMC_SOLVER_CTMC_ANALYZER_H
92 double nominal = std::numeric_limits<double>::quiet_NaN();
265 return {
"default",
"exact",
"mdd"};
270 return method ==
"mdd";
283 if (std::find(valid.begin(), valid.end(), method) == valid.end())
285 "' method is unsupported by this solver");
288 "' method does not enumerate a state space and is served by its "
289 "own analyzer, not by solver_ctmc_analyzer");
320 for (std::size_t i = 0; i <
sn.stations.size(); ++i) {
321 if (
sn.stations[i].cdscaling &&
sn.stations[i].cdscalingpeak.empty())
323 "SolverCTMC: station '" +
sn.stations[i].name +
324 "' declares class-dependent service without a peak rate. Utilization at a "
325 "class-dependent station is reported as T/mu/peak, so pass the peak to "
326 "setClassDependence");
327 if (
sn.stations[i].jdscaling &&
sn.stations[i].jdscalingpeak.empty())
329 "SolverCTMC: station '" +
sn.stations[i].name +
330 "' declares joint-dependent service without a peak rate; pass the peak to "
331 "setJointDependence");
353namespace analyzer_detail {
371std::vector<std::size_t> resolve_cutoff(
const NetworkStruct<T>&
sn,
const CtmcOptions&
opt) {
372 const std::size_t M =
sn.nstations, K =
sn.nclasses;
373 std::vector<std::size_t> cut(K, 0);
374 bool any_open =
false;
375 for (std::size_t k = 0; k < K; ++k)
376 if (!std::isfinite(
sn.njobs()[k])) any_open =
true;
377 if (!any_open)
return cut;
379 if (!
opt.cutoff_mat.empty()) {
383 if (
opt.cutoff_mat.size() != M)
384 throw InputError(
"SolverCTMC: the cutoff matrix must have one row per station");
385 for (std::size_t k = 0; k < K; ++k) {
386 if (std::isfinite(
sn.njobs()[k]))
continue;
387 for (std::size_t i = 0; i < M; ++i) {
388 if (
opt.cutoff_mat[i].size() != K)
390 "SolverCTMC: the cutoff matrix must have one column per class");
391 cut[k] = std::max(cut[k],
opt.cutoff_mat[i][k]);
396 if (!opt.cutoff_vec.empty()) {
397 if (opt.cutoff_vec.size() != K)
398 throw InputError(
"SolverCTMC: the per-class cutoff must have one entry per class");
399 return opt.cutoff_vec;
402 if (opt.cutoff > 0 && std::isfinite(opt.cutoff)) {
403 c =
static_cast<std::size_t
>(opt.cutoff);
404 }
else if (opt.cutoff < 0) {
407 const double e = 1.0 /
static_cast<double>(M * K);
408 c =
static_cast<std::size_t
>(std::ceil(std::pow(6000.0, e)));
411 for (std::size_t k = 0; k < K; ++k)
412 if (!std::isfinite(sn.njobs()[k])) cut[k] = c;
429bool set_retrieval_truncation(
const NetworkStruct<T>& sn,
const std::vector<std::size_t>& cutoff,
430 NetworkStruct<T>& out) {
432 for (
typename std::map<std::size_t, qn::CacheParam<T>>::const_iterator ci =
433 sn.nodeparam.begin();
434 ci != sn.nodeparam.end(); ++ci)
435 if (ci->second.retrieval_capacity > 0 && !ci->second.retrieval_classes.empty()) any =
true;
436 if (!any)
return false;
438 if (sn.nclosedjobs() > 0) {
439 lvl =
static_cast<long>(sn.nclosedjobs()) - 1;
442 for (std::size_t k = 0; k < cutoff.size(); ++k) mx = std::max(mx, cutoff[k]);
443 lvl =
static_cast<long>(mx) - 1;
445 if (lvl < 0) lvl = 0;
447 for (
typename std::map<std::size_t, qn::CacheParam<T>>::iterator ci = out.nodeparam.begin();
448 ci != out.nodeparam.end(); ++ci)
449 if (ci->second.retrieval_capacity > 0) ci->second.max_pending_retrieval = lvl;
477bool annihilate_signal_capacity(
const NetworkStruct<T>& sn, NetworkStruct<T>& out) {
478 std::vector<bool> annihilated(sn.nclasses,
false);
480 for (std::size_t k = 0; k < sn.nclasses && k < sn.issignal.size(); ++k) {
481 if (!sn.issignal[k])
continue;
483 annihilated[k] =
true;
486 if (!any)
return false;
488 for (std::size_t i = 0; i < out.stations.size() && i < out.classcap.size(); ++i) {
491 if (out.stations[i].sched == SchedStrategy::EXT)
continue;
492 for (std::size_t k = 0; k < annihilated.size() && k < out.classcap[i].size(); ++k)
493 if (annihilated[k]) out.classcap[i][k] = 0.0;
534solvers::CacheMetrics<T> cache_metrics(
const NetworkStruct<T>& sn,
const CtmcResult<T>& r,
535 const std::vector<T>& pi,
const Matrix<T>& QN) {
536 solvers::CacheMetrics<T> out =
538 std::vector<T>(), Matrix<T>(), Matrix<T>(), std::vector<T>());
539 if (out.caches.empty() || r.space.empty())
return out;
540 const std::size_t K = sn.nclasses, ns = r.space.size();
541 const double dnan = std::numeric_limits<double>::quiet_NaN();
543 for (std::size_t c = 0; c < out.caches.size(); ++c) {
544 solvers::CacheNodeMetrics<T>& m = out.caches[c];
545 const std::size_t isf = sn.stateful_index(m.node);
546 if (isf == 0)
continue;
547 const qn::CacheParam<T>& cp = sn.nodeparam.find(m.node)->second;
549 std::vector<double> tn(K, 0.0);
550 for (std::size_t s = 0; s < ns && s < pi.size(); ++s) {
551 const double p = num_traits<T>::to_double(pi[s]);
552 if (p == 0)
continue;
553 if (isf - 1 >= r.dep_rates[s].size())
continue;
554 for (std::size_t k = 0; k < K && k < r.dep_rates[s][isf - 1].size(); ++k)
555 tn[k] += p * num_traits<T>::to_double(r.dep_rates[s][isf - 1][k]);
558 const std::size_t n = cp.nitems;
560 for (std::size_t l = 0; l < cp.itemcap.size(); ++l)
561 if (cp.itemcap[l] > 0) tcc +=
static_cast<std::size_t
>(cp.itemcap[l]);
562 std::vector<std::size_t> rcl, rci, rco;
564 const std::size_t lvw = r.space[0].local[isf - 1].size();
565 const bool retr = !rcl.empty() && lvw >= tcc + n + rcl.size();
566 std::vector<double> drate(K, 0.0), dclass(K, 0.0), inflight(K, 0.0);
575 const std::size_t tail = cp.retrieval_capacity > 0 ? n + rcl.size() : 0;
576 if (n > 0 && tcc > 0 && lvw >= tcc + tail) {
577 const std::size_t coff = lvw - (tcc + tail);
578 const std::size_t h = cp.itemcap.size();
579 Matrix<T> ip(n, h + 1);
580 std::vector<double> acc(n * h, 0.0);
581 std::vector<char> present(n, 0);
582 for (std::size_t s = 0; s < ns && s < pi.size(); ++s) {
583 const double p = num_traits<T>::to_double(pi[s]);
584 if (p == 0)
continue;
585 const std::vector<T>& lv = r.space[s].local[isf - 1];
586 std::size_t off = coff;
587 for (std::size_t l = 0; l < h; ++l) {
588 const std::size_t cap =
589 cp.itemcap[l] > 0 ?
static_cast<std::size_t
>(cp.itemcap[l]) : 0;
590 std::fill(present.begin(), present.end(), 0);
591 for (std::size_t q = 0; q < cap; ++q) {
592 const long it =
static_cast<long>(num_traits<T>::to_double(lv[off + q]));
593 if (it >= 1 &&
static_cast<std::size_t
>(it) <= n)
594 present[
static_cast<std::size_t
>(it) - 1] = 1;
596 for (std::size_t i = 0; i < n; ++i)
597 if (present[i]) acc[i * h + l] += p;
601 for (std::size_t i = 0; i < n; ++i) {
603 for (std::size_t l = 0; l < h; ++l) {
604 const double v = acc[i * h + l];
605 ip(i, l + 1) = num_traits<T>::from_double(v);
608 ip(i, 0) = num_traits<T>::from_double(miss);
614 const std::size_t aoff = lvw - (n + rcl.size()), boff = aoff + n;
615 std::vector<double> phi(n, 0.0), d1(n, 0.0);
616 for (std::size_t s = 0; s < ns && s < pi.size(); ++s) {
617 const double p = num_traits<T>::to_double(pi[s]);
618 if (p == 0)
continue;
619 const std::vector<T>& lv = r.space[s].local[isf - 1];
620 for (std::size_t i = 0; i < n; ++i)
621 if (num_traits<T>::to_double(lv[aoff + i]) != 0) phi[i] += p;
622 for (std::size_t j = 0; j < rcl.size(); ++j)
623 d1[rci[j] - 1] += p * num_traits<T>::to_double(lv[boff + j]);
625 m.delayedhitqlen.assign(n, num_traits<T>::from_int(0));
626 m.delayedhitqlenfull.assign(n, num_traits<T>::from_int(0));
627 for (std::size_t i = 0; i < n; ++i) {
628 m.delayedhitqlen[i] = num_traits<T>::from_double(d1[i]);
629 m.delayedhitqlenfull[i] = num_traits<T>::from_double(d1[i] + phi[i]);
631 for (std::size_t s = 0; s < ns && s < pi.size(); ++s) {
632 const double p = num_traits<T>::to_double(pi[s]);
633 if (p == 0)
continue;
634 const std::vector<T>& lv = r.space[s].local[isf - 1];
635 for (std::size_t j = 0; j < rcl.size(); ++j) {
636 const std::size_t i = rci[j] - 1;
637 const double held = num_traits<T>::to_double(lv[boff + j]);
638 if (held <= 0 || num_traits<T>::to_double(lv[aoff + i]) == 0)
continue;
639 double completes = 0.0;
640 for (std::size_t b = 0; b < ns; ++b) {
641 if (b == s)
continue;
642 const double q = num_traits<T>::to_double(r.Q(s, b));
643 if (q == 0)
continue;
644 if (num_traits<T>::to_double(r.space[b].local[isf - 1][aoff + i]) == 0)
647 if (rco[j] - 1 < K) drate[rco[j] - 1] += p * held * completes;
652 for (std::size_t s = 0; s < ns && s < pi.size(); ++s) {
653 const double p = num_traits<T>::to_double(pi[s]);
654 if (p == 0)
continue;
655 const std::vector<T>& lv = r.space[s].local[isf - 1];
656 for (std::size_t j = 0; j < rcl.size(); ++j)
658 dclass[rco[j] - 1] += p * num_traits<T>::to_double(lv[boff + j]);
660 for (std::size_t k = 0; k < K; ++k)
661 for (std::size_t i = 0; i < cp.retrieval_classes.size(); ++i) {
662 if (k >= cp.retrieval_classes[i].size())
continue;
663 const std::size_t rc = cp.retrieval_classes[i][k];
664 if (rc == 0 || rc >
static_cast<std::size_t
>(
QN.cols()))
continue;
665 for (std::size_t st = 0; st < static_cast<std::size_t>(
QN.rows()); ++st)
666 inflight[k] += num_traits<T>::to_double(
QN(st, rc - 1));
670 m.hitprob.assign(K, num_traits<T>::from_double(dnan));
671 m.missprob.assign(K, num_traits<T>::from_double(dnan));
672 if (retr) m.delayedprob.assign(K, num_traits<T>::from_double(dnan));
673 for (std::size_t k = 0; k < K; ++k) {
674 if (k >= cp.hitclass.size() || k >= cp.missclass.size())
continue;
675 const std::size_t h = cp.hitclass[k], mi = cp.missclass[k];
676 if (h == 0 || mi == 0 || h > K || mi > K)
continue;
677 const double denom = tn[h - 1] + tn[mi - 1];
678 if (denom <= 0)
continue;
682 const double d = retr ? std::min(drate[k], tn[h - 1]) : 0.0;
683 m.hitprob[k] = num_traits<T>::from_double((tn[h - 1] - d) / denom);
684 m.missprob[k] = num_traits<T>::from_double(tn[mi - 1] / denom);
685 if (retr) m.delayedprob[k] = num_traits<T>::from_double(d / denom);
686 if (retr && cp.retrieval_queues.find(k) != cp.retrieval_queues.end() &&
687 !cp.retrieval_queues.find(k)->second.empty()) {
688 if (m.latency.empty()) m.latency.assign(K, num_traits<T>::from_double(dnan));
689 const double enter = d + tn[mi - 1];
691 m.latency[k] = num_traits<T>::from_double((inflight[k] + dclass[k]) / enter);
719void strip_reference_source_column(
const NetworkStruct<T>& sn, std::size_t ind,
720 std::vector<T>& row) {
721 const std::size_t ist = sn.nodes[ind - 1].station;
722 if (ist == 0 || ist > sn.stations.size())
return;
723 if (sn.stations[ist - 1].nodetype != NodeType::Source &&
724 sn.stations[ist - 1].sched != SchedStrategy::EXT)
727 for (std::size_t r = 0; r < sn.nclasses; ++r) w += sn.phasessz_of(ist, r + 1);
731 if (row.size() == w + 1) row.erase(row.begin());
746bool default_init_state(
const NetworkStruct<T>& sn, NetState<T>& init) {
747 const std::size_t R = sn.nclasses;
748 const std::vector<std::size_t>& sfn = sn.stateful_nodes;
749 init.local.assign(sfn.size(), std::vector<T>());
750 for (std::size_t f = 0; f < sfn.size(); ++f) {
751 const std::size_t ind = sfn[f];
760 const typename std::map<std::size_t, Matrix<T>>::const_iterator sp =
761 sn.statespace.find(ind);
762 if (sp != sn.statespace.end() && sp->second.rows() == 1 && sp->second.cols() > 0) {
763 std::vector<T> row(sp->second.cols());
764 for (std::size_t c = 0; c < sp->second.cols(); ++c) row[c] = sp->second(0, c);
765 strip_reference_source_column(sn, ind, row);
779 std::vector<std::size_t> marg(R, 0), mph(R, 1);
780 const std::size_t mist = sn.nodes[ind - 1].station;
781 bool rebuilt =
false;
782 if (row.size() == R && mist != 0) {
783 for (std::size_t r = 0; r < R; ++r) {
784 const double v = num_traits<T>::to_double(row[r]);
785 marg[r] = v > 0.0 ?
static_cast<std::size_t
>(v + 0.5) : 0;
786 mph[r] = sn.phasessz_of(mist, r + 1);
788 std::vector<T> built;
790 init.local[f] = built;
794 if (!rebuilt) init.local[f] = row;
797 const std::size_t ist = sn.nodes[ind - 1].station;
798 std::vector<std::size_t> nmarg(R, 0), ph(R, 1);
800 for (std::size_t r = 0; r < R; ++r) ph[r] = sn.phasessz_of(ist, r + 1);
801 if (sn.stations[ist - 1].nodetype == NodeType::Source) {
809 for (std::size_t r = 0; r < R; ++r)
810 if (!sn.disabled[ist - 1][r]) nmarg[r] = 1;
812 for (std::size_t r = 0; r < R; ++r) {
813 const double nj = sn.njobs()[r];
814 if (std::isfinite(nj) && sn.classes[r].refstat == ist)
815 nmarg[r] =
static_cast<std::size_t
>(nj);
826 for (std::size_t r = 0; r < R; ++r) {
828 if (m0 > nmarg[r]) nmarg[r] = m0;
839std::size_t init_state_index(
const NetworkStruct<T>& sn,
const std::vector<NetState<T>>& space) {
840 const std::size_t npos =
static_cast<std::size_t
>(-1);
841 if (space.empty())
return npos;
843 if (!default_init_state(sn, init))
return npos;
844 for (std::size_t f = 0; f < init.local.size(); ++f) {
847 const std::size_t w = space[0].local[f].size();
848 if (init.local[f].size() > w)
return npos;
849 if (init.local[f].size() < w)
850 init.local[f].insert(init.local[f].begin(), w - init.local[f].size(),
851 num_traits<T>::from_int(0));
853 const std::vector<double> key = ctmc_detail::state_key(init);
854 for (std::size_t s = 0; s < space.size(); ++s)
855 if (ctmc_detail::state_key(space[s]) == key)
return s;
879bool init_state_distribution(
const NetworkStruct<T>& sn,
const std::vector<NetState<T>>& space,
880 std::vector<T>& pi0) {
881 const std::size_t npos =
static_cast<std::size_t
>(-1);
882 pi0.assign(space.size(), num_traits<T>::from_int(0));
883 if (space.empty())
return false;
885 if (!default_init_state(sn, base))
return false;
886 const std::vector<std::size_t>& sfn = sn.stateful_nodes;
890 std::vector<std::vector<std::vector<T>>> rows(sfn.size());
891 std::vector<std::vector<double>> wts(sfn.size());
892 for (std::size_t f = 0; f < sfn.size(); ++f) {
893 const typename std::map<std::size_t, Matrix<T>>::const_iterator ss =
894 sn.statespace.find(sfn[f]);
895 const typename std::map<std::size_t, std::vector<T>>::const_iterator sp =
896 sn.stateprior.find(sfn[f]);
897 if (ss == sn.statespace.end() || sp == sn.stateprior.end() || ss->second.rows() == 0 ||
898 ss->second.rows() != sp->second.size()) {
899 rows[f].push_back(base.local[f]);
900 wts[f].push_back(1.0);
903 for (std::size_t r = 0; r < ss->second.rows(); ++r) {
904 const double w = num_traits<T>::to_double(sp->second[r]);
905 if (!(w > 0.0))
continue;
906 std::vector<T> row(ss->second.cols());
907 for (std::size_t c = 0; c < ss->second.cols(); ++c) row[c] = ss->second(r, c);
908 strip_reference_source_column(sn, sfn[f], row);
909 rows[f].push_back(row);
912 if (rows[f].empty())
return false;
915 std::vector<std::size_t> pick(sfn.size(), 0);
918 NetState<T> cand = base;
920 for (std::size_t f = 0; f < sfn.size(); ++f) {
921 cand.local[f] = rows[f][pick[f]];
922 w *= wts[f][pick[f]];
925 const std::size_t wd = space[0].local[f].size();
926 if (cand.local[f].size() > wd)
return false;
927 if (cand.local[f].size() < wd)
928 cand.local[f].insert(cand.local[f].begin(), wd - cand.local[f].size(),
929 num_traits<T>::from_int(0));
931 std::size_t idx = npos;
932 const std::vector<double> key = ctmc_detail::state_key(cand);
933 for (std::size_t s = 0; s < space.size() && idx == npos; ++s)
934 if (ctmc_detail::state_key(space[s]) == key) idx = s;
935 if (idx == npos)
return false;
936 pi0[idx] = T(pi0[idx] + num_traits<T>::from_double(w));
940 for (; f < sfn.size(); ++f) {
941 if (++pick[f] < rows[f].size())
break;
944 if (f == sfn.size())
break;
946 if (!(total > 0.0))
return false;
956std::vector<std::size_t> weak_components(
const Matrix<T>& Q, std::size_t& ncomp) {
957 const std::size_t n = Q.rows();
958 const std::size_t npos =
static_cast<std::size_t
>(-1);
959 std::vector<std::size_t> comp(n, npos);
961 for (std::size_t s = 0; s < n; ++s) {
962 if (comp[s] != npos)
continue;
963 std::vector<std::size_t> stack{s};
965 while (!stack.empty()) {
966 const std::size_t u = stack.back();
968 for (std::size_t v = 0; v < n; ++v) {
969 if (comp[v] != npos)
continue;
972 if (v == u)
continue;
973 if (num_traits<T>::to_double(Q(u, v)) != 0 ||
974 num_traits<T>::to_double(Q(v, u)) != 0) {
987CtmcResult<T> restrict_to(
const CtmcResult<T>& r,
const std::vector<std::size_t>& wset) {
989 out.Q =
Matrix<T>(wset.size(), wset.size(), num_traits<T>::from_int(0));
990 for (std::size_t a = 0; a < wset.size(); ++a)
991 for (std::size_t b = 0; b < wset.size(); ++b) out.Q(a, b) = r.Q(wset[a], wset[b]);
992 out.space.reserve(wset.size());
993 out.arv_rates.reserve(wset.size());
994 out.dep_rates.reserve(wset.size());
995 for (std::size_t a = 0; a < wset.size(); ++a) {
996 out.space.push_back(r.space[wset[a]]);
997 out.arv_rates.push_back(r.arv_rates[wset[a]]);
998 out.dep_rates.push_back(r.dep_rates[wset[a]]);
1004 out.filt.reserve(r.filt.size());
1005 for (std::size_t f = 0; f < r.filt.size(); ++f) {
1006 Matrix<T> F(wset.size(), wset.size(), num_traits<T>::from_int(0));
1007 for (std::size_t a = 0; a < wset.size(); ++a)
1008 for (std::size_t b = 0; b < wset.size(); ++b) F(a, b) = r.filt[f](wset[a], wset[b]);
1009 out.filt.push_back(F);
1036 out.
cutoff = analyzer_detail::resolve_cutoff(sn_in,
opt);
1040 const bool retr = analyzer_detail::set_retrieval_truncation(sn_in, out.
cutoff, sn_trunc);
1046 const bool sig = analyzer_detail::annihilate_signal_capacity(sn_r, sn_sig);
1064 const std::vector<Sync<T>> sync = refresh_sync(
sn);
1065 const std::vector<qn::GlobalSync<T>> gsync = refresh_global_sync(
sn);
1081 std::vector<NetState<T>> space;
1082 if (!gsync.empty() || !fjsync.empty()) {
1084 if (!analyzer_detail::default_init_state(
sn, init))
1086 "SolverCTMC: the model's initial marking admits no state; check the Place "
1087 "populations against the class reference stations");
1094 space = space_generator(
sn, out.
cutoff,
opt.state_max,
opt.cutoff_mat);
1098 "SolverCTMC: the state space is empty; no state satisfies the model's capacities");
1115 const std::size_t npos =
static_cast<std::size_t
>(-1);
1118 std::size_t init = analyzer_detail::init_state_index(
sn, r.
space);
1120 std::size_t ncomp = 0;
1121 const std::vector<std::size_t> comp = analyzer_detail::weak_components(r.
Q, ncomp);
1130 std::vector<std::size_t> sizes(ncomp, 0);
1131 for (std::size_t s = 0; s < comp.size(); ++s) ++sizes[comp[s]];
1132 pick =
static_cast<std::size_t
>(
1133 std::max_element(sizes.begin(), sizes.end()) - sizes.begin());
1135 std::vector<std::size_t> wset;
1136 for (std::size_t s = 0; s < comp.size(); ++s)
1137 if (comp[s] == pick) wset.push_back(s);
1140 std::size_t moved = npos;
1142 for (std::size_t k = 0; k < wset.size(); ++k)
1143 if (wset[k] == init) {
1148 r = analyzer_detail::restrict_to(r, wset);
1158 static_cast<std::size_t
>(r.
Q.rows()));
1165 out.
cache = analyzer_detail::cache_metrics(
sn, r, out.
pi, out.
avg.QN);
1249 const std::string& method) {
1250 const std::size_t M =
sn.nstations, K =
sn.nclasses;
1252 std::vector<std::vector<bool>> srcmask(M, std::vector<bool>(K,
false));
1253 for (std::size_t i = 0; i < M; ++i)
1254 if (
sn.stations[i].nodetype == NodeType::Source)
1255 for (std::size_t k = 0; k < K; ++k) srcmask[i][k] =
true;
1314 sub.chain_aggregation =
false;
1333 sub.load_concealment =
false;
1337 opt.method,
opt.transform_iter_max);
1365 const std::size_t M =
sn.nstations, K =
sn.nclasses;
1366 const std::vector<std::size_t>& subset =
opt.fes_stations;
1367 if (subset.size() < 2)
1369 "options.config.fes_stations must name at least two stations: collapsing one "
1370 "station into a flow-equivalent server saves nothing.");
1371 if (subset.size() >= M)
1373 "options.config.fes_stations names every station: there is no complement left "
1375 for (std::size_t i : subset)
1377 throw InputError(
"options.config.fes_stations must be 1-based station indices in 1.." +
1378 std::to_string(M) +
".");
1385 sub.fes_stations.clear();
1392 const std::size_t fesIst = snRed.
nodes[info.
fesNode - 1].station;
1393 std::size_t tableSize = 1;
1394 for (
int c : info.
cutoffs) tableSize *=
static_cast<std::size_t
>(c + 1);
1395 std::vector<double> Pn(tableSize, 0.0);
1396 for (std::size_t r = 0; r < SSq.
rows(); ++r) {
1397 std::vector<int> nvec(K, 0);
1398 for (std::size_t k = 0; k < K; ++k)
1399 nvec[k] =
static_cast<int>(
1417 for (std::size_t k = 0; k < K; ++k) {
1418 out.
QN(i, k) = redAvg.
QN(a, k);
1419 out.
UN(i, k) = redAvg.
UN(a, k);
1420 out.
TN(i, k) = redAvg.
TN(a, k);
1425 Matrix<T> Qsub(Msub, K, zero), Usub(Msub, K, zero);
1426 for (std::size_t idx = 0; idx < tableSize; ++idx) {
1427 if (!(Pn[idx] > 0.0))
continue;
1429 for (std::size_t a = 0; a < Msub && a < cm.
QN[idx].rows(); ++a)
1430 for (std::size_t k = 0; k < K; ++k) {
1431 Qsub(a, k) += T(w * cm.
QN[idx](a, k));
1432 Usub(a, k) += T(w * cm.
UN[idx](a, k));
1435 for (std::size_t a = 0; a < Msub; ++a) {
1437 for (std::size_t k = 0; k < K; ++k) {
1438 out.
QN(i, k) = Qsub(a, k);
1439 out.
UN(i, k) = Usub(a, k);
1443 for (std::size_t c = 0; c <
sn.nchains; ++c) {
1444 const std::size_t isf =
sn.stateful_of_station(i + 1) - 1;
1446 if (isf <
sn.visits[c].rows() && isfFes < snRed.
visits[c].rows() &&
1447 snRed.
visits[c](isfFes, k) > zero)
1448 ratio += T(
sn.visits[c](isf, k) / snRed.
visits[c](isfFes, k));
1450 out.
TN(i, k) = T(redAvg.
TN(fesIst - 1, k) * ratio);
1454 out.
CN.assign(K, zero);
1456 for (std::size_t i = 0; i < M; ++i)
1457 for (std::size_t k = 0; k < K; ++k) {
1458 if (out.
TN(i, k) > zero) out.
RN(i, k) = T(out.
QN(i, k) / out.
TN(i, k));
1459 out.
CN[k] += out.
RN(i, k);
1473 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...
SnPnAvgRates< T > sn_pn_avg_rates(const qn::NetworkStruct< T > &sn, const Matrix< T > &QN, const Matrix< T > &TN, const Matrix< T > &AN, const Matrix< T > &RN)
Port of sn_pn_avg_rates: rewrite the place rows of TN, AN and RN so that they agree with the recovere...
@ 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.
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.
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.
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.
Conservation laws of a layered queueing network, enumerated from its structure.
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.
Ports of matlab/src/api/sn/sn_pn_firing_rates.m and sn_pn_avg_rates.m.
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
What sn_pn_avg_rates rewrites in place; empty tables are left empty.
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.
std::vector< CtmcRateSched > rate_sched
options.config.rate_sched: the TIME-INHOMOGENEOUS transient.
bool chain_aggregation
options.config.chain_aggregation: solve the CHAIN-AGGREGATED model.
std::size_t ctmc_tv_ngrid
options.config.ctmc_tv_ngrid: uniform grid size of the rate_sched propagator.
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.
One entry of options.config.rate_sched: the rate of (station, class) follows the piecewise-linear sch...
std::vector< double > rates
std::vector< double > tgrid
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.
static constexpr double Zero
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.