5#ifndef LINE_SOLVERS_NC_SOLVER_NC_OI_H
6#define LINE_SOLVERS_NC_SOLVER_NC_OI_H
75inline void oi_lattice(
const std::vector<int>& N, std::vector<std::size_t>& shp,
76 std::vector<std::size_t>& stride, std::size_t& total) {
77 const std::size_t R = N.size();
81 for (std::size_t d = 0; d < R; ++d) shp[d] = static_cast<std::size_t>(N[d]) + 1;
82 for (std::size_t d = 1; d < R; ++d) stride[d] = stride[d - 1] * shp[d - 1];
83 for (std::size_t d = 0; d < R; ++d) total *= shp[d];
87inline std::vector<int> oi_sub(std::size_t i,
const std::vector<std::size_t>& shp) {
88 std::vector<int> n(shp.size(), 0);
90 for (std::size_t d = 0; d < shp.size(); ++d) {
91 n[d] =
static_cast<int>(li % shp[d]);
98inline std::size_t oi_idx(
const std::vector<int>& n,
const std::vector<std::size_t>& stride) {
100 for (std::size_t d = 0; d < n.size(); ++d) i += stride[d] *
static_cast<std::size_t
>(n[d]);
108inline std::vector<std::size_t> oi_microstate(
const std::vector<int>& n) {
109 std::vector<std::size_t> c;
110 for (std::size_t r = 0; r < n.size(); ++r)
111 for (
int a = 0; a < n[r]; ++a) c.push_back(r + 1);
116const std::size_t OI_RANK_RATE_MEMO_LIMIT = 1u << 17;
131 const std::function<T(
const std::vector<std::size_t>&)>& f) {
132 std::shared_ptr<std::map<std::vector<int>, T> > memo(
new std::map<std::vector<int>, T>());
133 return [f, memo](
const std::vector<int>& n) -> T {
134 const typename std::map<std::vector<int>, T>::const_iterator it = memo->find(n);
135 if (it != memo->end())
return it->second;
136 const T v = f(oi_microstate(n));
137 if (memo->size() < OI_RANK_RATE_MEMO_LIMIT) (*memo)[n] = v;
147std::vector<T> oi_phi(
const std::function<T(
const std::vector<int>&)>& oirate,
148 const std::vector<int>& N) {
149 std::vector<std::size_t> shp, stride;
150 std::size_t total = 0;
151 oi_lattice(N, shp, stride, total);
152 const std::size_t R = shp.size();
153 std::vector<T> Phi(total, num_traits<T>::from_int(0));
154 for (std::size_t i = 0; i < total; ++i) {
155 const std::vector<int> n = oi_sub(i, shp);
157 for (
int v : n)
tot += v;
159 Phi[i] = num_traits<T>::from_int(1);
162 T s = num_traits<T>::from_int(0);
163 for (std::size_t r = 0; r < R; ++r)
164 if (n[r] > 0) s += Phi[i - stride[r]];
165 Phi[i] = T(s / oirate(n));
177std::vector<T> oi_ld_table(
const std::vector<T>& Dq,
double c,
178 const std::vector<std::size_t>& shp, std::size_t total) {
179 const std::size_t R = shp.size();
180 std::vector<T> W(total, num_traits<T>::from_int(0));
181 const double cc = (std::isfinite(c) && c > 0.0) ? c : 1.0;
182 for (std::size_t i = 0; i < total; ++i) {
183 const std::vector<int> n = oi_sub(i, shp);
185 for (
int v : n)
tot += v;
186 double logf = std::lgamma(
static_cast<double>(tot) + 1.0);
188 for (std::size_t r = 0; r < R; ++r)
190 const double d = num_traits<T>::to_double(Dq[r]);
195 logf += n[r] * std::log(d) - std::lgamma(
static_cast<double>(n[r]) + 1.0);
198 for (
int k = 1; k <=
tot; ++k)
199 logf -= std::log(std::min(
static_cast<double>(k), cc));
200 W[i] = num_traits<T>::from_double(std::exp(logf));
207std::vector<T> oi_conv(
const std::vector<T>& A,
const std::vector<T>& B,
208 const std::vector<std::size_t>& shp,
209 const std::vector<std::size_t>& stride, std::size_t total) {
210 const std::size_t R = shp.size();
211 std::vector<std::vector<int>> subs(total);
212 for (std::size_t i = 0; i < total; ++i) subs[i] = oi_sub(i, shp);
213 std::vector<T> C(total, num_traits<T>::from_int(0));
214 for (std::size_t i = 0; i < total; ++i) {
215 T acc = num_traits<T>::from_int(0);
216 for (std::size_t j = 0; j <= i; ++j) {
218 for (std::size_t d = 0; d < R && le; ++d)
219 if (subs[j][d] > subs[i][d]) le =
false;
222 for (std::size_t d = 0; d < R; ++d)
223 off += stride[d] *
static_cast<std::size_t
>(subs[i][d] - subs[j][d]);
224 acc += T(A[j] * B[off]);
233T oi_fnc_mean(
const std::vector<T>& Psi,
const std::vector<T>& Gfull,
234 const std::vector<std::size_t>& shp,
const std::vector<std::size_t>& stride,
236 const T
zero = num_traits<T>::from_int(0);
238 for (std::size_t i = 0; i < total; ++i) {
239 if (Psi[i] == zero)
continue;
240 const std::vector<int> b = oi_sub(i, shp);
242 for (std::size_t d = 0; d < shp.size(); ++d)
243 off += stride[d] * (shp[d] - 1 -
static_cast<std::size_t
>(b[d]));
244 val += T(Psi[i] * Gfull[off]);
251Matrix<T> oi_visits(
const qn::NetworkStruct<T>& sn) {
252 const T
zero = num_traits<T>::from_int(0);
253 const std::size_t M = sn.nstations, K = sn.nclasses;
254 Matrix<T> V(M, K, zero);
255 for (std::size_t r = 0; r < K; ++r) {
256 std::size_t chain = 0;
257 for (std::size_t c = 0; c < sn.nchains; ++c)
258 if (sn.chains[c][r]) chain = c + 1;
259 if (chain == 0)
continue;
260 for (std::size_t i = 0; i < M; ++i)
261 V(i, r) = sn.visits[chain - 1](sn.stateful_of_station(i + 1) - 1, r);
262 const T vref = V(sn.classes[r].refstat - 1, r);
264 for (std::size_t i = 0; i < M; ++i) V(i, r) = T(V(i, r) / vref);
271bool class_dependent_fcfs_rate(
const qn::NetworkStruct<T>& sn, std::size_t i) {
272 double lo = 0.0, hi = 0.0;
274 for (std::size_t r = 0; r < sn.nclasses; ++r) {
275 if (!(sn.classes[r].population > 0.0))
continue;
276 const double v = num_traits<T>::to_double(sn.rates(i, r));
277 if (!std::isfinite(v))
continue;
282 lo = std::min(lo, v);
283 hi = std::max(hi, v);
286 return any && (hi - lo) > 1e-9 * hi;
305 for (std::size_t i = 0; i <
sn.nstations; ++i) {
307 if (s == SchedStrategy::INF ||
sn.stations[i].nodetype == qn::NodeType::Source)
continue;
308 if (s == SchedStrategy::PAS || s == SchedStrategy::OI) {
311 }
else if (s == SchedStrategy::PS || s == SchedStrategy::LCFSPR ||
312 s == SchedStrategy::SIRO || s == SchedStrategy::FCFS) {
313 if ((s == SchedStrategy::FCFS || s == SchedStrategy::SIRO) &&
314 detail::class_dependent_fcfs_rate(
sn, i))
336 if (
sn.nstations != 2)
return false;
337 for (std::size_t i = 0; i <
sn.nstations; ++i) {
339 if (s != SchedStrategy::PAS && s != SchedStrategy::OI)
return false;
340 if (!
sn.stations[i].svc_rate_fun)
return false;
349std::vector<T> oi_mixed_delay_table(
const std::vector<double>& Z,
350 const std::vector<std::size_t>& shp, std::size_t total) {
352 for (std::size_t k = 0; k < total; ++k) {
353 const std::vector<int> c = oi_sub(k, shp);
356 for (std::size_t a = 0; a < c.size(); ++a)
362 lw += c[a] * std::log(Z[a]) - std::lgamma(c[a] + 1.0);
364 if (ok) W[k] = num_traits<T>::from_double(std::exp(lw));
377bool oi_mixed_bcmp_table(
const std::vector<double>& D,
const std::vector<double>& rhoO,
double csrv,
378 const std::vector<std::size_t>& shp, std::size_t total,
379 const std::vector<std::size_t>& closedIdx, std::size_t K,
380 std::vector<T>& W, Matrix<T>& H) {
381 W.assign(total, num_traits<T>::from_int(0));
382 H =
Matrix<T>(total, K, num_traits<T>::from_int(0));
384 for (
double v : rhoO) ro += v;
385 if (!(ro < csrv))
return false;
386 for (std::size_t k = 0; k < total; ++k) {
387 const std::vector<int> c = oi_sub(k, shp);
390 for (std::size_t a = 0; a < c.size(); ++a) {
392 if (c[a] > 0 && !(D[a] > 0.0)) ok =
false;
395 double logb = std::lgamma(n + 1.0);
396 for (std::size_t a = 0; a < c.size(); ++a)
397 if (c[a] > 0) logb += c[a] * std::log(D[a]) - std::lgamma(c[a] + 1.0);
398 for (
int j = 1; j <= n; ++j) logb -= std::log(std::min(
static_cast<double>(j), csrv));
400 double s0 = 1.0, s1 = 0.0, t = 1.0;
404 t = t * (n + kk + 1) / (kk + 1) * ro / std::min(
static_cast<double>(n + kk + 1), csrv);
408 if (kk > csrv && t < 1e-17 * s0 &&
409 kk * t < 1e-17 * std::max(s1, std::numeric_limits<double>::min()))
413 const double base = std::exp(logb);
414 const double wk = base * s0;
415 W[k] = num_traits<T>::from_double(wk);
416 std::vector<double> hrow(K, 0.0);
417 for (std::size_t a = 0; a < closedIdx.size(); ++a) hrow[closedIdx[a]] = c[a] * wk;
419 for (std::size_t r = 0; r < K; ++r)
420 if (rhoO[r] > 0.0) hrow[r] += base * s1 * rhoO[r] / ro;
421 for (std::size_t r = 0; r < K; ++r) H(k, r) = num_traits<T>::from_double(hrow[r]);
458 "solver_nc_oi_mixed: the delay and BCMP station tables are formed as exp(lgamma(...)), "
459 "lG as log(G) and an unstable station reports Inf; this backend has no transcendental "
465 const std::size_t M =
sn.nstations, K =
sn.nclasses;
466 std::vector<bool> isOpen(K,
false);
467 std::vector<double> Nfull(K, 0.0);
468 std::vector<std::size_t> closedIdx;
470 for (std::size_t r = 0; r < K; ++r) {
471 Nfull[r] =
sn.classes[r].population;
472 isOpen[r] = std::isinf(Nfull[r]);
474 closedIdx.push_back(r);
475 Nc.push_back(
static_cast<int>(std::llround(Nfull[r])));
478 std::vector<std::size_t> shp, stride;
480 detail::oi_lattice(Nc, shp, stride, ncl);
481 std::vector<T> unit(ncl, zero);
486 std::vector<T> lam(K, zero);
487 for (std::size_t r = 0; r < K; ++r)
489 const std::size_t ref =
sn.classes[r].refstat;
491 if (std::isfinite(l) && l > 0.0) lam[r] =
sn.rates(ref - 1, r);
494 for (std::size_t i = 0; i < M; ++i)
495 for (std::size_t r = 0; r < K; ++r) {
497 if (std::isfinite(rate) && rate > 0.0)
502 std::vector<std::vector<T>> Wt(M);
503 std::vector<Matrix<T>> Ht(M), St(M);
504 std::vector<int> kind(M, 0);
505 std::vector<bool> unstableAt(M,
false);
506 bool anyUnstable =
false, trunc =
false;
509 for (std::size_t i = 0; i < M; ++i) {
511 if (st.
nodetype == qn::NodeType::Source) {
514 }
else if (st.
sched == SchedStrategy::INF) {
516 std::vector<double> Z(closedIdx.size(), 0.0);
517 for (std::size_t a = 0; a < closedIdx.size(); ++a)
519 Wt[i] = detail::oi_mixed_delay_table<T>(Z, shp, ncl);
520 }
else if (st.
sched == SchedStrategy::OI || st.
sched == SchedStrategy::PAS) {
522 std::vector<T> w(K, zero);
523 for (std::size_t r = 0; r < K; ++r)
524 w[r] = isOpen[r] ? T(lam[r] * V(i, r)) : V(i, r);
527 if (mr.
method ==
"oi.trunc") trunc =
true;
530 unstableAt[i] =
true;
540 if (!std::isfinite(csrv) || csrv <= 0.0) csrv = 1.0;
541 std::vector<double> D(closedIdx.size(), 0.0), rhoO(K, 0.0);
542 for (std::size_t a = 0; a < closedIdx.size(); ++a)
544 for (std::size_t r = 0; r < K; ++r)
549 if (!detail::oi_mixed_bcmp_table<T>(D, rhoO, csrv, shp, ncl, closedIdx, K, Wi, Hi)) {
551 unstableAt[i] =
true;
561 std::vector<T> Gfull = unit;
562 for (std::size_t i = 0; i < M; ++i) Gfull = detail::oi_conv(Gfull, Wt[i], shp, stride, ncl);
563 const T G = Gfull[ncl - 1];
564 std::vector<T> X(K, zero);
565 for (std::size_t r = 0; r < K; ++r)
566 if (isOpen[r]) X[r] = lam[r];
567 for (std::size_t a = 0; a < closedIdx.size(); ++a)
568 if (Nc[a] > 0) X[closedIdx[a]] = T(Gfull[ncl - 1 - stride[a]] / G);
571 Matrix<T> Q(M, K, zero), U(M, K, zero), Tp(M, K, zero), R(M, K, zero);
572 for (std::size_t i = 0; i < M; ++i)
573 for (std::size_t r = 0; r < K; ++r) Tp(i, r) = T(V(i, r) * X[r]);
575 for (std::size_t i = 0; i < M; ++i) {
576 if (kind[i] == 0)
continue;
578 std::vector<double> load(K, 0.0);
580 for (std::size_t r = 0; r < K; ++r) {
583 if (isOpen[r] && Tp(i, r) > zero) Q(i, r) = inf;
590 for (std::size_t r = 0; r < K; ++r) {
591 Q(i, r) = T(Tp(i, r) * ST(i, r));
596 std::vector<T> Gm = unit;
597 for (std::size_t j = 0; j < M; ++j)
598 if (j != i) Gm = detail::oi_conv(Gm, Wt[j], shp, stride, ncl);
599 double csrv =
sn.stations[i].nservers;
600 if (!std::isfinite(csrv) || csrv <= 0.0) csrv = 1.0;
602 for (std::size_t r = 0; r < K; ++r) {
603 T qa = zero, ua = zero;
604 for (std::size_t k = 0; k < ncl; ++k) {
605 const T& gf = Gm[ncl - 1 - k];
606 qa += T(Ht[i](k, r) * gf);
607 if (kind[i] == 2) ua += T(St[i](k, r) * gf);
610 U(i, r) = kind[i] == 2 ? T(ua / G / cs) : T(Tp(i, r) * ST(i, r) / cs);
613 for (std::size_t i = 0; i < M; ++i)
614 for (std::size_t r = 0; r < K; ++r)
615 if (Tp(i, r) > zero) R(i, r) = T(Q(i, r) / Tp(i, r));
617 std::vector<T> C(K, zero);
618 for (std::size_t r = 0; r < K; ++r) {
620 for (std::size_t i = 0; i < M; ++i)
621 if (
sn.stations[i].nodetype != qn::NodeType::Source && V(i, r) > zero)
622 C[r] += T(R(i, r) * V(i, r));
623 }
else if (X[r] > zero) {
634 out.
sol.lG = anyUnstable ? std::numeric_limits<double>::infinity()
636 out.
sol.method = trunc ?
"oi.trunc" :
"oi";
657 "solver_nc_oi_analyzer: the BCMP weight table is formed as exp(lgamma(...)) and lG as "
658 "log(G); this backend has no transcendental arithmetic");
661 const std::size_t M =
sn.nstations, K =
sn.nclasses;
667 bool anyOpen =
false, allOpen =
true;
670 else allOpen =
false;
672 if (anyOpen && allOpen) {
682 for (std::size_t c = 0; c <
sn.nchains; ++c)
683 if (
sn.inchain[c].size() > 1)
685 "solver_nc_oi: requires one class per chain (no class switching)");
686 std::vector<int> N(K, 0);
687 for (std::size_t r = 0; r < K; ++r) {
688 if (std::isinf(
sn.classes[r].population))
690 N[r] =
static_cast<int>(std::llround(
sn.classes[r].population));
693 std::vector<bool> isOI(M,
false), isINF(M,
false), isQ(M,
false);
694 for (std::size_t i = 0; i < M; ++i) {
696 if (s == SchedStrategy::INF) {
698 }
else if (s == SchedStrategy::PAS || s == SchedStrategy::OI) {
701 "solver_nc_oi: supports OI stations only (PAS with a non-empty swap graph "
702 "is not order-independent)");
704 if (!
sn.stations[i].svc_rate_fun)
706 "solver_nc_oi: an OI station has no service rate function; set it via "
707 "setServiceRateFunction");
708 }
else if (s == SchedStrategy::PS || s == SchedStrategy::LCFSPR ||
709 s == SchedStrategy::FCFS || s == SchedStrategy::SIRO) {
711 if ((s == SchedStrategy::FCFS || s == SchedStrategy::SIRO) &&
712 detail::class_dependent_fcfs_rate(
sn, i))
714 "solver_nc_oi: a station has class-dependent FCFS/SIRO rates and is not "
715 "product form; class-independent rates are required");
718 "solver_nc_oi: supports only INF (delay), OI, PS, LCFS-PR, SIRO and "
719 "class-independent FCFS stations");
726 std::vector<T> Z(K, zero);
728 for (std::size_t i = 0; i < M; ++i)
729 for (std::size_t r = 0; r < K; ++r) {
731 if (!std::isfinite(mu) || mu == 0.0)
continue;
732 const T st = T(V(i, r) /
sn.rates(i, r));
733 if (isINF[i]) Z[r] += st;
734 if (isQ[i]) D(i, r) = st;
737 for (std::size_t i = 0; i < M; ++i)
739 for (std::size_t r = 0; r < K; ++r)
743 "solver_nc_oi: requires unit per-class visits at every OI station");
745 std::vector<std::size_t> oiList, qList;
746 for (std::size_t i = 0; i < M; ++i) {
747 if (isOI[i]) oiList.push_back(i + 1);
748 if (isQ[i]) qList.push_back(i + 1);
750 std::vector<pfqn::OiRate<T>> rates;
751 for (std::size_t m = 0; m < oiList.size(); ++m) {
752 const std::function<T(
const std::vector<std::size_t>&)> f =
753 sn.stations[oiList[m] - 1].svc_rate_fun;
755 [f](
const std::vector<int>& n) {
return f(detail::oi_microstate(n)); });
758 std::vector<std::size_t> shp, stride;
759 std::size_t total = 0;
760 detail::oi_lattice(N, shp, stride, total);
763 std::vector<T> Gfull(total, zero);
764 for (std::size_t i = 0; i < total; ++i)
767 for (std::size_t i : qList) {
768 std::vector<T> Dq(K, zero);
769 for (std::size_t r = 0; r < K; ++r) Dq[r] = D(i - 1, r);
770 const std::vector<T> Wq =
771 detail::oi_ld_table(Dq,
sn.stations[i - 1].nservers, shp, total);
772 Gfull = detail::oi_conv(Gfull, Wq, shp, stride, total);
775 const T G = Gfull[total - 1];
778 std::vector<T> X(K, zero);
779 for (std::size_t r = 0; r < K; ++r)
781 std::vector<int> Nr = N;
783 X[r] = T(Gfull[detail::oi_idx(Nr, stride)] / G);
786 Matrix<T> Q(M, K, zero), Tp(M, K, zero), R(M, K, zero), U(M, K, zero);
788 for (std::size_t m = 0; m < oiList.size(); ++m) {
789 const std::size_t i = oiList[m];
790 const std::vector<T> Phi = detail::oi_phi<T>(rates[m], N);
791 for (std::size_t r = 0; r < K; ++r) {
792 if (N[r] == 0)
continue;
794 Phi, N, [r](
const std::vector<int>& n) {
798 T(detail::oi_fnc_mean(fr.
Psi, Gfull, shp, stride, total) / G - one);
801 for (std::size_t i : qList) {
802 std::vector<T> Dq(K, zero);
803 for (std::size_t r = 0; r < K; ++r) Dq[r] = D(i - 1, r);
804 const std::vector<T> Wq =
805 detail::oi_ld_table(Dq,
sn.stations[i - 1].nservers, shp, total);
806 for (std::size_t r = 0; r < K; ++r) {
807 if (N[r] == 0)
continue;
809 Wq, N, [r](
const std::vector<int>& n) {
813 T(detail::oi_fnc_mean(fr.
Psi, Gfull, shp, stride, total) / G - one);
816 for (std::size_t i = 0; i < M; ++i)
818 for (std::size_t r = 0; r < K; ++r) {
820 if (!std::isfinite(mu) || mu == 0.0)
continue;
821 Q(i, r) = T(X[r] * V(i, r) /
sn.rates(i, r));
824 for (std::size_t i = 0; i < M; ++i)
825 for (std::size_t r = 0; r < K; ++r) Tp(i, r) = T(X[r] * V(i, r));
826 for (std::size_t i = 0; i < M; ++i)
828 for (std::size_t r = 0; r < K; ++r) U(i, r) = Q(i, r);
829 for (std::size_t i : qList) {
830 const double c_raw =
sn.stations[i - 1].nservers;
831 const double c = (std::isfinite(c_raw) && c_raw > 0.0) ? c_raw : 1.0;
832 for (std::size_t r = 0; r < K; ++r)
835 for (std::size_t m = 0; m < oiList.size(); ++m) {
842 const std::size_t i = oiList[m];
843 const double s_raw =
sn.stations[i - 1].nservers;
844 const double s = (std::isfinite(s_raw) && s_raw > 0.0) ? s_raw : 1.0;
845 const std::vector<T> Phi = detail::oi_phi<T>(rates[m], N);
847 for (std::size_t r = 0; r < K; ++r) {
848 if (N[r] == 0)
continue;
850 Phi, N, [&ins, &stride, r](
const std::vector<int>& n) {
851 return ins.
g(detail::oi_idx(n, stride), r);
854 T((detail::oi_fnc_mean(fr.
Psi, Gfull, shp, stride, total) / G - one) /
858 for (std::size_t i = 0; i < M; ++i)
859 for (std::size_t r = 0; r < K; ++r)
860 if (Tp(i, r) > zero) R(i, r) = T(Q(i, r) / Tp(i, r));
862 std::vector<T> C(K, zero);
863 for (std::size_t r = 0; r < K; ++r)
873 out.
sol.method =
"oi";
894 "solver_nc_pas_is_analyzer: the auto-normalized importance sampler draws from a "
895 "continuous proposal and reports lG = log(G); this backend has no transcendental "
899 const std::size_t M =
sn.nstations, K =
sn.nclasses;
901 for (std::size_t c = 0; c <
sn.nchains; ++c)
902 if (
sn.inchain[c].size() > 1)
904 "solver_nc_pas_is: requires one class per chain (no class switching)");
910 "solver_nc_pas_is: models a two-station pass-and-swap tandem");
911 std::vector<int> N(K, 0);
912 for (std::size_t r = 0; r < K; ++r)
913 N[r] =
static_cast<int>(std::llround(
sn.classes[r].population));
915 std::vector<std::function<T(
const std::vector<std::size_t>&)>> svc(M);
916 std::vector<Matrix<T>> swapG(M);
917 for (std::size_t i = 0; i < M; ++i) {
919 if (s != SchedStrategy::PAS && s != SchedStrategy::OI)
921 "solver_nc_pas_is: requires both stations to be OI/PAS");
922 svc[i] =
sn.stations[i].svc_rate_fun;
925 "solver_nc_pas_is: an OI/PAS station has no service rate function; set it via "
926 "setServiceRateFunction");
930 std::vector<pfqn::OiRateFun<T>> mu(M);
931 for (std::size_t i = 0; i < M; ++i) mu[i] = detail::oi_rank_rate<T>(svc[i]);
942 std::vector<pfqn::PasRateFun<T>> murates(M);
943 for (std::size_t i = 0; i < M; ++i) {
944 const std::function<T(
const std::vector<std::size_t>&)> f = svc[i];
945 murates[i] = [f](
const std::vector<int>& c) {
946 std::vector<std::size_t>
mc(c.size());
947 for (std::size_t a = 0; a < c.size(); ++a)
948 mc[a] =
static_cast<std::size_t
>(c[a]);
954 for (std::size_t a = 0; a < H.
rows(); ++a)
955 for (std::size_t b = 0; b < H.
cols(); ++b)
959 for (std::size_t i = 0; i < M; ++i)
960 for (std::size_t r = 0; r < K; ++r)
963 "solver_nc_pas_is: requires unit per-class visits at both stations");
965 const std::size_t samples =
opt.samples > 0 ?
opt.samples : 10000;
966 const unsigned seed =
opt.seed > 0 ?
static_cast<unsigned>(
opt.seed) : 23456u;
972 Matrix<T> Q(M, K, zero), Tp(M, K, zero), R(M, K, zero), U(M, K, zero);
973 for (std::size_t i = 0; i < M; ++i)
974 for (std::size_t r = 0; r < K; ++r) Q(i, r) = res.
Q(i, r);
979 std::vector<T> X(K, zero);
980 for (std::size_t r = 0; r < K; ++r)
982 std::vector<int> Nr = N;
990 if (res.
G > zero) X[r] = T(gr.
G / res.
G);
993 for (std::size_t i = 0; i < M; ++i)
994 for (std::size_t r = 0; r < K; ++r) Tp(i, r) = T(X[r] * V(i, r));
995 for (std::size_t i = 0; i < M; ++i) {
996 const double s_raw =
sn.stations[i].nservers;
997 const double s = (std::isfinite(s_raw) && s_raw > 0.0) ? s_raw : 1.0;
998 for (std::size_t r = 0; r < K; ++r) {
999 if (N[r] == 0)
continue;
1000 std::vector<int> er(K, 0);
1002 const T muR = mu[i](er);
1007 for (std::size_t i = 0; i < M; ++i)
1008 for (std::size_t r = 0; r < K; ++r)
1009 if (Tp(i, r) > zero) R(i, r) = T(Q(i, r) / Tp(i, r));
1011 std::vector<T> C(K, zero);
1012 for (std::size_t r = 0; r < K; ++r)
1022 out.
sol.method =
"is";
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
The exception types the port throws.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
double tot(const std::vector< double > &pops)
bool nc_is_oi_model(const qn::NetworkStruct< T > &sn)
Port of nc_is_oi_model.m: a closed, open or mixed network with at least one OI station and nothing bu...
NcSolution< T > solver_nc_pas_is_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_pas_is_analyzer.m.
NcSolution< T > solver_nc_oi_mixed(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_oi_mixed.m: exact normalizing-constant analysis of a MIXED (open and closed) networ...
mva::MvaSolution< T > solver_oi_open_analyzer(const qn::NetworkStruct< T > &sn, double tol)
Port of solver_oi_open_analyzer.m.
bool nc_is_pas_model(const qn::NetworkStruct< T > &sn)
Port of nc_is_pas_model.m: a closed two-station OI / P&S tandem.
NcSolution< T > solver_nc_oi_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_oi_analyzer.m.
std::string nc_oi_refusal(const qn::NetworkStruct< T > &sn, const std::string &route="oi")
Port of nc_oi_refusal.m: may the order-independent route ROUTE run on this model?
std::mt19937_64 McRng
The generator type every Monte Carlo entry point in this tree accepts.
OiMixedResult< T > pfqn_oi_mixed(const std::vector< T > &lambda, const std::vector< double > &N, const std::function< T(const std::vector< int > &)> &mu, const OiMixedOptions &opt=OiMixedOptions())
Closed-lattice station tables of an OI station with open classes summed out.
NcResult< T > pfqn_ncoi(const std::vector< T > &Z, const std::vector< int > &N, const std::vector< OiRate< T > > &mu, const Matrix< T > &visits)
Normalizing constant of a closed network of ORDER-INDEPENDENT (OI) / pass-and-swap stations with empt...
PasIsResult< T > pfqn_pas_is(const std::vector< int > &N, const std::vector< OiRateFun< T > > &mu, const Matrix< int > &H, std::size_t samples, McRng &rng, bool want_qlen=true)
Importance-sampling estimate of the normalizing constant of a single communicating class of a cyclic ...
Matrix< T > pas_swap2order(const std::vector< Matrix< T > > &swap, const std::vector< PasRateFun< T > > &listRate, const std::vector< int > &N0=std::vector< int >())
Placement-order DAG of a two-station pass-and-swap tandem.
OiFncResult< T > pfqn_oi_fnc(const std::vector< T > &Phi, const std::vector< int > &N, const std::function< T(const std::vector< int > &)> &f)
Order-independent (OI) functional server: the balance function Psi and the rate mu_f of an auxiliary ...
OiInsvcResult< T > pfqn_oi_insvc(const std::function< T(const std::vector< int > &)> &oirate, const std::vector< int > &N)
Conditional mean number of IN-SERVICE jobs per class at an order-independent station.
std::function< T(const std::vector< int > &)> OiRateFun
The OI rank rate of a station as a function of the per-class COUNT vector: the svcRateFun of an OI / ...
Matrix< T > station_swap_graph(const NetworkStruct< T > &sn, std::size_t ist)
The swap graph of a PAS / OI station, with the defaults refreshLocalVars.m installs applied.
bool station_swap_graph_is_zero(const NetworkStruct< T > &sn, std::size_t ist)
True when the station's materialized swap graph is entirely zero.
Conservation laws of a layered queueing network, enumerated from its structure.
Controls and result shape shared by the normalizing-constant analyzers.
A queueing network and its refreshed NetworkStruct.
Global placement-order DAG of a closed two-station pass-and-swap tandem.
Normalizing constant of a closed network of ORDER-INDEPENDENT (OI) / pass-and-swap stations with empt...
Order-independent (OI) functional server: the balance function Psi and the rate mu_f of an auxiliary ...
Conditional mean number of IN-SERVICE jobs per class at an order-independent station.
Closed-lattice station tables of an order-independent (OI) station visited by CLOSED and OPEN classes...
Importance-sampling estimate of the normalizing constant of a single communicating class of a cyclic ...
Exact analysis of an OPEN queueing network mixing order-independent (OI) stations with BCMP product-f...
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
The [Q,U,R,T,C,X,lG] of the reference, plus the algorithm that ran.
mva::MvaSolution< T > sol
Controls, defaulting to SolverOptions('NC') in the reference.
Return value of pfqn_oi_fnc, mirroring [muf, Psi, mu] flattened.
std::vector< T > Psi
column-major over the lattice
Return value of pfqn_oi_insvc, mirroring [g, Xi, Phi].
Matrix< T > g
(prod(N+1) x R) E[sir_r | n]
The tuning fields of pfqn_oi_mixed / pfqn_oi_open (OPTIONS in the reference).
double tol
relative tolerance of the 'oi.trunc' branch
Return value of pfqn_oi_mixed, mirroring [W, H, S, stable, tau, method].
Matrix< T > S
(prod(Nc+1) x R) per-class in-service weights
std::vector< T > W
(prod(Nc+1)) column-major table over the closed lattice
std::string method
"oi" (exact) or "oi.trunc"
bool stable
false when some reachable macrostate has den(m) <= 0
Matrix< T > H
(prod(Nc+1) x R) per-class mean weights
Return value of pfqn_pas_is / pfqn_oi_is, mirroring [G, lG, Q].
T G
estimate of the communicating-class normalizing constant
Matrix< T > Q
(2 x R) mean per-class queue length, Q(1,:) = N - Q(0,:)
One job class of the network.
double population
infinite for an open class
One station of the network.
double nservers
may be infinite (a Delay, or an inf-scheduled task)