5#ifndef LINE_SOLVERS_MAM_SOLVER_MAM_BASIC_H
6#define LINE_SOLVERS_MAM_SOLVER_MAM_BASIC_H
107using lang::GlobalConstants;
111namespace basic_detail {
127 case ProcessType::EXP:
128 case ProcessType::ERLANG:
129 case ProcessType::HYPEREXP:
130 case ProcessType::PH:
131 case ProcessType::APH:
132 case ProcessType::ME:
133 case ProcessType::RAP:
134 case ProcessType::MAP:
135 case ProcessType::MMAP:
136 case ProcessType::MPH:
137 case ProcessType::COXIAN:
138 case ProcessType::COX2:
139 case ProcessType::MMPP2:
140 case ProcessType::IMMEDIATE:
141 case ProcessType::DISABLED:
163const lang::Distrib<T>& mam_declared_law(
const lang::Distrib<T>& d) {
167 return d.declared ? *d.declared : d;
171bool mam_gk1_applicable(
const qn::NetworkStruct<T>& L, std::size_t i0, std::size_t K) {
172 for (std::size_t r = 0; r < K; ++r) {
189bool is_renewal_map(
const Map<T>& m) {
190 const std::size_t n = m.D0.rows();
191 if (n == 1)
return true;
193 for (std::size_t i = 0; i < n; ++i)
194 for (std::size_t j = 0; j < n; ++j)
195 scale = std::max(scale, std::fabs(num_traits<T>::to_double(m.D1(i, j))));
196 const double tol = 1e-9 * scale;
197 std::vector<double> exitrate(n, 0.0), sigma(n, 0.0);
199 for (std::size_t i = 0; i < n; ++i) {
200 for (std::size_t j = 0; j < n; ++j) exitrate[i] += num_traits<T>::to_double(m.D1(i, j));
203 if (tot <= 0.0)
return true;
206 for (std::size_t i = 0; i < n; ++i)
207 if (exitrate[i] > tol) {
211 if (ref == n)
return true;
212 for (std::size_t j = 0; j < n; ++j)
213 sigma[j] = num_traits<T>::to_double(m.D1(ref, j)) / exitrate[ref];
214 for (std::size_t i = 0; i < n; ++i)
215 for (std::size_t j = 0; j < n; ++j)
216 if (std::fabs(num_traits<T>::to_double(m.D1(i, j)) - exitrate[i] * sigma[j]) > tol)
229std::vector<bool> corr_service_classes(
const qn::NetworkStruct<T>& L, std::size_t i0,
230 const std::vector<Map<T>>& PHi,
231 const std::vector<bool>& known) {
232 const std::size_t K = L.nclasses;
233 std::vector<bool> corr(K,
false);
234 for (std::size_t r = 0; r < K; ++r) {
236 if (pt != ProcessType::MAP && pt != ProcessType::MMPP2)
continue;
237 if (r >= PHi.size() || !known[r] || PHi[r].D0.rows() == 0)
continue;
238 corr[r] = !is_renewal_map(PHi[r]);
245std::string class_names(
const qn::NetworkStruct<T>& L,
const std::vector<bool>& mask) {
247 for (std::size_t r = 0; r < mask.size(); ++r)
248 if (mask[r]) s += (s.empty() ?
"" :
", ") + L.classes[r].name;
259void warn_carried(
const qn::NetworkStruct<T>& L, std::size_t i0,
const std::vector<bool>& corr) {
260 const std::size_t K = L.nclasses;
261 const double ns = L.stations[i0].nservers;
262 const std::string
name = L.stations[i0].name, corrNames = class_names(L, corr);
263 if (ns > 1.0 && K == 1)
264 std::cerr <<
"[LINE] Warning: Station " <<
name <<
" has a correlated MAP service (class "
265 << corrNames <<
") at " << ns <<
" servers, and its exact MAP/MAP/c chain is "
266 <<
"too large. MAM carries the service phase on the single-fast-server "
267 <<
"surrogate, which is an approximation.\n";
269 std::cerr <<
"[LINE] Warning: Station " <<
name <<
" has a correlated MAP service (class "
270 << corrNames <<
") at " << ns <<
" servers with " << K <<
" classes. No exact "
271 <<
"multiclass multiserver analysis exists, so MAM carries each class's service "
272 <<
"phase across its services on the single-fast-server surrogate, which is an "
273 <<
"approximation.\n";
274 std::vector<bool> fitted(K,
false);
275 bool anyFitted =
false;
276 for (std::size_t r = 0; r < K; ++r) {
278 fitted[r] = !corr[r] &&
279 (pt == ProcessType::DET || pt == ProcessType::UNIFORM ||
280 pt == ProcessType::GAMMA || pt == ProcessType::PARETO ||
281 pt == ProcessType::WEIBULL || pt == ProcessType::LOGNORMAL ||
282 pt == ProcessType::ME);
283 anyFitted = anyFitted || fitted[r];
286 std::cerr <<
"[LINE] Warning: Station " <<
name <<
" mixes a correlated MAP service (class "
287 << corrNames <<
") with the non-phase-type service of class "
288 << class_names(L, fitted) <<
", which is read through its phase-type fit: "
289 <<
"MMAP[K]/G[K]/1 admits only independent service times.\n";
311bool mam_source_feeds_station(
const qn::NetworkStruct<T>& L, std::size_t jst, std::size_t ist) {
312 const std::size_t M = L.nstations, K = L.nclasses;
313 if (jst < 1 || jst > M || ist < 1 || ist > M || jst == ist)
return false;
314 if (L.nodes[L.node_of_station(jst) - 1].nodetype != qn::NodeType::Source)
return false;
317 if (rtst.rows() < M * K)
return false;
321 double emitted = 0.0;
322 for (std::size_t r = 0; r < K; ++r) {
323 const std::size_t row = (jst - 1) * K + r;
324 double into = 0.0, total = 0.0;
325 for (std::size_t c = 0; c < K; ++c)
326 into += num_traits<T>::to_double(rtst(row, (ist - 1) * K + c));
327 for (std::size_t c = 0; c < rtst.cols(); ++c)
328 total += num_traits<T>::to_double(rtst(row, c));
329 if (std::fabs(into - total) > tol)
return false;
332 if (emitted <= tol)
return false;
335 for (std::size_t kst = 1; kst <= M; ++kst) {
336 if (kst == jst)
continue;
338 for (std::size_t r = 0; r < K; ++r)
339 for (std::size_t c = 0; c < K; ++c)
340 into += num_traits<T>::to_double(rtst((kst - 1) * K + r, (ist - 1) * K + c));
341 if (into > tol)
return false;
348bool is_markovian_map(
const Map<T>& m) {
349 const std::size_t n = m.D0.rows();
351 for (std::size_t i = 0; i < n; ++i)
352 for (std::size_t j = 0; j < n; ++j) {
353 scale = std::max(scale, std::fabs(num_traits<T>::to_double(m.D0(i, j))));
354 scale = std::max(scale, std::fabs(num_traits<T>::to_double(m.D1(i, j))));
356 const double tol = 1e-9 * scale;
357 for (std::size_t i = 0; i < n; ++i) {
359 for (std::size_t j = 0; j < n; ++j) {
360 const double a = num_traits<T>::to_double(m.D0(i, j));
361 const double b = num_traits<T>::to_double(m.D1(i, j));
362 if (i != j && a < -tol)
return false;
363 if (b < -tol)
return false;
366 if (std::fabs(rowsum) > tol)
return false;
373qsys::ServiceLaw<T> svc_mixture(
const Mmap<T>& arv,
const std::vector<PhService<T>>& svc) {
374 const T zero = num_traits<T>::from_int(0);
375 const std::size_t K = svc.size();
376 Matrix<T> Q = arv.D0;
377 for (std::size_t k = 0; k < arv.classes(); ++k)
378 for (std::size_t i = 0; i < Q.rows(); ++i)
379 for (std::size_t j = 0; j < Q.cols(); ++j) Q(i, j) += arv.Dc[k](i, j);
381 std::vector<T> lam(K, zero);
383 for (std::size_t k = 0; k < K && k < arv.classes(); ++k) {
384 const std::vector<T> t =
vecmul(theta, arv.Dc[k]);
385 for (
const T& v : t) lam[k] += v;
388 std::vector<T> w(K, T(num_traits<T>::from_int(1) / num_traits<T>::from_int((
int)K)));
390 for (std::size_t k = 0; k < K; ++k) w[k] = T(lam[k] / sumL);
392 std::size_t ntot = 0;
393 for (
const PhService<T>& s : svc) ntot += s.S.rows();
394 std::vector<T> alpha(ntot, zero);
395 Matrix<T> Tm(ntot, ntot, zero);
397 for (std::size_t k = 0; k < K; ++k) {
398 for (std::size_t i = 0; i < svc[k].S.rows(); ++i) {
399 alpha[off + i] = T(w[k] * svc[k].sigma[i]);
400 for (std::size_t j = 0; j < svc[k].S.cols(); ++j) Tm(off + i, off + j) = svc[k].S(i, j);
402 off += svc[k].S.rows();
418Matrix<T> station_visits(
const qn::NetworkStruct<T>& L) {
419 Matrix<T> V(L.nstations, L.nclasses, num_traits<T>::from_int(0));
420 for (std::size_t c = 0; c < L.nchains; ++c)
421 for (std::size_t i = 0; i < L.nstations; ++i) {
422 const std::size_t sf = L.stateful_of_station(i + 1) - 1;
423 for (std::size_t k = 0; k < L.nclasses; ++k) V(i, k) += L.visits[c](sf, k);
430void zero_nans(Matrix<T>& A) {
431 for (std::size_t i = 0; i < A.rows(); ++i)
432 for (std::size_t j = 0; j < A.cols(); ++j)
433 if (std::isnan(num_traits<T>::to_double(A(i, j)))) A(i, j) = num_traits<T>::from_int(0);
454TruncRenorm<T> truncate_renorm(
const Mmap<T>& arv,
const std::vector<PhService<T>>& svc,
456 const T zero = num_traits<T>::from_int(0);
458 std::vector<PhService<T>> scall = svc;
459 if (svc.size() > 1) {
460 const qsys::ServiceLaw<T> mix = svc_mixture(arv, svc);
461 Matrix<T> Dsum(arv.order(), arv.order(), zero);
462 for (std::size_t k = 0; k < arv.classes(); ++k)
463 for (std::size_t i = 0; i < Dsum.rows(); ++i)
464 for (std::size_t j = 0; j < Dsum.cols(); ++j) Dsum(i, j) += arv.Dc[k](i, j);
467 call.Dc.assign(1, Dsum);
468 scall.assign(1, PhService<T>{mix.ph_alpha, mix.ph_T});
472 out.p.assign(capK + 1, zero);
474 for (std::size_t n = 0; n <= capK; ++n) {
478 if (!(mass > zero)) {
479 out.p.assign(capK + 1, zero);
480 out.p[0] = num_traits<T>::from_int(1);
482 for (std::size_t n = 0; n <= capK; ++n) out.p[n] /= mass;
485 for (std::size_t n = 0; n <= capK; ++n) m += num_traits<T>::from_int((int)n) * out.p[n];
486 if (m < zero) m = zero;
487 if (num_traits<T>::to_double(m) >
static_cast<double>(capK))
488 m = num_traits<T>::from_int((
int)capK);
490 out.lossProb = out.p[capK];
502bool station_setup_pair(
const qn::NetworkStruct<T>& L, std::size_t ist, lang::Distrib<T>& setup,
503 lang::Distrib<T>& delayoff) {
504 typename std::map<std::size_t, qn::SetupDelayOffParam<T>>::const_iterator it =
505 L.setupparam.find(ist);
506 if (it == L.setupparam.end())
return false;
507 return it->second.last(setup, delayoff);
520void mam_setup_qbd(
const qn::NetworkStruct<T>& L, std::size_t ist,
521 const std::vector<T>& aggrLambda,
522 const std::vector<std::vector<PhService<T>>>& svc,
const Matrix<T>& S,
523 const std::vector<std::vector<T>>& rates, std::size_t R,
double ns,
524 const lang::Distrib<T>& setup,
const lang::Distrib<T>& delayoff,
525 std::vector<T>& Qret) {
526 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
527 const std::size_t i0 = ist - 1, K = L.nclasses;
528 for (std::size_t r = 0; r < K; ++r) Qret[r] = zero;
529 if constexpr (!num_traits<T>::has_transcendental) {
531 "solver_mam_basic: a setup/delay-off station is solved by a QBD whose G matrix needs "
532 "a logarithm; rerun with --arith double or real");
538 std::vector<T> rho(K, zero);
540 for (std::size_t r = 0; r < K; ++r) {
541 if (L.disabled[i0][r])
continue;
543 const Matrix<T>& Sr = svc[i0][r].S;
544 if (Sr.rows() == 0)
continue;
546 for (std::size_t a = 0; a < negS.rows(); ++a)
547 for (std::size_t b = 0; b < negS.cols(); ++b) negS(a, b) = -negS(a, b);
548 const Matrix<T> negSinv =
inverse(negS);
550 for (std::size_t a = 0; a < negSinv.rows() && a < svc[i0][r].sigma.size(); ++a)
551 for (std::size_t b = 0; b < negSinv.cols(); ++b)
552 mean += svc[i0][r].sigma[a] * negSinv(a, b);
553 if (!(mean > zero))
continue;
554 std::size_t c = L.nchains;
555 for (std::size_t cc = 0; cc < L.nchains; ++cc)
556 if (L.chains[cc][r]) c = cc;
557 if (c == L.nchains)
continue;
559 rho[r] = T(rates[c][r] * mean);
562 if (!(rho_total > zero))
return;
565 for (std::size_t r = 0; r < K && r < aggrLambda.size(); ++r) lam_total += aggrLambda[r];
566 if (R == 1 && !aggrLambda.empty()) lam_total = aggrLambda[0];
567 if (!(lam_total > zero))
return;
568 const T aggrRate = T(lam_total / rho_total);
571 for (std::size_t r = 0; r < K; ++r)
572 if (rho[r] > zero) Qret[r] = T(qtot * rho[r] / rho_total);
593void mam_setup_closed(
const qn::NetworkStruct<T>& L, std::size_t ist,
594 const std::vector<std::vector<PhService<T>>>& svc,
const Matrix<T>& S,
595 const std::vector<std::vector<T>>& rates,
const std::vector<T>& ztchain,
596 const Matrix<T>& V,
double ns,
const lang::Distrib<T>& setup,
597 const lang::Distrib<T>& delayoff,
const Matrix<T>& QNprev,
598 std::vector<T>& Qret) {
599 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
600 const std::size_t i0 = ist - 1, K = L.nclasses;
601 for (std::size_t r = 0; r < K; ++r) Qret[r] = zero;
602 if constexpr (!num_traits<T>::has_transcendental) {
604 "solver_mam_basic: the closed setup/delay-off chain fits a phase-type setup and "
605 "delay-off, which needs a square root; rerun with --arith double or real");
612 for (std::size_t c = 0; c < L.nchains; ++c) {
614 bool finiteNc =
true, anyActive =
false;
615 for (std::size_t r = 0; r < K; ++r) {
616 if (!L.chains[c][r])
continue;
617 if (!std::isfinite(L.classes[r].population)) { finiteNc =
false;
break; }
618 Nc += num_traits<T>::from_double(L.classes[r].population);
619 if (rates[c][r] > zero && std::isfinite(num_traits<T>::to_double(S(i0, r))))
622 if (!finiteNc || !anyActive || !(Nc > zero))
continue;
625 for (std::size_t j = 0; j < K; ++j)
626 if (L.chains[c][j]) vtot += V(i0, j);
627 const T ZT = T(ztchain[c] / (vtot > ft ? vtot : ft));
637 T lamHere = zero, qnHere = zero, tnS = zero, tnTot = zero, svcAny = zero;
638 std::size_t svcAnyCount = 0;
639 for (std::size_t r = 0; r < K; ++r) {
640 if (!L.chains[c][r])
continue;
641 T lamK = rates[c][r];
642 if (!std::isfinite(num_traits<T>::to_double(lamK))) lamK = zero;
644 if (!std::isfinite(num_traits<T>::to_double(sk))) sk = zero;
646 if (i0 < QNprev.rows() && r < QNprev.cols() &&
647 std::isfinite(num_traits<T>::to_double(QNprev(i0, r))))
648 qnHere += QNprev(i0, r);
651 if (sk > zero) { svcAny += sk; ++svcAnyCount; }
654 if (lamHere > ft && T(Nc - qnHere) > zero) {
655 const T zalt = T(T(Nc - qnHere) / lamHere);
656 Zc = zalt > ZT ? zalt : ZT;
660 T Sbar = tnTot > ft ? T(tnS / tnTot)
662 ? T(svcAny / num_traits<T>::from_int(
663 static_cast<long>(svcAnyCount)))
665 if (!(Sbar > ft))
continue;
667 Nc, Zc, T(one / Sbar), alpharate, alphascv, betarate, betascv);
668 if (!std::isfinite(num_traits<T>::to_double(cr.QN)) || !(cr.XN > zero))
continue;
669 T Wq = T(T(cr.QN / cr.XN) - Sbar);
670 if (!(Wq > zero)) Wq = zero;
671 for (std::size_t r = 0; r < K; ++r) {
672 if (!L.chains[c][r])
continue;
673 if (L.disabled[i0][r])
continue;
679 const T cserv = (std::isfinite(ns) && ns >= 1.0)
680 ? num_traits<T>::from_double(ns)
682 if (rates[c][r] > zero && std::isfinite(num_traits<T>::to_double(S(i0, r))))
683 Qret[r] = T(rates[c][r] * T(Wq + T(S(i0, r) / cserv)));
707void solve_fcfs_station(
const qn::NetworkStruct<T>& L,
const MamOptions& opt, std::size_t ist,
708 const std::vector<T>& lambda,
const Matrix<T>& V,
const Matrix<T>& S,
709 const std::vector<std::vector<bool>>& Sknown,
710 const std::vector<std::vector<Map<T>>>& PH,
711 const std::vector<std::vector<bool>>& PHset,
712 const std::vector<std::vector<PhService<T>>>& svc,
713 const std::vector<Mmap<T>>& chainSysArrivals,
714 const std::vector<T>& ztchain, Matrix<T>& QN, Matrix<T>& UN,
715 Matrix<T>& RN, Matrix<T>& TN, std::vector<bool>& exact_station,
716 std::vector<bool>& car_warned) {
717 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
718 const std::size_t M = L.nstations, K = L.nclasses, C = L.nchains;
719 const double ns = L.stations[ist - 1].nservers;
720 const std::size_t i0 = ist - 1;
725 bool prio_distinct =
false;
726 if (sched_i == SchedStrategy::HOL || sched_i == SchedStrategy::FCFSPRPRIO)
727 for (std::size_t r = 1; r < K; ++r)
728 if (L.classes[r].prio != L.classes[0].prio) prio_distinct =
true;
731 std::vector<std::vector<T>> rates(C, std::vector<T>(K, zero));
732 for (std::size_t c = 0; c < C; ++c)
733 for (std::size_t r = 0; r < K; ++r) rates[c][r] = T(V(i0, r) * lambda[c]);
736 for (std::size_t c = 0; c < C; ++c) {
737 const std::vector<std::size_t>& ic = L.inchain[c];
739 for (std::size_t r : ic)
tot += rates[c][r - 1];
740 Matrix<T> markProb(1, ic.size(), zero);
741 for (std::size_t j = 0; j < ic.size(); ++j)
742 markProb(0, j) = (
tot > zero) ? T(rates[c][ic[j] - 1] / tot) : zero;
749 for (std::size_t j = 0; j < ic.size(); ++j)
750 if (rates[c][ic[j] - 1] > zero) anypos =
true;
752 std::vector<T> tgt(ic.size(), zero);
753 for (std::size_t j = 0; j < ic.size(); ++j)
754 tgt[j] = (rates[c][ic[j] - 1] > zero)
755 ? T(one / rates[c][ic[j] - 1])
756 : num_traits<T>::from_double(1.0 / GlobalConstants::Zero);
764 aggr =
mmap_super_safe(std::vector<Mmap<T>>{aggr, cur}, opt.space_max);
771 std::vector<std::size_t> markorder;
772 for (std::size_t c = 0; c < C; ++c)
773 for (std::size_t r : L.inchain[c]) markorder.push_back(r);
774 if (markorder.size() == aggr.Dc.size() &&
775 !std::is_sorted(markorder.begin(), markorder.end())) {
776 std::vector<std::size_t> perm(markorder.size());
777 for (std::size_t j = 0; j < perm.size(); ++j) perm[j] = j;
778 std::stable_sort(perm.begin(), perm.end(),
779 [&markorder](std::size_t a, std::size_t b) {
780 return markorder[a] < markorder[b];
782 std::vector<Matrix<T>> reordered(perm.size());
783 for (std::size_t j = 0; j < perm.size(); ++j) reordered[j] = aggr.Dc[perm[j]];
784 aggr.Dc.swap(reordered);
788 const std::size_t R = aggr.classes();
789 lang::Distrib<T> setup_dist, delayoff_dist;
790 const bool has_setup = station_setup_pair(L, ist, setup_dist, delayoff_dist);
814 const std::string mark_refusal =
815 std::string(
"solver_mam_basic: the assembled arrival stream at station '") +
816 L.stations[i0].name +
"' carries " + std::to_string(R) +
817 " marked classes against the model's " + std::to_string(K) +
818 "; the reference collapses chain 1 to a single mark, so this analyzer has no arrival "
819 "stream to pair with each service law. A class-switching chain at an FCFS station is "
820 "refused rather than solved with a mismatched marking";
822 const std::vector<T> aggrLambda =
mmap_lambda(aggr);
823 double aggrUtil = 0.0;
824 for (std::size_t r = 0; r < K; ++r) {
827 if (L.disabled[i0][r])
continue;
828 const double lam = num_traits<T>::to_double(aggrLambda[R == 1 ? 0 : r]);
829 const double mu = num_traits<T>::to_double(L.rates(i0, r));
831 if (den > 0.0 && std::isfinite(den)) aggrUtil += lam / den;
834 std::vector<T> Qret(K, zero);
835 bool exact_here =
false;
837 bool finiteCapUsed =
false;
838 T finiteCapMeanQ = zero, finiteCapLossProb = zero;
839 std::vector<T> finiteCapLossPerClass;
841 bool anyopen =
false;
842 for (std::size_t r = 0; r < K; ++r)
843 if (std::isinf(L.classes[r].population)) anyopen =
true;
845 if (prio_distinct && !car_warned[i0]) {
846 const std::vector<bool> corrP = corr_service_classes(L, i0, PH[i0], PHset[i0]);
847 if (std::find(corrP.begin(), corrP.end(),
true) != corrP.end()) {
848 car_warned[i0] =
true;
849 std::cerr <<
"[LINE] Warning: Station " << L.stations[i0].name
850 <<
" has a correlated MAP service (class " << class_names(L, corrP)
851 <<
") under class priorities. The priority analysis reads it through its "
852 <<
"renewal marginal, which discards the autocorrelation; SolverCTMC "
853 <<
"carries it exactly.\n";
863 std::vector<std::size_t> iK(K);
864 for (std::size_t r = 0; r < K; ++r) iK[r] = r;
865 std::stable_sort(iK.begin(), iK.end(), [&L](std::size_t a, std::size_t b) {
866 return L.classes[a].prio > L.classes[b].prio;
868 for (std::size_t j = 1; j < K; ++j)
869 if (L.classes[iK[j]].prio == L.classes[iK[j - 1]].prio)
871 "solver_mam_basic: Solver MAM requires either identical priorities or all "
872 "distinct priorities");
876 std::vector<PhService<T>> sl;
877 for (std::size_t j = 0; j < K; ++j) {
878 pa.Dc.push_back(aggr.Dc[iK[j]]);
879 sl.push_back(svc[i0][iK[j]]);
881 const std::vector<std::vector<T>> m = (sched_i == SchedStrategy::FCFSPRPRIO)
884 for (std::size_t j = 0; j < K; ++j) Qret[iK[j]] = m[j][0];
886 for (std::size_t r = 0; r < K; ++r)
887 Qret[r] = num_traits<T>::from_double(L.classes[r].population);
888 }
else if (anyopen) {
889 bool isMapDc = (K == 1) && (L.service[i0][0].type == ProcessType::DET);
894 std::size_t dmcSource = 0;
895 if (K == 1 && !isMapDc && L.service[i0][0].type == ProcessType::EXP) {
896 for (std::size_t j = 1; j <= M; ++j)
897 if (j != ist && L.service[j - 1][0].type == ProcessType::DET &&
898 mam_source_feeds_station(L, j, ist)) {
905 std::size_t phSource = 0;
906 if (K == 1 && !isMapDc && !isDMc && L.service[i0][0].type == ProcessType::EXP &&
907 std::isfinite(ns) && ns >= 1.0) {
908 for (std::size_t j = 1; j <= M; ++j) {
909 if (j == ist)
continue;
911 if (sp != ProcessType::EXP && sp != ProcessType::DET &&
912 sp != ProcessType::IMMEDIATE && sp != ProcessType::DISABLED) {
920 if (!mam_source_feeds_station(L, j, ist))
continue;
924 }
else if (sp == ProcessType::EXP && ns > 1.0 && M == 2 &&
925 L.nodes[L.node_of_station(j) - 1].nodetype == qn::NodeType::Source) {
958 const T muQ = T(one / S(i0, 0));
961 map_pie(src), src.D0, muQ,
static_cast<unsigned>(std::llround(ns)));
962 Qret[0] = r.meanQueueLength;
963 exactRespT = r.meanSojournTime;
965 }
catch (
const std::exception&) {
969 if (!exact_here && isDMc) {
971 const T muQ = T(one / S(i0, 0));
973 L.rates(dmcSource - 1, 0), muQ,
static_cast<unsigned>(std::llround(ns)));
974 Qret[0] = r.meanQueueLength;
975 exactRespT = r.meanSojournTime;
977 }
catch (
const std::exception&) {
981 if (!exact_here && !isFiniteCap && isMapDc) {
986 const qsys::MapDcResult<T> r =
988 Qret[0] = r.meanQueueLength;
989 exactRespT = r.meanSojournTime;
991 }
catch (
const std::exception&) {
1000 bool isMapMc = !exact_here && !isFiniteCap && (K == 1) && !isMapDc && !isDMc &&
1001 !isPhM1 && L.service[i0][0].type == ProcessType::EXP &&
1002 std::isfinite(ns) && ns > 1.0;
1008 const T muQ = T(one / S(i0, 0));
1009 const qsys::MapMcResult<T> r =
1011 Qret[0] = r.meanQueueLength;
1012 exactRespT = r.meanSojournTime;
1014 }
catch (
const std::exception&) {
1024 bool isMapPhc =
false, isMapMapc =
false;
1025 if (!exact_here && !isFiniteCap && K == 1 && std::isfinite(ns) && ns > 1.0) {
1027 if (st != ProcessType::EXP && st != ProcessType::DET && st != ProcessType::ME &&
1028 st != ProcessType::RAP && st != ProcessType::IMMEDIATE &&
1029 st != ProcessType::DISABLED) {
1034 isMapMapc = !isMapPhc && Sknown[i0][0];
1043 const qsys::MapPhcResult<T> r =
1045 static_cast<std::size_t
>(500),
static_cast<std::size_t
>(1));
1046 Qret[0] = r.meanQueueLength;
1047 exactRespT = r.meanSojournTime;
1049 }
catch (
const std::exception&) {
1062 arv,
map_pie(svc0), svc0.D0,
static_cast<unsigned>(std::llround(ns)),
1063 static_cast<std::size_t
>(500),
static_cast<std::size_t
>(1), std::vector<T>());
1064 Qret[0] = r.meanQueueLength;
1065 exactRespT = r.meanSojournTime;
1067 }
catch (
const std::exception&) {
1073 }
else if (isFiniteCap) {
1076 if (R != K && !(aggr.order() == 1))
throw UnsupportedError(ErrorKind{
"ClassSwitch"}, mark_refusal);
1077 const std::size_t capK =
static_cast<std::size_t
>(std::llround(L.cap[i0]));
1080 bool isMmck = (aggr.order() == 1);
1084 double lo = 0.0, hi = 0.0;
1085 for (std::size_t r = 0; r < K; ++r) {
1086 if (L.disabled[i0][r])
continue;
1087 if (L.service[i0][r].type != ProcessType::EXP) {
1091 const double v = num_traits<T>::to_double(L.rates(i0, r));
1092 if (!(v > 0.0))
continue;
1096 muMmck = L.rates(i0, r);
1098 lo = std::min(lo, v);
1099 hi = std::max(hi, v);
1102 if (!any) isMmck =
false;
1103 if (isMmck && hi - lo > 1e-9 * std::max(1.0, hi)) isMmck =
false;
1107 for (
const T& v : aggrLambda) lamTot += v;
1108 const qsys::MmckResult<T> r =
1109 qsys::qsys_mmck(lamTot, muMmck,
static_cast<unsigned>(std::llround(ns)),
1110 static_cast<unsigned>(capK));
1111 finiteCapMeanQ = r.meanQueueLength;
1112 finiteCapLossProb = r.lossProbability;
1113 }
else if (ns == 1.0) {
1117 std::vector<PhService<T>> sl;
1118 for (std::size_t r = 0; r < K; ++r) sl.push_back(svc[i0][r]);
1119 const qsys::ServiceLaw<T> mix = svc_mixture(aggr, sl);
1121 finiteCapMeanQ = r.meanQueueLength;
1122 finiteCapLossProb = r.lossAggregate;
1123 finiteCapLossPerClass = r.lossRatio;
1125 std::vector<PhService<T>> sl;
1126 for (std::size_t r = 0; r < K; ++r) sl.push_back(svc[i0][r]);
1127 const TruncRenorm<T> r = truncate_renorm(aggr, sl, capK);
1128 finiteCapMeanQ = r.meanQ;
1129 finiteCapLossProb = r.lossProb;
1131 finiteCapUsed =
true;
1132 exact_station[i0] =
true;
1133 }
else if (has_setup) {
1139 mam_setup_qbd(L, ist, aggrLambda, svc, S, rates, R, ns, setup_dist, delayoff_dist,
1147 (K == 1) && (ns == 1.0) && PHset[i0][0] &&
1148 std::fabs(num_traits<T>::to_double(
map_acf(PH[i0][0], std::vector<unsigned>{1})[0])) >
1152 std::vector<bool> corrSvc(K,
false);
1153 if (!corr) corrSvc = corr_service_classes(L, i0, PH[i0], PHset[i0]);
1154 const bool useCarried =
1155 std::find(corrSvc.begin(), corrSvc.end(),
true) != corrSvc.end();
1156 if (useCarried && !car_warned[i0]) {
1157 car_warned[i0] =
true;
1158 warn_carried(L, i0, corrSvc);
1163 arv.D1 = aggr.Dc[0];
1164 const QbdMapMap1Result<T> r =
qbd_mapmap1(arv, PH[i0][0]);
1166 }
else if (useCarried) {
1170 if (R != K)
throw UnsupportedError(ErrorKind{
"ClassSwitch"}, mark_refusal);
1171 std::vector<Map<T>> svcK(PH[i0].begin(), PH[i0].begin() + K);
1173 for (std::size_t r = 0; r < K; ++r) Qret[r] = cr.meanQueueLength[r];
1177 if (R != K)
throw UnsupportedError(ErrorKind{
"ClassSwitch"}, mark_refusal);
1183 bool gk_done =
false;
1184 if (ns == 1.0 && mam_gk1_applicable(L, i0, K)) {
1186 std::vector<Matrix<T>> MM;
1187 MM.push_back(aggr.D0);
1188 Matrix<T> D1sum(aggr.D0.rows(), aggr.D0.cols(),
1189 num_traits<T>::from_int(0));
1190 for (std::size_t r = 0; r < K; ++r)
1191 for (std::size_t a = 0; a < D1sum.rows(); ++a)
1192 for (std::size_t b = 0; b < D1sum.cols(); ++b)
1193 D1sum(a, b) += aggr.Dc[r](a, b);
1194 MM.push_back(D1sum);
1195 for (std::size_t r = 0; r < K; ++r) MM.push_back(aggr.Dc[r]);
1196 std::vector<lang::Distrib<T>> laws;
1197 for (std::size_t r = 0; r < K; ++r)
1198 laws.push_back(mam_declared_law(L.service[i0][r]));
1200 MM, laws, std::vector<T>(),
static_cast<std::size_t
>(1), 1e-12,
1201 static_cast<std::size_t
>(10000));
1202 for (std::size_t r = 0; r < K; ++r)
1203 Qret[r] = gk.lambdas[r] * gk.meanSojournTime[r];
1210 }
catch (
const std::exception&) {
1215 std::vector<PhService<T>> sl;
1216 for (std::size_t r = 0; r < R; ++r) sl.push_back(svc[i0][r]);
1218 for (std::size_t r = 0; r < K; ++r) Qret[r] = m[r];
1226 std::size_t maxLevel = 1;
1227 for (std::size_t r = 0; r < K; ++r)
1228 if (std::isfinite(L.classes[r].population))
1229 maxLevel +=
static_cast<std::size_t
>(std::llround(L.classes[r].population));
1234 const Map<T> probe = aggr.map();
1236 for (std::size_t r = 0; r < K; ++r)
1237 Qret[r] = (L.rates(i0, 0) > zero)
1241 }
else if (has_setup) {
1248 mam_setup_closed(L, ist, svc, S, rates, ztchain, V, ns, setup_dist, delayoff_dist,
1252 if (R != K)
throw UnsupportedError(ErrorKind{
"ClassSwitch"}, mark_refusal);
1256 const std::vector<bool> corrC = corr_service_classes(L, i0, PH[i0], PHset[i0]);
1257 if (std::find(corrC.begin(), corrC.end(),
true) != corrC.end() && !car_warned[i0]) {
1258 car_warned[i0] =
true;
1259 std::cerr <<
"[LINE] Warning: Station " << L.stations[i0].name
1260 <<
" has a correlated MAP service (class " << class_names(L, corrC)
1261 <<
") in a closed chain. The closed decomposition reads it through "
1262 <<
"its renewal marginal, which discards the autocorrelation; method "
1263 <<
"'ldqbd' carries it exactly on a single-class Delay+Queue model, "
1264 <<
"and SolverCTMC on any model.\n";
1266 std::vector<PhService<T>> sl;
1267 for (std::size_t r = 0; r < R; ++r) sl.push_back(svc[i0][r]);
1269 for (std::size_t r = 0; r < K; ++r) {
1270 const std::size_t Nk =
1271 static_cast<std::size_t
>(std::llround(L.classes[r].population));
1272 std::vector<T> p(Nk + 1, zero);
1273 const std::vector<T>& src = pd[r];
1275 for (std::size_t n = 0; n < Nk; ++n) {
1281 p[Nk] =
num_abs(T(one - acc));
1283 for (std::size_t n = 0; n <= Nk; ++n) mass += p[n];
1286 for (std::size_t n = 0; n <= Nk; ++n)
1287 m += num_traits<T>::from_int((
int)n) * T(p[n] / mass);
1288 if (m < zero) m = zero;
1289 if (num_traits<T>::to_double(m) >
static_cast<double>(Nk))
1290 m = num_traits<T>::from_int((
int)Nk);
1297 if (finiteCapUsed) {
1300 std::vector<T> inflow(K, zero), eff(K, zero);
1301 for (std::size_t r = 0; r < K; ++r) {
1303 for (std::size_t cc = 0; cc < C; ++cc)
1304 if (L.chains[cc][r]) {
1308 inflow[r] = rates[c][r];
1309 const T loss = finiteCapLossPerClass.empty() ? finiteCapLossProb
1310 : finiteCapLossPerClass[r];
1311 eff[r] = T(inflow[r] * T(one - loss));
1314 for (std::size_t r = 0; r < K; ++r) sumTN += eff[r];
1318 for (std::size_t r = 0; r < K; ++r)
1319 if (Sknown[i0][r]) sw += eff[r] * S(i0, r);
1320 const T w = T(T(finiteCapMeanQ / sumTN) - T(sw / sumTN));
1321 Wq = (w > zero) ? w : zero;
1323 for (std::size_t r = 0; r < K; ++r) {
1325 UN(i0, r) = T(TN(i0, r) * S(i0, r) / num_traits<T>::from_double(ns));
1326 if (TN(i0, r) > zero) {
1327 RN(i0, r) = T(Wq + S(i0, r));
1328 QN(i0, r) = T(TN(i0, r) * RN(i0, r));
1335 for (std::size_t r = 0; r < K; ++r) {
1337 for (std::size_t cc = 0; cc < C; ++cc)
1338 if (L.chains[cc][r]) {
1342 TN(i0, r) = rates[c][r];
1343 UN(i0, r) = T(TN(i0, r) * S(i0, r) / num_traits<T>::from_double(ns));
1344 QN(i0, r) = Qret[r];
1346 RN(i0, r) = exactRespT;
1347 exact_station[i0] =
true;
1351 if (Sknown[i0][r] && std::isfinite(ns))
1352 QN(i0, r) = T(
QN(i0, r) + TN(i0, r) * S(i0, r) *
1353 num_traits<T>::from_double((ns - 1.0) / ns));
1354 RN(i0, r) = (TN(i0, r) > zero) ? T(
QN(i0, r) / TN(i0, r)) : zero;
1373 "solver_mam_basic: the matrix-analytic station solves run tolerance-terminated "
1374 "iterations (the Riccati doubling behind MMAP[K]/PH[K]/1, the QBD cyclic reduction) "
1375 "and need transcendental arithmetic; rerun this model with --arith double or "
1378 using namespace basic_detail;
1381 const double tol =
opt.tol;
1385 std::vector<std::vector<bool>> Sknown(M, std::vector<bool>(K,
false));
1386 for (std::size_t i = 0; i < M; ++i)
1387 for (std::size_t r = 0; r < K; ++r)
1389 S(i, r) = T(one / L.
rates(i, r));
1390 Sknown[i][r] =
true;
1398 std::vector<T> ztchain(C, zero);
1399 for (std::size_t c = 0; c < C; ++c)
1400 for (std::size_t i = 0; i < M; ++i)
1401 if (std::isinf(L.
stations[i].nservers)) ztchain[c] += dem.
Lchain(i, c);
1403 Matrix<T> QN(M, K, zero), UN(M, K, zero), RN(M, K, zero), TN(M, K, zero);
1404 std::vector<T> CN(K, zero), XN(K, zero);
1405 std::vector<bool> exact_station(M,
false);
1406 std::vector<bool> car_warned(M,
false);
1410 std::vector<std::vector<Map<T>>> PH(M, std::vector<
Map<T>>(K));
1411 std::vector<std::vector<bool>> PHset(M, std::vector<bool>(K,
false));
1412 std::vector<std::vector<PhService<T>>> svc(M, std::vector<
PhService<T>>(K));
1413 for (std::size_t i = 0; i < M; ++i) {
1415 if (!(sc == SchedStrategy::FCFS || sc == SchedStrategy::HOL ||
1416 sc == SchedStrategy::FCFSPRPRIO || sc == SchedStrategy::PS))
1418 for (std::size_t r = 0; r < K; ++r) {
1419 if (L.
service[i][r].type == ProcessType::DET &&
opt.preserve_det_resolved())
continue;
1420 const double ns = L.
stations[i].nservers;
1423 if (L.
disabled[i][r] || !Sknown[i][r] || !(target > zero)) {
1432 svc[i][r].sigma.assign(1, one);
1441 PH[i][r] = (pt == ProcessType::ME || pt == ProcessType::RAP)
1445 svc[i][r].sigma =
map_pie(PH[i][r]);
1446 svc[i][r].S = PH[i][r].D0;
1451 std::vector<bool> isopenchain(C,
false), isclosedchain(C,
false);
1452 std::vector<T> lambda(C, zero);
1453 std::vector<Mmap<T>> chainSysArrivals(C);
1454 for (std::size_t c = 0; c < C; ++c) {
1457 for (std::size_t r : L.
inchain[c]) {
1458 const double n = L.
classes[r - 1].population;
1459 if (std::isinf(n)) inf =
true;
1463 isopenchain[c] = inf;
1464 isclosedchain[c] = !inf;
1469 std::vector<Mmap<T>> parts;
1470 for (std::size_t r : L.
inchain[c]) {
1472 if (L.
disabled[ist - 1][r - 1] || !(L.
rates(ist - 1, r - 1) > zero)) {
1482 m.
Dc.assign(1, src.
D1);
1483 lambda[c] += L.
rates(ist - 1, r - 1);
1487 chainSysArrivals[c] = parts[0];
1488 for (std::size_t p = 1; p < parts.size(); ++p)
1490 std::vector<
Mmap<T>>{chainSysArrivals[c], parts[p]},
opt.space_max);
1491 for (std::size_t r : L.
inchain[c])
1492 TN(ist - 1, r - 1) = L.
disabled[ist - 1][r - 1] ? zero : L.
rates(ist - 1, r - 1);
1495 std::vector<bool> finite_srv(M,
false);
1496 for (std::size_t i = 0; i < M; ++i) finite_srv[i] = std::isfinite(L.
stations[i].nservers);
1498 bool ismixed =
false;
1500 bool anyc =
false, anyo =
false;
1501 for (std::size_t c = 0; c < C; ++c) {
1502 anyc = anyc || isclosedchain[c];
1503 anyo = anyo || isopenchain[c];
1505 ismixed = anyc && anyo;
1510 std::vector<std::size_t> all_classes(K);
1511 for (std::size_t r = 0; r < K; ++r) all_classes[r] = r + 1;
1512 auto resptime_floor = [&](
const std::vector<std::size_t>& rlist) {
1513 for (std::size_t i = 0; i < M; ++i) {
1514 if (exact_station[i])
continue;
1515 for (std::size_t r : rlist) {
1516 const std::size_t k = r - 1;
1517 if (V(i, k) > zero) {
1518 if (!finite_srv[i]) {
1521 const T byLittle = (TN(i, k) > zero) ? T(QN(i, k) / TN(i, k)) : zero;
1522 RN(i, k) = (S(i, k) > byLittle) ? S(i, k) : byLittle;
1527 QN(i, k) = T(RN(i, k) * TN(i, k));
1534 double delta = std::numeric_limits<double>::infinity();
1536 while (delta > tol && it <=
opt.iter_max) {
1540 for (std::size_t i = 0; i < M; ++i) {
1541 if (!finite_srv[i])
continue;
1543 for (std::size_t r = 0; r < K; ++r) s += num_traits<T>::to_double(UN(i, r));
1544 if (s > Umax) Umax = s;
1546 if (ismixed || Umax < 1.0) {
1547 for (std::size_t c = 0; c < C; ++c) {
1548 if (!isclosedchain[c])
continue;
1550 for (std::size_t r : L.
inchain[c]) Nc += L.
classes[r - 1].population;
1552 for (std::size_t i = 0; i < M; ++i)
1554 QNc = std::max(tol, QNc);
1556 for (std::size_t i = 0; i < M; ++i) Dsum += dem.
Lchain(i, c);
1563 const double w =
static_cast<double>(it) /
opt.iter_max;
1572 bool binding =
false;
1573 for (std::size_t i = 0; i < M; ++i) {
1574 if (!finite_srv[i])
continue;
1575 double Uopen = 0.0, Uclosed = 0.0;
1576 for (std::size_t c = 0; c < C; ++c) {
1579 if (isclosedchain[c]) Uclosed += u;
1582 if (Uclosed > tol) {
1584 theta = std::min(theta, (Ulim - Uopen) / Uclosed);
1587 if (binding && theta < 1.0)
1588 for (std::size_t c = 0; c < C; ++c)
1589 if (isclosedchain[c])
1591 }
else if (Umax >= 1.0) {
1592 for (std::size_t c = 0; c < C; ++c)
1596 for (std::size_t c = 0; c < C; ++c) {
1597 if (isclosedchain[c]) {
1601 chainSysArrivals[c] =
1604 for (std::size_t i = 0; i < M; ++i)
1605 for (std::size_t r : L.
inchain[c]) TN(i, r - 1) = T(V(i, r - 1) * lambda[c]);
1608 for (std::size_t ind = 1; ind <= I; ++ind) {
1610 if (nd.
station == 0)
continue;
1611 const std::size_t ist = nd.
station;
1612 if (nd.
nodetype == qn::NodeType::Join) {
1613 for (std::size_t c = 0; c < C; ++c)
1614 for (std::size_t r : L.
inchain[c]) {
1615 std::size_t fanin = 0;
1617 for (std::size_t row = 0; row < L.
rtnodes.rows(); ++row)
1618 if (L.
rtnodes(row, (ind - 1) * K + (r - 1)) != zero) ++fanin;
1619 if (fanin == 0) fanin = 1;
1620 TN(ist - 1, r - 1) =
1622 UN(ist - 1, r - 1) = zero;
1623 QN(ist - 1, r - 1) = zero;
1624 RN(ist - 1, r - 1) = zero;
1629 const double ns = L.
stations[ist - 1].nservers;
1630 if (sched == SchedStrategy::INF) {
1631 for (std::size_t c = 0; c < C; ++c)
1632 for (std::size_t r : L.
inchain[c]) {
1633 const std::size_t k = r - 1;
1634 if (!(V(ist - 1, k) > zero)) {
1635 TN(ist - 1, k) = UN(ist - 1, k) = QN(ist - 1, k) = RN(ist - 1, k) = zero;
1638 TN(ist - 1, k) = T(lambda[c] * V(ist - 1, k));
1641 UN(ist - 1, k) = T(S(ist - 1, k) * TN(ist - 1, k));
1642 QN(ist - 1, k) = T(TN(ist - 1, k) * S(ist - 1, k));
1643 RN(ist - 1, k) = (TN(ist - 1, k) > zero)
1644 ? T(QN(ist - 1, k) / TN(ist - 1, k))
1647 }
else if (sched == SchedStrategy::PS) {
1648 for (std::size_t c = 0; c < C; ++c) {
1649 for (std::size_t r : L.
inchain[c]) {
1650 const std::size_t k = r - 1;
1651 if (!(V(ist - 1, k) > zero)) {
1652 TN(ist - 1, k) = UN(ist - 1, k) = zero;
1655 TN(ist - 1, k) = T(lambda[c] * V(ist - 1, k));
1656 UN(ist - 1, k) = T(S(ist - 1, k) * TN(ist - 1, k) /
1660 for (std::size_t k = 0; k < K; ++k) Uden += num_traits<T>::to_double(UN(ist - 1, k));
1662 for (std::size_t r : L.
inchain[c]) {
1663 const std::size_t k = r - 1;
1664 if (!(V(ist - 1, k) > zero)) {
1665 QN(ist - 1, k) = RN(ist - 1, k) = zero;
1670 RN(ist - 1, k) = (TN(ist - 1, k) > zero)
1671 ? T(QN(ist - 1, k) / TN(ist - 1, k))
1675 }
else if (sched == SchedStrategy::FCFS || sched == SchedStrategy::HOL ||
1676 sched == SchedStrategy::FCFSPRPRIO) {
1677 solve_fcfs_station(L,
opt, ist, lambda, V, S, Sknown, PH, PHset, svc,
1678 chainSysArrivals, ztchain, QN, UN, RN, TN, exact_station,
1680 }
else if (sched != SchedStrategy::EXT) {
1687 std::string(
"solver_mam_basic: station '") + L.
stations[ist - 1].name +
1689 " discipline, which the dec.source decomposition does not model (it solves "
1690 "INF, PS, FCFS and HOL stations only)");
1695 resptime_floor(all_classes);
1698 for (std::size_t i = 0; i < M; ++i)
1699 for (std::size_t r = 0; r < K; ++r)
1705 for (std::size_t i = 0; i < M; ++i)
1706 for (std::size_t r = 0; r < K; ++r) QN(i, r) =
num_abs(QN(i, r));
1707 for (
int pass = 0; pass < 2; ++pass) {
1708 for (std::size_t c = 0; c < C; ++c) {
1711 for (std::size_t r : L.
inchain[c]) {
1712 if (std::isinf(L.
classes[r - 1].population)) closed =
false;
1713 else Nc += L.
classes[r - 1].population;
1717 for (std::size_t i = 0; i < M; ++i)
1718 for (std::size_t r : L.
inchain[c]) QNc += QN(i, r - 1);
1721 for (std::size_t i = 0; i < M; ++i)
1722 for (std::size_t r : L.
inchain[c]) QN(i, r - 1) *= f;
1726 if (closed && Nc == 0.0) {
1727 for (std::size_t i = 0; i < M; ++i)
1728 for (std::size_t r : L.
inchain[c]) {
1729 QN(i, r - 1) = UN(i, r - 1) = RN(i, r - 1) = TN(i, r - 1) = zero;
1731 for (std::size_t r : L.
inchain[c]) CN[r - 1] = XN[r - 1] = zero;
1736 for (std::size_t r = 0; r < K; ++r) {
1738 for (std::size_t i = 0; i < M; ++i) s += RN(i, r);
1741 for (std::size_t c = 0; c < C; ++c)
1742 for (std::size_t r : L.
inchain[c]) XN[r - 1] = TN(L.
classes[r - 1].refstat - 1, r - 1);
Acyclic phase-type fitters from the first two moments.
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
std::size_t nof_nodes() const
std::vector< std::vector< Distrib< T > > > service
service[i][r], 0-based station and class; a disabled entry marks a pair never visited.
std::vector< std::vector< bool > > disabled
std::vector< JobClass > classes
std::vector< Station< T > > stations
stations[k-1] is the k-th station
Matrix< T > rates
(nstations x nclasses) service rates and SCVs, with a PARALLEL disabled flag instead of MATLAB's NaN ...
std::vector< std::vector< std::size_t > > inchain
1-based class indices per chain
std::vector< NodeDef > nodes
every node, in creation order
Steady-state distribution of a continuous-time Markov chain.
What refreshProcessRepresentations and refreshLST compute FROM a distribution: the (D0,...
The exception types the port throws.
The option and result types SolverMAM shares with its analyzers.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
The MMAP assembly primitives solver_mam_basic.m builds its per-station arrival stream from: mmap_expo...
Marked MAP (MMAP) algebra: per-class rates, class probabilities, superposition, normalization and sca...
The MMAP[K]/PH[K]/1 FCFS queue: per-class mean number in system and per-class queue-length distributi...
The MMAP[K]/PH[K]/1 priority queue, preemptive resume (mmapph1prpr_*) and non-preemptive (mmapph1nppr...
SnRtStations< T > sn_rt_stations(const qn::NetworkStruct< T > &sn)
mam::Map< T > dist_to_map(const Distrib< T > &d)
The (D0,D1) pair that reaches sn.proc.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
ProcessType
Distribution kinds, with the values of MATLAB ProcessType.
const char * sched_to_text(SchedStrategy s)
double tot(const std::vector< double > &pops)
std::string name(const Element *el, const std::string &key="name")
std::vector< T > map_acf(const Map< T > &m, const std::vector< unsigned > &lags)
Autocorrelation coefficients of the inter-arrival times at the given lags,.
Mmap< T > mmap_normalize(const Mmap< T > &in)
Clamp negative off-diagonal and per-class entries to zero and rebuild D1 and the diagonal of D0 from ...
std::vector< T > mmapph1fcfs_ncmean(const Mmap< T > &arrival, const std::vector< PhService< T > > &svc)
Per-class mean number of customers in the system, BUTools' 'ncMoms', 1.
std::vector< T > mmap_lambda(const Mmap< T > &m)
Alias kept for parity with the MATLAB name.
Mmap< T > mmap_mark_probs(const Mmap< T > &in, const Matrix< T > &prob)
Re-mark an MMAP by a (K x R) probability matrix (mmap_mark.m): a type-k arrival is reported as class ...
Mmap< T > mmap_scale_perclass(const Mmap< T > &in, const std::vector< T > &M)
Retarget the per-class MEAN inter-arrival times (mmap_scale.m, vector form).
QbdMapMap1Result< T > qbd_mapmap1(const Map< T > &arrival, const Map< T > &service_in, const T &util, std::size_t max_levels)
MAP/MAP/1 queue (qbd_mapmap1.m).
T qbd_setupdelayoff(const T &lambda, const T &mu, const T &alpharate, const T &alphascv, const T &betarate, const T &betascv)
Mean queue length of the M/M/1 queue with setup delay and delay-off (qbd_setupdelayoff....
Mmap< T > mmap_exponential_vec(const std::vector< T > &lambda, std::size_t n=1)
Order-n MMAP with the given per-class arrival rates (mmap_exponential.m).
mva::MvaSolution< T > solver_mam_basic(const qn::NetworkStruct< T > &L, const MamOptions &opt)
Port of solver_mam_basic.m.
std::vector< std::vector< T > > mmapph1prpr_ncmoms(const Mmap< T > &arrival, const std::vector< PhService< T > > &svc, std::size_t n, const PrioQueueOptions &opt=PrioQueueOptions())
Per-class moments 1..n of the number of jobs, MMAP[K]/PH[K]/1 preemptive resume priority.
std::vector< std::vector< T > > mmapph1fcfs_ncdistr(const Mmap< T > &arrival, const std::vector< PhService< T > > &svc, std::size_t levels)
Per-class queue-length distribution, BUTools' 'ncDistr', n: P(N_k = 0..n-1).
Map< T > map_exponential_mean(const T &mean)
Poisson process with the given mean inter-arrival time (map_exponential.m).
Map< T > map_scale_rate(const Map< T > &in, const T &new_mean)
Rescale to a target mean WITHOUT the feasibility repair, for a matrix exponential.
Map< T > map_scale(const Map< T > &in, const T &new_mean)
Rescale time so that the mean inter-arrival time becomes new_mean.
std::vector< T > map_pie(const Map< T > &m)
Phase distribution seen by an arriving job, pie = pi D1 / (pi D1 e).
T map_scv(const Map< T > &m)
Squared coefficient of variation.
SetupDelayoffClosed< T > qbd_setupdelayoff_closed(const T &N, const T &Z, const T &mu, const T &alpharate, const T &alphascv, const T &betarate, const T &betascv)
Mean queue length and throughput of a FINITE-POPULATION queue with setup delay and delay-off,...
T map_lambda(const Map< T > &m)
Stationary arrival rate, lambda = pi D1 e.
std::vector< std::vector< T > > mmapph1nppr_ncmoms(const Mmap< T > &arrival, const std::vector< PhService< T > > &svc, std::size_t n, const PrioQueueOptions &opt=PrioQueueOptions())
Per-class moments 1..n of the number of jobs, MMAP[K]/PH[K]/1 non-preemptive priority.
Mmap< T > mmap_super_safe(const std::vector< Mmap< T > > &in, std::size_t maxorder)
Order-bounded superposition of several MMAPs (mmap_super_safe.m).
std::vector< T > ctmc_solve(const Matrix< T > &Qin)
Steady-state distribution of a continuous-time Markov chain.
ChainDemands< T > sn_get_demands_chain(const qn::NetworkStruct< T > &L)
Port of sn_get_demands_chain.
MapMcResult< T > qsys_mapmc(const mam::Map< T > &arrival, const T &mu, unsigned c, std::size_t dist_size)
MAP/M/c by the matrix-geometric solution.
MapPhcResult< T > qsys_mapmapc(const mam::Map< T > &arrival, const mam::Map< T > &service, unsigned c, std::size_t dist_size=500, std::size_t num_w_moms=3)
MAP/MAP/c FCFS with the service phase carried in start order, exactly.
MmapGk1Result< T > qsys_mmapgk1(const std::vector< Matrix< T > > &MMAP, const std::vector< MmapGk1Service< T > > &svc, const std::vector< T > &w_points, std::size_t num_w_moms, double tol, std::size_t iter_max, std::size_t quad_nodes)
MMAP[K]/G[K]/1 FCFS, per type.
MmckResult< T > qsys_mmck(const T &lambda, const T &mu, unsigned c, unsigned K)
Exact analysis of the M/M/c/K queue (truncated Erlang form).
MapPhcResult< T > qsys_mapphc(const mam::Map< T > &arrival, const std::vector< T > &alpha, const Matrix< T > &S, unsigned c, std::size_t dist_size, std::size_t num_w_moms, const std::vector< T > &w_points)
MAP/PH/c FCFS, exactly.
MmapMap1Result< T > qsys_mmapmap1(const mam::Mmap< T > &arrival, const std::vector< mam::Map< T > > &svc, std::vector< bool > carry=std::vector< bool >())
MMAP[K]/MAP[K]/1 FCFS with per-class carried service phases, exactly.
MmapG1kResult< T > qsys_mmapg1k(const Matrix< T > &D0, const std::vector< Matrix< T > > &D1c, const ServiceLaw< T > &svc, std::size_t K, const T &tol, std::size_t nmaxCap)
MMAP[K]/G/1/K with tail drop.
DmcResult< T > qsys_dmc(const T &lambda, const T &mu, unsigned c, unsigned truncation, unsigned quadSteps)
D/M/c: deterministic interarrival times, exponential service.
PhMcResult< T > qsys_phmc(const std::vector< T > &alpha, const Matrix< T > &Tm, const T &mu, unsigned c, unsigned maxIter, const T &tol)
Exact PH/M/c by Neuts' matrix-geometric method.
MapDcResult< T > qsys_mapdc(const mam::Map< T > &arrival, const T &s, unsigned c, std::size_t dist_size, unsigned max_arrivals, std::size_t max_levels, const T &tol, std::size_t num_steps)
MAP/D/c by Crommelin's exact embedded lattice chain.
double sn_get_buffer_size(const qn::NetworkStruct< T > &sn, std::size_t ist)
Physical buffer size of a station, in jobs, the one in service included.
Conservation laws of a layered queueing network, enumerated from its structure.
std::vector< T > vecmul(const std::vector< T > &v, const Matrix< T > &A)
Row vector times matrix, v A.
Matrix< T > inverse(const Matrix< T > &A)
Inverse by LU with one factorization and n back substitutions.
A queueing network and its refreshed NetworkStruct.
The MAP/MAP/1 queue solved as a quasi-birth-death process.
Mean queue length of an M/M/1 queue with a setup delay and a delayed-off period, solved as a QBD.
D/M/c: deterministic interarrival times, exponential service.
The MAP/D/c FCFS queue: c servers, deterministic service of length s, fed by a Markovian arrival proc...
The MAP/MAP/c FCFS queue whose service MAP is CARRIED in service-start order.
The MAP/M/c FCFS queue: c identical exponential servers of rate mu fed by a Markovian arrival process...
The MAP/PH/c FCFS queue, solved exactly.
Exact per-class throughput and loss ratio of an MMAP[K]/G/1/K tail-drop queue.
The MMAP[K]/G[K]/1 FCFS queue: K customer types with class-dependent GENERAL service,...
The MMAP[K]/MAP[K]/1 FCFS queue in which each class's service phase is CARRIED.
Exact analysis of the M/M/c/K queue (truncated Erlang form).
Exact PH/M/c by Neuts' matrix-geometric method.
Chain aggregation and de-aggregation.
Physical buffer size of a station, in jobs, the one in service included.
Port of matlab/src/api/sn/sn_rt_stations.m.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
static constexpr double Immediate
Rate of an Immediate distribution; its mean is 1/Immediate = 1e-8.
static constexpr double FineTol
static constexpr double CoarseTol
The options SolverMAM reads.
A MAP as the pair of matrices (D0, D1).
An MMAP: the underlying MAP plus the per-class arrival matrices.
std::vector< Matrix< T > > Dc
per-class matrices, sum_c Dc = D1
One class's phase-type service law, He's (sigma_k, S_k).
The chain-level view of a layer, as sn_get_demands_chain returns it.
Matrix< T > Lchain
(M x C) demand
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
static ServiceLaw phase_type(const std::vector< T > &alpha, const Matrix< T > &Tmat)
Phase type (alpha, Tmat).