5#ifndef LINE_SOLVERS_MVA_SOLVER_MVA_H
6#define LINE_SOLVERS_MVA_SOLVER_MVA_H
95 std::size_t lcfspr_ist) {
108 std::vector<T> alpha(R, one), beta(R, one);
109 std::vector<int> N(R, 0);
110 for (std::size_t r = 0; r < R; ++r) {
111 const double nr = L.
classes[r].population;
112 if (!(nr > 0.0))
continue;
113 N[r] =
static_cast<int>(std::llround(nr));
114 const T mu_l = L.
rates(lcfs_ist - 1, r);
115 const T mu_p = L.
rates(lcfspr_ist - 1, r);
117 throw InputError(
"solver_mva_lcfsqn: invalid service rate at the LCFS station for class " +
118 std::to_string(r + 1));
120 throw InputError(
"solver_mva_lcfsqn: invalid service rate at the LCFS-PR station for "
121 "class " + std::to_string(r + 1));
122 alpha[r] = T(one / mu_l);
123 beta[r] = T(one / mu_p);
133 out.
C.assign(R, zero);
134 out.
X.assign(R, zero);
135 for (std::size_t r = 0; r < R; ++r) {
136 out.
Q(lcfs_ist - 1, r) = res.
Q(0, r);
137 out.
Q(lcfspr_ist - 1, r) = res.
Q(1, r);
138 out.
U(lcfs_ist - 1, r) = res.
U(0, r);
139 out.
U(lcfspr_ist - 1, r) = res.
U(1, r);
140 if (N[r] <= 0)
continue;
141 out.
X[r] = res.
T_[r];
142 out.
Tp(lcfs_ist - 1, r) = res.
T_[r];
143 out.
Tp(lcfspr_ist - 1, r) = res.
T_[r];
145 for (std::size_t i : {lcfs_ist - 1, lcfspr_ist - 1})
146 for (std::size_t r = 0; r < R; ++r)
147 if (out.
Tp(i, r) > zero) out.
R(i, r) = T(out.
Q(i, r) / out.
Tp(i, r));
148 for (std::size_t r = 0; r < R; ++r)
149 if (N[r] > 0) out.
C[r] = T(out.
R(lcfs_ist - 1, r) + out.
R(lcfspr_ist - 1, r));
155 out.
lG = std::numeric_limits<double>::quiet_NaN();
169 std::vector<std::size_t> lcfs, lcfspr;
170 for (std::size_t i = 0; i < M; ++i) {
171 if (L.
stations[i].sched == SchedStrategy::LCFS) lcfs.push_back(i + 1);
172 if (L.
stations[i].sched == SchedStrategy::LCFSPR) lcfspr.push_back(i + 1);
174 if (!lcfs.empty() && !lcfspr.empty()) {
175 if (lcfs.size() != 1 || lcfspr.size() != 1)
177 "solver_mva: LCFS MVA requires exactly one LCFS and one LCFS-PR station");
178 for (std::size_t c = 0; c < C; ++c)
179 if (std::isinf(d.
Nchain[c]))
184 for (std::size_t ist : {lcfs[0], lcfspr[0]}) {
186 for (std::size_t r = 0; r < Rn; ++r)
187 if (L.
rt.rows() == S * Rn && L.
rt(sf * Rn + r, sf * Rn + r) > zero)
189 "solver_mva: LCFS MVA does not support self-loops at stations");
194 throw UnsupportedError(
ErrorKind{
"SchedStrategy_LCFS"},
"solver_mva: LCFS scheduling requires a paired LCFS-PR station");
203 if (!L.
sched_is_product_form()) why =
"a station's scheduling is outside BCMP (INF, PS, FCFS, LCFS, LCFS-PR)";
206 else if (!L.
fj.empty()) why =
"the model has a fork-join";
207 else if (L.
has_sd_routing()) why =
"a node routes by state-dependent rules (RROBIN, WRROBIN, JSQ, SQ, SDR)";
208 else if (L.
has_blocking()) why =
"a station has a finite buffer or the model has a capacity region";
209 else why =
"an FCFS station has non-exponential service";
213 std::vector<std::size_t> infSET, qSET;
214 for (std::size_t i = 0; i < M; ++i) {
216 case SchedStrategy::EXT:
break;
217 case SchedStrategy::INF: infSET.push_back(i);
break;
218 case SchedStrategy::PS:
219 case SchedStrategy::LCFSPR:
220 case SchedStrategy::FCFS:
221 case SchedStrategy::SIRO: qSET.push_back(i);
break;
229 Matrix<T> Lq(qSET.size(), C, zero), Zd(infSET.size(), C, zero);
230 for (std::size_t a = 0; a < qSET.size(); ++a)
231 for (std::size_t c = 0; c < C; ++c)
233 for (std::size_t a = 0; a < infSET.size(); ++a)
234 for (std::size_t c = 0; c < C; ++c)
235 Zd(a, c) = T(d.
STchain(infSET[a], c) * d.
Vchain(infSET[a], c));
238 std::vector<T> lambda(C, zero);
239 std::vector<int> N(C, 0);
240 for (std::size_t c = 0; c < C; ++c) {
241 if (!std::isfinite(d.
Nchain[c])) {
247 N[c] =
static_cast<int>(std::llround(d.
Nchain[c]));
250 for (std::size_t a = 0; a < qSET.size(); ++a) {
251 const double s = L.
stations[qSET[a]].nservers;
252 if (!std::isfinite(s))
254 "is not inf-scheduled");
255 S.push_back(
static_cast<int>(std::llround(s)));
268 Matrix<T> Qchain(M, C, zero), Wchain(M, C, zero), Tchain(M, C, zero), Uchain(M, C, zero);
269 std::vector<T> Xchain = pf.
XN;
270 for (std::size_t a = 0; a < qSET.size(); ++a)
271 for (std::size_t c = 0; c < C; ++c) Qchain(qSET[a], c) = pf.
QN(a, c);
272 for (std::size_t a = 0; a < infSET.size(); ++a)
273 for (std::size_t c = 0; c < C; ++c)
274 Qchain(infSET[a], c) = T(Xchain[c] * d.
STchain(infSET[a], c) * d.
Vchain(infSET[a], c));
276 std::vector<std::size_t> rset;
277 for (std::size_t c = 0; c < C; ++c)
278 if (d.
Nchain[c] != 0.0) rset.push_back(c);
280 for (std::size_t c : rset) {
281 for (std::size_t i : infSET) Wchain(i, c) = d.
STchain(i, c);
282 for (std::size_t i : qSET) {
283 if (std::isinf(L.
stations[i].nservers)) {
284 Wchain(i, c) = d.
STchain(i, c);
285 }
else if (d.
Vchain(i, c) == zero || Xchain[c] == zero) {
288 Wchain(i, c) = T(Qchain(i, c) / (Xchain[c] * d.
Vchain(i, c)));
293 std::vector<T> Cc(C, zero);
294 for (std::size_t c : rset) {
296 for (std::size_t i = 0; i < M; ++i) sw += Wchain(i, c);
301 for (std::size_t i = 0; i < M; ++i) cyc += d.
Vchain(i, c) * Wchain(i, c);
304 if (cyc != zero && std::isfinite(d.
Nchain[c]))
307 for (std::size_t i = 0; i < M; ++i) {
308 Qchain(i, c) = T(Xchain[c] * d.
Vchain(i, c) * Wchain(i, c));
309 Tchain(i, c) = T(Xchain[c] * d.
Vchain(i, c));
312 for (std::size_t i = 0; i < M; ++i)
313 for (std::size_t c : rset) {
315 Uchain(i, c) = std::isinf(L.
stations[i].nservers)
321 for (std::size_t i = 0; i < M; ++i) {
322 if (!(L.
stations[i].sched == SchedStrategy::FCFS || L.
stations[i].sched == SchedStrategy::PS))
325 for (std::size_t c = 0; c < C; ++c) usum += Uchain(i, c);
328 for (std::size_t c = 0; c < C; ++c) den += d.
Vchain(i, c) * d.
STchain(i, c) * Xchain[c];
329 if (den == zero)
continue;
331 for (std::size_t c = 0; c < C; ++c) {
333 Uchain(i, c) = T(cap * d.
Vchain(i, c) * d.
STchain(i, c) * Xchain[c] / den);
338 for (std::size_t i = 0; i < M; ++i)
339 for (std::size_t c = 0; c < C; ++c)
340 if (Tchain(i, c) != zero) Rchain(i, c) = T(Qchain(i, c) / Tchain(i, c));
347 for (std::size_t c = 0; c < C; ++c)
348 if (nonfinite(Xchain[c])) Xchain[c] = zero;
349 for (std::size_t i = 0; i < M; ++i)
350 for (std::size_t c = 0; c < C; ++c) {
351 if (nonfinite(Uchain(i, c))) Uchain(i, c) = zero;
352 if (nonfinite(Qchain(i, c))) Qchain(i, c) = zero;
353 if (nonfinite(Rchain(i, c))) Rchain(i, c) = zero;
356 for (std::size_t c = 0; c < C; ++c) {
357 if (d.
Nchain[c] != 0.0)
continue;
359 for (std::size_t i = 0; i < M; ++i) {
403std::vector<T> ms_term(
const qn::NetworkStruct<T>& L,
const std::vector<qn::SchedStrategy>& sched,
404 const std::vector<T>& narrival,
const std::string& multiserver) {
408 std::vector<T> r(M, one);
409 if (multiserver ==
"suri")
return r;
410 if (!(multiserver ==
"default" || multiserver ==
"seidmann" || multiserver ==
"softmin"))
412 "' is not implemented in this port");
413 for (std::size_t i = 0; i < M; ++i) {
414 const double c = L.
stations[i].nservers;
417 if (sc == SchedStrategy::INF)
continue;
418 const bool fcfs_family =
419 sc == SchedStrategy::FCFS || sc == SchedStrategy::SIRO || sc == SchedStrategy::LCFSPR;
420 if (multiserver ==
"seidmann" || (multiserver ==
"default" && fcfs_family)) {
421 r[i] = std::isinf(c) ? one : T(one / num_traits<T>::from_double(c));
428 if constexpr (num_traits<T>::has_transcendental) {
430 const double alpha = 20.0;
431 const double n = num_traits<T>::to_double(narrival[i]);
432 const double lo = std::min(n, c), hi = std::max(n, c);
433 const double gap = hi - lo;
434 const double w = alpha * gap > 745.0 ? 0.0 : std::exp(-alpha * gap);
435 const double sm = lo + gap * w / (1.0 + w);
436 r[i] = num_traits<T>::from_double(sm > 0.0 ? 1.0 / sm : 1.0 / std::min(n, c));
439 "solver_amvald: the soft-minimum multiserver term evaluates exp, which exact "
440 "arithmetic has no representation for; use the double or real backend, the "
441 "seidmann or suri multiserver rule, or a layer whose queueing stations are "
442 "FCFS-family or infinite-server");
457std::vector<T> suri_factor(
const qn::NetworkStruct<T>& L,
const Matrix<T>& Uin,
double tol) {
458 const std::size_t M = L.nstations, K = Uin.cols();
459 const T one = num_traits<T>::from_int(1),
zero = num_traits<T>::from_int(0);
460 std::vector<T> f(M, one);
461 if constexpr (!num_traits<T>::has_transcendental) {
463 "solver_amvald: the Suri multiserver factor is a real power of the utilization, "
464 "which exact arithmetic has no representation for; use the double or real backend");
466 const double alpha = 4.464, beta = 0.676;
467 for (std::size_t i = 0; i < M; ++i) {
468 const double c = L.stations[i].nservers;
469 if (std::isinf(c) || c == 0.0) {
473 if (!(c > 1.0))
continue;
475 for (std::size_t s = 0; s < K; ++s) usum += Uin(i, s);
476 double rho = num_traits<T>::to_double(usum) / c;
477 if (rho > 1.0 - tol) rho = 1.0 - tol;
478 f[i] = rho > 0.0 ? num_traits<T>::from_double(
479 std::pow(rho, alpha * (std::pow(c, beta) - 1.0)) / c)
480 : T(one / num_traits<T>::from_double(c));
494 const MvaOptions&
opt,
const std::string& method,
bool& converged,
509 "solver_amvald: the approximate MVA is an iterative fixed point whose iterates "
510 "accumulate the product of every denominator seen so far, so exact rational "
511 "arithmetic grows without bound and the solve does not terminate; rerun with "
512 "--arith double or --arith real, or give the model a product form (BCMP type 1 "
513 "asks FCFS service to be exponential) so the exact recursion applies");
519 for (std::size_t i = 0; i < M; ++i) {
521 if (!(s == SchedStrategy::INF || s == SchedStrategy::PS || s == SchedStrategy::FCFS ||
522 s == SchedStrategy::SIRO || s == SchedStrategy::LCFSPR || s == SchedStrategy::EXT ||
523 s == SchedStrategy::DPS || s == SchedStrategy::HOL ||
524 s == SchedStrategy::FCFSPRPRIO))
526 " scheduling is not implemented in this port");
537 bool any_queue =
false;
538 for (std::size_t i = 0; i < M && !any_queue; ++i)
539 if (L.
stations[i].sched != SchedStrategy::INF && L.
stations[i].sched != SchedStrategy::EXT)
541 const bool linmethod = (method ==
"lin" || method ==
"qdlin");
543 !(linmethod || method ==
"qd" || method ==
"default" || method ==
"bs" ||
544 method ==
"egflin" || method ==
"gflin" || method ==
"qli" || method ==
"fli" ||
545 method ==
"aql" || method ==
"qdaql" || method ==
"tay" || method ==
"priomva"))
550 for (std::size_t c = 0; c < K; ++c)
554 std::vector<T> deltaclass(K, one);
555 for (std::size_t c = 0; c < K; ++c)
560 std::vector<std::size_t> nnz, ccl, ocl;
561 std::vector<bool> isopen(K,
false);
562 for (std::size_t c = 0; c < K; ++c) {
563 if (!(d.
Nchain[c] > 0.0))
continue;
565 if (std::isfinite(d.
Nchain[c])) ccl.push_back(c);
566 else { ocl.push_back(c); isopen[c] =
true; }
576 std::vector<std::size_t> ocl_exo, ocl_aux;
577 for (std::size_t c : ocl) {
580 allaux = !L.
inchain[c].empty();
581 for (std::size_t r : L.
inchain[c])
584 if (allaux) ocl_aux.push_back(c);
else ocl_exo.push_back(c);
589 if (init_sol.rows() == M && init_sol.cols() == K) {
593 for (std::size_t c = 0; c < K; ++c) {
594 if (!std::isfinite(d.
Nchain[c]))
continue;
595 for (std::size_t i = 0; i < M; ++i)
601 std::vector<T> Xchain(K, zero);
602 for (std::size_t c = 0; c < K; ++c) {
606 Xchain[c] = st > zero ? T(one / st) : zero;
610 for (std::size_t i = 0; i < M; ++i) s += d.
STchain(i, c);
611 if (s != zero) Xchain[c] = T(one / s);
613 Matrix<T> Uchain(M, K, zero), Tchain(M, K, zero), Wchain(M, K, zero), STeff = d.
STchain;
614 for (std::size_t i = 0; i < M; ++i)
615 for (std::size_t c : nnz) {
617 Uchain(i, c) = std::isinf(L.
stations[i].nservers)
623 std::vector<Matrix<T>> gamma(K,
Matrix<T>(M, K, zero));
627 const int max_totiter = std::min(
opt.iter_max, 10000);
629 const int inner_cap =
static_cast<int>(std::sqrt(
static_cast<double>(
opt.iter_max)));
633 std::vector<int> chainprio(K, 0);
634 for (std::size_t c = 0; c < K && c < L.
inchain.size(); ++c) {
636 for (std::size_t k1 : L.
inchain[c]) {
637 const int p = L.
classes[k1 - 1].prio;
638 chainprio[c] = first ? p : std::min(chainprio[c], p);
643 const bool has_prio = [&] {
646 for (std::size_t c = 0; c < K; ++c) {
647 const int p = chainprio[c];
648 if (first) { lo = hi = p; first =
false; }
649 lo = std::min(lo, p);
650 hi = std::max(hi, p);
654 std::vector<std::vector<std::size_t>> ehprio(K), hprio(K), eprio(K), lprio(K);
655 for (std::size_t r : nnz) {
658 for (std::size_t s : nnz) {
659 ehprio[r].push_back(s);
660 eprio[r].push_back(s);
664 for (std::size_t s : nnz) {
665 const int pr = chainprio[r], ps = chainprio[s];
666 if (ps <= pr) ehprio[r].push_back(s);
667 if (ps < pr) hprio[r].push_back(s);
668 if (ps == pr) eprio[r].push_back(s);
669 if (ps > pr) lprio[r].push_back(s);
674 std::size_t smax = 0;
675 for (
const auto& st : L.
stations) smax = std::max(smax, st.lldscaling.size());
679 for (std::size_t i = 0; i < M; ++i)
680 for (std::size_t k = 0; k < L.
stations[i].lldscaling.size(); ++k)
681 lldscaling(i, k) = L.
stations[i].lldscaling[k];
683 std::vector<lang::CdScaling<T>> cdscaling;
689 if (!cdscaling.empty())
690 for (std::size_t i = 0; i < M; ++i) cdscaling[i] = L.
stations[i].cdscaling;
695 std::vector<lang::CdScaling<T>> jdscaling;
701 if (!jdscaling.empty())
702 for (std::size_t i = 0; i < M; ++i) jdscaling[i] = L.
stations[i].jdscaling;
703 const bool has_scaling = (smax > 0) || !cdscaling.empty() || !jdscaling.empty();
711 std::vector<SchedStrategy> schedfw(M);
712 for (std::size_t i = 0; i < M; ++i) {
714 const double cs = L.
stations[i].nservers;
715 if (!std::isfinite(cs))
continue;
716 bool any =
false, open =
false;
718 for (std::size_t c = 0; c < K; ++c) {
722 if (std::isfinite(d.
Nchain[c])) nvis += d.
Nchain[c];
else open =
true;
724 if (!any || open || nvis > cs)
continue;
726 if (!(s == SchedStrategy::FCFS || s == SchedStrategy::SIRO || s == SchedStrategy::LCFS ||
727 s == SchedStrategy::LCFSPR || s == SchedStrategy::PS || s == SchedStrategy::HOL ||
728 s == SchedStrategy::FCFSPRPRIO))
731 for (
const T& v : L.
stations[i].lldscaling)
733 if (!hasLD && !L.
stations[i].cdscaling && !L.
stations[i].jdscaling) schedfw[i] = SchedStrategy::INF;
737 std::vector<std::vector<T>> tau(K, std::vector<T>(K, zero));
749 auto forward = [&](
const Matrix<T>& Qin,
const std::vector<T>& Xin,
const Matrix<T>& Uin,
752 for (std::size_t c = 0; c < K; ++c)
753 if (std::isfinite(Nc[c])) Ntl += Nc[c];
755 std::vector<T> dcl(K, one);
756 for (std::size_t c = 0; c < K; ++c)
757 if (std::isfinite(Nc[c]) && Nc[c] > 0.0)
760 std::vector<T> interpTot(M, zero);
761 Matrix<T> selfArvl(M, K, zero), totArvl(M, K, zero), totArvlOpen(M, K, zero);
762 for (std::size_t i = 0; i < M; ++i) {
764 for (std::size_t c : nnz) s += Qin(i, c);
777 T sc = zero, so = zero;
778 for (std::size_t c : ccl) sc += Qin(i, c);
779 for (std::size_t c : ocl_aux) sc += Qin(i, c);
780 for (std::size_t c : ocl_exo) so += Qin(i, c);
781 interpTot[i] = T(deltaL * sc + so);
782 const bool hol = schedfw[i] == SchedStrategy::HOL;
783 for (std::size_t c : nnz) {
784 selfArvl(i, c) = T(dcl[c] * Qin(i, c));
786 T eh = zero, ehx = zero;
787 for (std::size_t s2 : ehprio[c]) {
789 if (s2 != c) ehx += Qin(i, s2);
791 totArvlOpen(i, c) = eh;
792 totArvl(i, c) = T(dcl[c] * Qin(i, c) + ehx);
794 totArvlOpen(i, c) = s;
795 totArvl(i, c) = T(dcl[c] * Qin(i, c) + s - Qin(i, c));
801 std::vector<T> gmean(M, zero);
806 for (std::size_t i = 0; i < M; ++i) {
808 for (std::size_t s : ccl) {
810 for (std::size_t r : ccl)
812 acc += T(deltaL * gs);
814 gmean[i] = T(acc / nccl);
819 for (std::size_t i = 0; i < M; ++i)
820 for (std::size_t r : ccl)
823 for (std::size_t i = 0; i < M; ++i) gmean[i] = sc;
826 std::vector<T> narrival(M, zero);
827 for (std::size_t i = 0; i < M; ++i) narrival[i] = T(one + interpTot[i] + gmean[i]);
828 const std::vector<T> msterm = detail::ms_term(L, schedfw, narrival,
opt.multiserver);
829 std::vector<T> suri(M, one);
830 if (
opt.multiserver ==
"suri") suri = detail::suri_factor(L, Uin,
opt.tol);
838 "solver_amvald: load-dependent scaling interpolates a rate lattice with a "
839 "soft minimum, which exact arithmetic has no representation for; use the "
840 "double or real backend");
842 if (linmethod && !ccl.empty() && !nnz.empty()) {
843 for (std::size_t r : nnz) {
844 std::vector<T> arg(M, zero);
845 for (std::size_t i = 0; i < M; ++i) {
847 for (std::size_t s : ccl)
849 gcorr -= gamma[r](i, r);
850 arg[i] = T(one + interpTot[i] + gcorr);
852 const std::vector<T> v =
854 for (std::size_t i = 0; i < M; ++i) lldterm(i, r) = v[i];
857 std::vector<T> arg(M, zero);
858 for (std::size_t i = 0; i < M; ++i) arg[i] = T(one + interpTot[i]);
859 const std::vector<T> v =
861 for (std::size_t i = 0; i < M; ++i)
862 for (std::size_t c = 0; c < K; ++c) lldterm(i, c) = v[i];
869 if (!cdscaling.empty()) {
870 for (std::size_t r : nnz) {
872 const bool closed = std::isfinite(Nc[r]);
873 for (std::size_t i = 0; i < M; ++i)
874 for (std::size_t c = 0; c < K; ++c)
875 arg(i, c) = T(one + (closed ? selfArvl(i, c) : Qin(i, c)));
876 if (closed && linmethod)
877 for (std::size_t i = 0; i < M; ++i) {
880 for (std::size_t c = 0; c < K; ++c) arg(i, c) = T(arg(i, c) + gself);
883 for (std::size_t i = 0; i < M; ++i) cdterm(i, r) = v[i];
899 if (!jdscaling.empty()) {
900 for (std::size_t r : nnz) {
901 const bool closed = std::isfinite(Nc[r]);
903 for (std::size_t i = 0; i < M; ++i) {
904 for (std::size_t c : nnz) arg(i, c) = Qin(i, c);
905 T self = T(one + (closed ? selfArvl(i, r) : Qin(i, r)));
906 if (closed && linmethod)
911 for (std::size_t i = 0; i < M; ++i) jdterm(i, r) = v[i];
916 for (std::size_t c : nnz)
917 for (std::size_t i = 0; i < M; ++i)
919 T(d.
STchain(i, c) * lldterm(i, c) * msterm[i] * cdterm(i, c) * jdterm(i, c));
923 if (method ==
"qli" || method ==
"fli") {
924 const bool qli = (method ==
"qli");
925 for (std::size_t i = 0; i < M; ++i) {
926 const bool hol = schedfw[i] == SchedStrategy::HOL;
927 for (std::size_t r : nnz) {
930 for (std::size_t s2 : ehprio[r]) tot += Qin(i, s2);
932 for (std::size_t s2 : nnz) tot += Qin(i, s2);
935 totArvl(i, r) = T(tot - Qin(i, r));
938 const T num = T(STeffOut(i, r) * (one + tot - Qin(i, r)));
940 for (std::size_t m = 0; m < M; ++m)
941 if (schedfw[m] == SchedStrategy::INF) den += STeffOut(m, r);
942 for (std::size_t m = 0; m < M; ++m) {
944 if (schedfw[m] == SchedStrategy::HOL) {
945 for (std::size_t s2 : ehprio[r]) totm += Qin(m, s2);
947 for (std::size_t s2 : nnz) totm += Qin(m, s2);
949 den += T(STeffOut(m, r) * (one + totm - Qin(m, r)));
951 if (den == zero)
continue;
954 totArvl(i, r) = T(tot - f * (Qin(i, r) - num / den));
957 totArvl(i, r) = T(tot - f * Qin(i, r) + num / den);
968 if (!ILchain.
empty()) {
969 for (std::size_t i = 0; i < M; ++i)
970 for (std::size_t c : nnz) {
972 for (std::size_t c2 : nnz)
973 if (c2 != c) ilq += ILchain(c, c2) * Qin(i, c2);
975 T adj = T(totArvl(i, c) - ilq);
976 if (adj < selfArvl(i, c)) adj = selfArvl(i, c);
983 for (std::size_t c : nnz) {
984 for (std::size_t i = 0; i < M; ++i) {
987 if (sc == SchedStrategy::EXT)
continue;
988 if (sc == SchedStrategy::INF) {
989 Wout(i, c) = STeffOut(i, c);
992 const double cs = L.
stations[i].nservers;
994 if (sc == SchedStrategy::PS) {
997 for (std::size_t s : ccl)
999 corr -= gamma[c](i, c);
1003 if (
opt.multiserver ==
"suri") {
1006 const T Lm = isopen[c] ? totArvlOpen(i, c)
1007 : T(totArvl(i, c) + corr);
1008 Wout(i, c) = T(STeffOut(i, c) * (one + Lm * suri[i]));
1011 if (
opt.multiserver ==
"seidmann")
1015 Wout(i, c) = T(Wout(i, c) + STeffOut(i, c) * (one + totArvlOpen(i, c)));
1023 Wout(i, c) = T(Wout(i, c) + STeffOut(i, c) * (one + totArvl(i, c) + corr));
1028 if (sc == SchedStrategy::DPS) {
1031 const std::vector<T>& w = L.
stations[i].schedparam;
1034 "solver_amvald: the DPS station '" + L.
stations[i].name +
1035 "' has no per-class weights");
1037 if (cs > 1.0 && std::isfinite(cs))
1039 acc += T(STeffOut(i, c) * (one + selfArvl(i, c)));
1040 for (std::size_t s : nnz) {
1041 if (s == c)
continue;
1043 acc += T(STeffOut(i, c) * Qin(i, s));
1045 acc += T(STeffOut(i, c) * Qin(i, s) * w[s] / w[c]);
1051 const bool fcfs_family = (sc == SchedStrategy::FCFS || sc == SchedStrategy::SIRO ||
1052 sc == SchedStrategy::LCFSPR);
1053 if (!fcfs_family && sc != SchedStrategy::HOL && sc != SchedStrategy::FCFSPRPRIO)
1055 " scheduling is not implemented in this port");
1056 if (STeffOut(i, c) <= zero)
continue;
1058 const std::vector<T>& Xarv = Xref.empty() ? Xin : Xref;
1071 if (sc == SchedStrategy::FCFSPRPRIO) {
1072 if (cs > 1.0 && std::isfinite(cs))
1074 "solver_amvald: FCFSPRPRIO with more than one server. The "
1075 "preemptive-resume priority arm (priomva) is implemented for "
1076 "single-server stations only; use SolverCTMC or SolverSSA for "
1077 "multiserver PRS.");
1081 for (std::size_t h : hprio[c])
1082 uh_prs += T(d.
Vchain(i, h) * STeffOut(i, h) * T(Xarv[h] + tau[c][h]));
1084 vps = std::max(
opt.tol, std::min(vps, 1.0 -
opt.tol));
1088 T queued = T(STeffOut(i, c) * (isopen[c] ? Qin(i, c) : selfArvl(i, c)));
1089 for (std::size_t s : ehprio[c])
1090 if (s != c) queued += T(STeffOut(i, s) * Qin(i, s));
1092 Wout(i, c) = T((STeffOut(i, c) + queued) / ps_prs);
1096 auto Ur = [&](std::size_t k, std::size_t s) -> T {
1097 if (!(Xin[s] > zero))
return Uin(k, s);
1098 return T(Uin(k, s) / Xin[s] * (Xarv[s] + tau[c][s]));
1101 const bool per_server = cs > 1.0 && std::isfinite(cs) &&
1102 (
opt.multiserver ==
"softmin" ||
opt.multiserver ==
"suri");
1103 auto STps = [&](std::size_t s) -> T {
1104 if (!per_server)
return STeffOut(i, s);
1109 auto prio_scaling = [&](std::size_t r) -> T {
1110 if (sc != SchedStrategy::HOL)
return one;
1112 for (std::size_t h : hprio[r]) {
1115 const T xh =
opt.np_priority ==
"shadow" ? Xarv[h] : T(Xarv[h] + tau[r][h]);
1116 uh += T(d.
Vchain(i, h) * STps(h) * xh);
1119 v = std::max(
opt.tol, std::min(v, 1.0 -
opt.tol));
1122 const T ps_r = prio_scaling(c);
1129 auto hol_ehprio_backlog = [&](
const std::vector<T>& Bkw) -> T {
1131 for (std::size_t s : ehprio[c])
1132 if (s != c) acc += T(STeffOut(i, s) * Qin(i, s) * Bkw[s]);
1135 auto hol_np_residual = [&](
const std::vector<T>& Bkw) -> T {
1136 if (
opt.highvar ==
"hvmva")
return zero;
1138 for (std::size_t s : lprio[c])
1139 acc += T(d.
Vchain(i, s) * STps(s) * (Xarv[s] + tau[c][s]) * STps(s) * Bkw[s]);
1144 std::vector<T> Bk(K, one);
1145 if (cs > 1.0 && std::isfinite(cs)) {
1149 const bool hol_softmin = sc == SchedStrategy::HOL &&
opt.multiserver ==
"softmin";
1151 for (std::size_t s : nnz) {
1152 const T dr = hol_softmin ? dcl[s] : ((s == c) ? dcl[c] : one);
1153 load += dr * Xin[s] * d.
Vchain(i, s) * STeffOut(i, s);
1160 const unsigned e =
static_cast<unsigned>(std::llround(cs) - (hol_softmin ? 0 : 1));
1163 for (std::size_t s : nnz)
1170 if (
opt.highvar ==
"hvmva") {
1172 for (std::size_t s : ccl) usum += Ur(i, s);
1173 w = T(STeffOut(i, c) * (one - usum));
1174 for (std::size_t s : ccl)
1175 w += T(STeffOut(i, s) / prio_scaling(s) * Ur(i, s) *
1177 }
else if (
opt.highvar !=
"default") {
1179 "' is not implemented");
1183 if (sc == SchedStrategy::HOL) {
1185 const std::vector<T>
ones(K, one);
1186 w += T((STeffOut(i, c) * (isopen[c] ? Qin(i, c) : selfArvl(i, c)) +
1187 hol_ehprio_backlog(
ones) + hol_np_residual(
ones)) / ps_r);
1189 w += STeffOut(i, c) * (isopen[c] ? Qin(i, c) : selfArvl(i, c));
1190 for (std::size_t s : nnz)
1191 if (s != c) w += STeffOut(i, s) * Qin(i, s);
1198 if (
opt.multiserver ==
"suri") {
1199 T Lm = isopen[c] ? T(deltaclass[c] * Qin(i, c)) : selfArvl(i, c);
1200 if (sc != SchedStrategy::HOL)
1201 for (std::size_t s : nnz)
1202 if (s != c) Lm += Qin(i, s);
1203 if (sc == SchedStrategy::HOL) {
1204 Lm = isopen[c] ? Qin(i, c) : selfArvl(i, c);
1205 const std::vector<T>
ones(K, one);
1206 Wout(i, c) = T(STeffOut(i, c) +
1207 ((STeffOut(i, c) * Lm + hol_ehprio_backlog(
ones)) * suri[i] +
1208 hol_np_residual(
ones)) / ps_r);
1211 Wout(i, c) = T(STeffOut(i, c) / ps_r + STeffOut(i, c) * Lm * suri[i] / ps_r);
1214 if (
opt.multiserver ==
"softmin") {
1218 if (sc == SchedStrategy::HOL) {
1220 (STeffOut(i, c) * (isopen[c] ? Qin(i, c) : selfArvl(i, c)) * Bk[c] +
1221 hol_ehprio_backlog(Bk) + hol_np_residual(Bk)) / ps_r);
1224 const T selfQ = isopen[c] ? Qin(i, c) : selfArvl(i, c);
1226 T wq = T(STeffOut(i, c) * selfQ);
1227 for (std::size_t s : nnz)
1230 wq += T(STeffOut(i, s) * Qin(i, s));
1232 T w = T(STeffOut(i, c) / msterm[i]);
1234 T qfrac = T(nB + one - one / msterm[i]);
1235 if (qfrac < zero) qfrac = zero;
1236 w += T(wq * qfrac / nB);
1243 w += STeffOut(i, c);
1244 if (sc == SchedStrategy::HOL) {
1245 w += T((STeffOut(i, c) * (isopen[c] ? Qin(i, c) : selfArvl(i, c)) * Bk[c] +
1246 hol_ehprio_backlog(Bk) + hol_np_residual(Bk)) / ps_r);
1248 w += STeffOut(i, c) *
1249 (isopen[c] ? T(deltaclass[c] * Qin(i, c)) : selfArvl(i, c)) * Bk[c];
1250 for (std::size_t s : nnz)
1251 if (s != c) w += STeffOut(i, s) * Bk[s] * Qin(i, s);
1265 const std::vector<T> Xprev = X;
1268 forward(Qprev, Xprev, Uprev, Nc, Wout, STeffOut);
1272 for (std::size_t i = 0; i < Q.
rows(); ++i)
1273 for (std::size_t c = 0; c < Q.
cols(); ++c)
1277 "AMVA sweep %d: queue-length residual %.3e",
1280 if (totiter >= max_totiter)
break;
1284 for (std::size_t c : nnz) {
1286 for (std::size_t i = 0; i < M; ++i) sw += Wout(i, c);
1289 }
else if (!isopen[c]) {
1291 for (std::size_t i = 0; i < M; ++i) cyc += d.
Vchain(i, c) * Wout(i, c);
1294 (one - omicron) * Xprev[c]);
1298 for (std::size_t i = 0; i < M; ++i) {
1299 Q(i, c) = T(omicron * X[c] * d.
Vchain(i, c) * Wout(i, c) +
1300 (one - omicron) * Qprev(i, c));
1301 U(i, c) = T(omicron * d.
Vchain(i, c) * STeffOut(i, c) * X[c] +
1302 (one - omicron) * Uprev(i, c));
1307 for (std::size_t i = 0; i < M; ++i)
1308 for (std::size_t c = 0; c < K; ++c)
1310 if (err <=
opt.iter_tol)
break;
1312 if (iter > inner_cap)
break;
1322 QouterPrev = Qchain;
1323 const std::vector<T> XouterPrev = Xchain;
1325 if (linmethod) Xref = XouterPrev;
1328 if (linmethod && std::isfinite(Nt) && Nt > 0.0) {
1329 for (std::size_t s = 0; s < K; ++s) {
1330 if (!std::isfinite(d.
Nchain[s]))
continue;
1331 std::vector<double> Ns = d.
Nchain;
1335 std::vector<T> Xs = Xchain;
1337 for (std::size_t i = 0; i < M; ++i)
1338 for (std::size_t c = 0; c < K; ++c) {
1339 Qs(i, c) = T(Qs(i, c) * shrink);
1340 Us(i, c) = T(Us(i, c) * shrink);
1342 for (std::size_t c = 0; c < K; ++c) Xs[c] = T(Xs[c] * shrink);
1344 const std::vector<T> Xs_in = Xs;
1345 const Matrix<T> Qs_prev = inner_loop(Qs, Xs, Us, Ns, Ws, STs);
1347 for (std::size_t c : nnz) tau[s][c] = T(Xs[c] - XouterPrev[c]);
1366 if (method ==
"qdlin") {
1367 for (std::size_t i = 0; i < M; ++i) {
1368 T qs = zero, qo = zero;
1369 for (std::size_t c = 0; c < K; ++c) {
1370 qs += Qs_prev(i, c);
1371 qo += QouterPrev(i, c);
1382 for (std::size_t i = 0; i < M; ++i)
1383 for (std::size_t c : nnz)
1384 if (std::isfinite(d.
Nchain[c]) && Ns[c] > 0.0)
1392 if (totiter >= max_totiter)
break;
1395 const Matrix<T> Qprev = inner_loop(Qchain, Xchain, Uchain, d.
Nchain, Wtmp, STtmp);
1400 for (std::size_t i = 0; i < M; ++i)
1401 for (std::size_t c = 0; c < K; ++c)
1403 converged = err <=
opt.iter_tol;
1404 if (outer >= 2 && converged)
break;
1405 if (outer >= inner_cap || totiter > max_totiter)
break;
1409 for (std::size_t i = 0; i < M; ++i)
1410 for (std::size_t c = 0; c < K; ++c) Tchain(i, c) = T(Xchain[c] * d.
Vchain(i, c));
1413 for (std::size_t i = 0; i < M; ++i) {
1415 if (!(sc == SchedStrategy::FCFS || sc == SchedStrategy::SIRO || sc == SchedStrategy::PS ||
1416 sc == SchedStrategy::LCFSPR || sc == SchedStrategy::DPS || sc == SchedStrategy::HOL))
1419 for (std::size_t c = 0; c < K; ++c) usum += Uchain(i, c);
1422 for (std::size_t c = 0; c < K; ++c) den += d.
Vchain(i, c) * STeff(i, c) * Xchain[c];
1423 if (den == zero)
continue;
1424 for (std::size_t c = 0; c < K; ++c) {
1425 if (!(d.
Vchain(i, c) * STeff(i, c) > zero))
continue;
1426 Uchain(i, c) = T(one * d.
Vchain(i, c) * STeff(i, c) * Xchain[c] / den);
1431 for (std::size_t i = 0; i < M; ++i)
1432 for (std::size_t c = 0; c < K; ++c)
1433 if (Tchain(i, c) != zero) Rchain(i, c) = T(Qchain(i, c) / Tchain(i, c));
1434 for (std::size_t c = 0; c < K; ++c) {
1435 if (d.
Nchain[c] != 0.0)
continue;
1437 for (std::size_t i = 0; i < M; ++i) {
1438 Uchain(i, c) = zero;
1439 Rchain(i, c) = zero;
1440 Tchain(i, c) = zero;
1452 bool declares_dependence =
false;
1454 if (!st.lldscaling.empty() || st.cdscaling || st.jdscaling) declares_dependence =
true;
1456 L, d,
Matrix<T>(), declares_dependence ? Uchain :
Matrix<T>(), Rchain, Tchain, Xchain);
1476 for (std::size_t ist = 0; ist < M; ++ist) {
1479 "SolverMVA: station '" + L.
stations[ist].name +
1480 "' declares class-dependent service without a peak rate. Utilization at a "
1481 "class-dependent station is reported as T*S/peak, so pass the peak to "
1482 "setClassDependence");
1485 "SolverMVA: station '" + L.
stations[ist].name +
1486 "' declares joint-dependent service without a peak rate; pass the peak to "
1487 "setJointDependence");
1489 bool anyOpen =
false;
1490 for (
const auto& c : L.
classes)
1491 if (std::isinf(c.population)) anyOpen =
true;
1493 const std::size_t Kcls = L.
nclasses;
1494 for (std::size_t ist = 0; ist < M; ++ist) {
1495 const std::vector<T>* peak =
nullptr;
1497 peak = &L.
stations[ist].cdscalingpeak;
1498 else if (L.
stations[ist].jdscaling)
1499 peak = &L.
stations[ist].jdscalingpeak;
1500 if (peak ==
nullptr)
continue;
1501 for (std::size_t k = 0; k < Kcls; ++k) {
1503 const T bmax = k < peak->size() ? (*peak)[k] : zero;
1504 if (std::isfinite(rate) && rate > 0.0 && bmax > zero)
1505 out.
U(ist, k) = T(out.
Tp(ist, k) / L.
rates(ist, k) / bmax);
1507 out.
U(ist, k) = zero;
1518 std::snprintf(buf,
sizeof(buf),
"AMVA finished after %d sweeps", totiter);
1519 line::util::LineConsole::detail(buf);
1537 if (m ==
"amva.qli")
return "qli";
1538 if (m ==
"amva.qd" || m ==
"amva.qdamva" || m ==
"qdamva")
return "qd";
1539 if (m ==
"amva.aql")
return "aql";
1540 if (m ==
"amva.qsa")
return "qsa";
1541 if (m ==
"amva.qdaql")
return "qdaql";
1542 if (m ==
"amva.tay")
return "tay";
1543 if (m ==
"amva.scat")
return "scat";
1544 if (m ==
"amva.lin")
return "lin";
1545 if (m ==
"amva.qdlin")
return "qdlin";
1546 if (m ==
"amva.fli")
return "fli";
1547 if (m ==
"amva.bs")
return "bs";
1548 if (m ==
"amva.ab")
return "ab";
1549 if (m ==
"amva.schmidt")
return "schmidt";
1550 if (m ==
"amva.schmidt-ext")
return "schmidt-ext";
1551 if (m ==
"amva.lcp")
return "lcp";
1552 if (m ==
"amva.chow")
return "chow";
1553 if (m ==
"amva.pamb")
return "pamb";
1554 if (m ==
"amva.pami")
return "pami";
1555 if (m ==
"amva.pamt")
return "pamt";
1556 if (m ==
"amva.clust")
return "clust";
1557 if (m ==
"amva.dmlin")
return "dmlin";
1558 if (m ==
"amva.priomva")
return "priomva";
1559 if (m ==
"amva.marie")
return "marie";
1565 const Matrix<T>& init_sol,
bool& converged) {
1569 opt.iter_max = std::min(
opt.iter_max, 10000);
1573 if (method ==
"default" || method ==
"amva") {
1575 bool anysmall =
false;
1576 for (std::size_t c = 0; c < C; ++c) {
1578 if (d.
Nchain[c] < 1.0) anysmall =
true;
1580 if (Nsum <= 2.0 || anysmall) {
1583 bool anyfinite =
false, allone =
true;
1585 if (std::isfinite(s.nservers)) {
1587 if (s.nservers != 1.0) allone =
false;
1590 method = (anyfinite && allone) ?
"egflin" :
"lin";
1611 return solver_amvald(L, d, o2, method, converged, init_sol);
1616 const bool het_fcfs_own =
1617 (method ==
"ab" || method ==
"schmidt" || method ==
"schmidt-ext");
1622 if (!st.lldscaling.empty()) cond2 =
false;
1628 if (!(cond1 && cond2 && cond3))
return solver_amvald(L, d,
opt, method, converged, init_sol);
1642 std::vector<int> N(C, 0);
1643 for (std::size_t c = 0; c < C; ++c)
1644 N[c] = std::isfinite(d.
Nchain[c]) ?
static_cast<int>(std::llround(d.
Nchain[c]))
1648 std::vector<T> Nt(C, zero);
1649 for (std::size_t c = 0; c < C; ++c)
1653 std::vector<pfqn::SchedStrategy> types;
1654 for (std::size_t a = 0; a < nq; ++a) {
1668 for (std::size_t a = 0; a < nq && !bad; ++a)
1669 for (std::size_t c = 0; c < C; ++c) {
1671 if (Q0(a, c) < zero) {
1680 const bool direct_ms = (method ==
"ab" || method ==
"schmidt" || method ==
"schmidt-ext");
1681 const bool seidmann = (
opt.multiserver ==
"default" ||
opt.multiserver ==
"seidmann");
1688 for (std::size_t a = 0; a < nq; ++a) {
1689 const double c = pf.
S[a];
1690 if (!std::isfinite(c))
continue;
1691 for (std::size_t k = 0; k < C; ++k)
1694 for (std::size_t k = 0; k < C; ++k)
1698 }
else if (
opt.multiserver ==
"softmin") {
1706 std::vector<T> Zsum(C, zero);
1707 for (std::size_t c = 0; c < C; ++c)
1708 for (std::size_t a = 0; a < Zm.rows(); ++a) Zsum[c] += Zm(a, c);
1710 bool allone =
true, anyinf =
false;
1711 for (
double s : pf.
S) {
1712 if (!std::isfinite(s)) anyinf =
true;
1713 else if (s != 1.0) allone =
false;
1717 Matrix<T> Qq(nq, C, zero), Uq(nq, C, zero), Qz(nz, C, zero);
1718 std::vector<T> X(C, zero);
1720 bool have_delay_rows =
false;
1722 if (method ==
"sqni") {
1724 if (!(M == 2 && nq == 1 && nz == 1))
1726 "solver_amva: method 'sqni' applies only to a model of one queueing station and "
1727 "one infinite server");
1730 "solver_amva: method 'sqni' solves a quadratic and evaluates a square root, "
1731 "which exact arithmetic has no representation for; use the double or real "
1734 std::vector<T> Lv(C, zero);
1735 for (std::size_t c = 0; c < C; ++c) Lv[c] = Dm(0, c);
1737 for (std::size_t c = 0; c < C; ++c) {
1744 }
else if (method ==
"bs") {
1745 std::vector<pfqn::AmvaSched> bstype;
1746 for (std::size_t a = 0; a < nq; ++a)
1756 }
else if (method ==
"lcp" || method ==
"chow") {
1760 std::vector<pfqn::AmvaSched> lctype;
1761 for (std::size_t a = 0; a < nq; ++a)
1768 static_cast<std::size_t
>(
opt.iter_max), Q0)
1770 static_cast<std::size_t
>(
opt.iter_max), Q0);
1775 }
else if (method ==
"pamb" || method ==
"pami" || method ==
"pamt") {
1785 }
else if (method ==
"clust") {
1789 Dm, Nt, Zsum, std::vector<std::vector<std::size_t> >(),
1791 static_cast<std::size_t
>(
opt.iter_max));
1796 }
else if (method ==
"dmlin") {
1806 }
else if (method ==
"tay") {
1813 "solver_amva: Tay's approximation is defined for single-server stations; use "
1814 "'default' or 'lin'");
1817 "solver_amva: method 'tay' stops on a tolerance evaluated with transcendentals, "
1818 "which exact arithmetic has no representation for; use the double or real "
1822 Dm, Nt, Zsum,
opt.tol,
static_cast<std::size_t
>(
opt.iter_max), Q0);
1828 }
else if (method ==
"scat") {
1838 }
else if (method ==
"aql") {
1843 "solver_amva: AQL cannot handle multi-server stations; use 'default' or 'lin'");
1846 "solver_amva: method 'aql' stops on a relative tolerance evaluated with "
1847 "transcendentals, which exact arithmetic has no representation for; use the "
1848 "double or real backend");
1857 }
else if (method ==
"qsa") {
1862 "solver_amva: QSA cannot handle multi-server stations; use 'default' or 'lin'");
1865 "solver_amva: method 'qsa' stops on a residual tolerance evaluated with "
1866 "transcendentals, which exact arithmetic has no representation for; use the "
1867 "double or real backend");
1873 static_cast<std::size_t
>(
opt.iter_max));
1879 }
else if (direct_ms) {
1883 std::vector<int> nsfull;
1884 std::vector<pfqn::SchedStrategy> schedfull;
1886 for (std::size_t a = 0; a < nz; ++a) {
1887 for (std::size_t c = 0; c < C; ++c) Dfull(a, c) = pf.
Z(a, c);
1888 nsfull.push_back(1);
1892 for (std::size_t a = 0; a < nq; ++a) {
1893 for (std::size_t c = 0; c < C; ++c) {
1894 Dfull(nz + a, c) = pf.
D(a, c);
1899 const int c_i = std::isfinite(pf.
S[a]) ?
static_cast<int>(std::llround(pf.
S[a])) : 1;
1900 nsfull.push_back(c_i);
1901 Sfull(nz + a, 0) = c_i;
1902 schedfull.push_back(types[a]);
1906 "solver_amva: the Akyildiz-Bolch and Schmidt multiserver methods use marginal "
1907 "weights with non-integer powers and floors, which exact arithmetic has no "
1908 "representation for; use the double or real backend");
1909 }
else if (method ==
"ab") {
1912 for (std::size_t a = 0; a < nq; ++a)
1913 for (std::size_t c = 0; c < C; ++c) {
1914 Qq(a, c) = r.
QN(nz + a, c);
1915 Uq(a, c) = r.
UN(nz + a, c);
1917 for (std::size_t a = 0; a < nz; ++a)
1918 for (std::size_t c = 0; c < C; ++c) Qz(a, c) = r.
QN(a, c);
1920 iters =
static_cast<int>(r.
totiter);
1921 }
else if (method ==
"schmidt") {
1923 for (std::size_t a = 0; a < nq; ++a)
1924 for (std::size_t c = 0; c < C; ++c) Qq(a, c) = r.
QN(nz + a, c);
1925 for (std::size_t a = 0; a < nz; ++a)
1926 for (std::size_t c = 0; c < C; ++c) Qz(a, c) = r.
QN(a, c);
1935 std::vector<double> sx_n(C, 0.0);
1936 for (std::size_t c = 0; c < C; ++c) sx_n[c] = d.
Nchain[c];
1937 std::vector<bool> sx_fcfs;
1938 for (std::size_t a = 0; a < nq; ++a)
1940 SchedStrategy::FCFS);
1941 const std::string sx_reason =
1946 for (std::size_t a = 0; a < nq; ++a)
1947 for (std::size_t c = 0; c < C; ++c) Qq(a, c) = r.
QN(nz + a, c);
1948 for (std::size_t a = 0; a < nz; ++a)
1949 for (std::size_t c = 0; c < C; ++c) Qz(a, c) = r.
QN(a, c);
1953 have_delay_rows =
true;
1956 for (std::size_t a = 0; a < nq; ++a) {
1957 const double c_i = std::isfinite(pf.
S[a]) ? pf.
S[a] : 1.0;
1958 for (std::size_t k = 0; k < C; ++k)
1961 }
else if (method ==
"lin" || method ==
"gflin" || method ==
"egflin") {
1965 if (st.cdscaling || st.jdscaling)
1973 return solver_amvald(L, d, o2, method, converged, init_sol);
1975 if (allone ||
opt.multiserver ==
"krzesinski") {
1976 std::vector<int> ns;
1977 for (std::size_t a = 0; a < nq; ++a)
1978 ns.push_back(std::isfinite(pf.
S[a]) ?
static_cast<int>(std::llround(pf.
S[a])) : 1);
1979 if (allone) ns.assign(nq, 1);
1981 pf.
lambda, Dm, N, Zm, ns, types,
opt.tol,
opt.iter_max, mx, Q0);
1986 }
else if (
opt.multiserver ==
"conway") {
1989 "solver_amva: the Conway multiserver correction evaluates transcendentals, "
1990 "which exact arithmetic has no representation for; use the double or real "
1993 std::vector<int> ns;
1994 for (std::size_t a = 0; a < nq; ++a)
1995 ns.push_back(std::isfinite(pf.
S[a]) ?
static_cast<int>(std::llround(pf.
S[a]))
2004 }
else if (
opt.multiserver ==
"default" ||
opt.multiserver ==
"softmin" ||
2005 opt.multiserver ==
"seidmann" ||
opt.multiserver ==
"suri" ||
2006 opt.multiserver ==
"erlang") {
2017 bool conserves =
true;
2018 for (std::size_t c = 0; c < C && conserves; ++c) {
2019 const double Nc = d.
Nchain[c];
2020 if (!std::isfinite(Nc) || Nc <= 0.0)
continue;
2022 for (std::size_t k : L.
inchain[c])
2023 for (std::size_t i = 0; i < sol.
Q.rows(); ++i) {
2025 if (!std::isnan(v)) qc += v;
2027 if (!std::isfinite(qc) || std::abs(qc - Nc) > 1e-3 * Nc) conserves =
false;
2029 if (converged || conserves)
return sol;
2040 "'. Supported: default, softmin, seidmann, suri, conway, "
2041 "erlang, krzesinski.");
2049 return solver_amvald(L, d, o2, method, converged, init_sol);
2052 Matrix<T> Q(M, C, zero), U(M, C, zero), Tp(M, C, zero), R(M, C, zero);
2053 for (std::size_t a = 0; a < nq; ++a)
2054 for (std::size_t c = 0; c < C; ++c) {
2062 for (std::size_t a = 0; a < nz; ++a)
2063 for (std::size_t c = 0; c < C; ++c) {
2067 (void)have_delay_rows;
2070 if (seidmann && !direct_ms) {
2071 for (std::size_t a = 0; a < nq; ++a) {
2072 const double c = pf.
S[a];
2073 if (!std::isfinite(c) || c <= 1.0)
continue;
2074 for (std::size_t k = 0; k < C; ++k)
2080 for (std::size_t i = 0; i < M; ++i)
2081 for (std::size_t c = 0; c < C; ++c) {
2082 Tp(i, c) = T(d.
Vchain(i, c) * X[c]);
2083 if (Tp(i, c) != zero) R(i, c) = T(Q(i, c) / Tp(i, c));
2088 std::vector<T> Cyc(C, zero);
2089 for (std::size_t c = 0; c < C; ++c) {
2090 if (!(X[c] > zero))
continue;
2092 for (std::size_t a = 0; a < nz; ++a) z += pf.
Z(a, c);
2132 const std::vector<T>& a = L.
stations[i].lldscaling;
2133 const double c = L.
stations[i].nservers;
2134 std::vector<T> row(ncol);
2135 for (std::size_t n = 0; n < ncol; ++n) {
2136 const double k = std::min(
static_cast<double>(n + 1), c);
2138 row[n] = a.empty() ? base : T(base * (n < a.size() ? a[n] : a.back()));
2166 for (std::size_t c = 0; c < C; ++c)
2168 const std::size_t NT =
static_cast<std::size_t
>(std::llround(Nt));
2174 std::vector<T> lambda(C, zero);
2175 std::vector<int> N(C, 0);
2176 std::vector<bool> openChain(C,
false);
2177 std::size_t nOpenChains = 0;
2178 for (std::size_t c = 0; c < C; ++c) {
2179 if (std::isfinite(d.
Nchain[c])) {
2180 N[c] =
static_cast<int>(std::llround(d.
Nchain[c]));
2184 openChain[c] =
true;
2187 if (st > zero) lambda[c] = T(one / st);
2190 Matrix<T> Qchain(M, C, zero), Uchain(M, C, zero);
2191 std::vector<T> Xchain(C, zero);
2192 if (nOpenChains == 0) {
2198 for (std::size_t i = 0; i < M; ++i) {
2199 if (std::isinf(L.
stations[i].nservers)) {
2200 for (std::size_t n = 0; n < NT; ++n)
2208 const std::vector<T> row = detail::mvald_rate_row(L, i, NT);
2209 for (std::size_t n = 0; n < NT; ++n) mu(i, n) = row[n];
2213 for (std::size_t i = 0; i < M; ++i)
2214 for (std::size_t c = 0; c < C; ++c) Dm(i, c) = d.
Lchain(i, c);
2233 std::vector<bool> sourceStation(M,
false), delayStation(M,
false);
2234 for (std::size_t c = 0; c < C; ++c)
2235 if (openChain[c]) sourceStation[
static_cast<std::size_t
>(d.
refstatchain[c] - 1)] =
true;
2236 std::vector<std::size_t> queueStations;
2237 for (std::size_t i = 0; i < M; ++i) {
2238 if (sourceStation[i])
continue;
2239 if (std::isinf(L.
stations[i].nservers))
2240 delayStation[i] =
true;
2242 queueStations.push_back(i);
2244 const std::size_t nq = queueStations.size();
2247 for (std::size_t c = 0; c < C; ++c) {
2249 for (std::size_t i = 0; i < M; ++i)
2250 if (delayStation[i]) z = T(z + d.
Lchain(i, c));
2257 std::size_t ncol = NT > 0 ? NT : 1;
2258 for (std::size_t i = 0; i < M; ++i) ncol = std::max(ncol, L.
stations[i].lldscaling.size());
2259 for (std::size_t k = 0; k < nq; ++k)
2260 ncol = std::max(ncol,
static_cast<std::size_t
>(std::llround(L.
stations[queueStations[k]].nservers)));
2262 for (std::size_t k = 0; k < nq; ++k) {
2263 const std::vector<T> row = detail::mvald_rate_row(L, queueStations[k], ncol);
2264 for (std::size_t n = 0; n < ncol; ++n) mu(k, n) = row[n];
2267 for (std::size_t k = 0; k < nq; ++k)
2268 for (std::size_t c = 0; c < C; ++c) Dq(k, c) = d.
Lchain(queueStations[k], c);
2272 for (std::size_t k = 0; k < nq; ++k)
2273 for (std::size_t c = 0; c < C; ++c) {
2274 Qchain(queueStations[k], c) = pf.
QN(k, c);
2275 Uchain(queueStations[k], c) = pf.
UN(k, c);
2277 for (std::size_t i = 0; i < M; ++i)
2278 if (delayStation[i])
2279 for (std::size_t c = 0; c < C; ++c)
2281 Qchain(i, c) = T(d.
Lchain(i, c) * Xchain[c]);
2296 Matrix<T> Tchain(M, C, zero), Rchain(M, C, zero);
2297 for (std::size_t i = 0; i < M; ++i)
2298 for (std::size_t c = 0; c < C; ++c) {
2299 Tchain(i, c) = T(Xchain[c] * d.
Vchain(i, c));
2300 if (Tchain(i, c) > zero) Rchain(i, c) = T(Qchain(i, c) / Tchain(i, c));
2319 bool anyLld =
false;
2320 for (std::size_t i = 0; i < M; ++i)
2321 if (!L.
stations[i].lldscaling.empty()) anyLld =
true;
2322 for (std::size_t i = 0; i < M; ++i) {
2323 if (!anyLld || !std::isfinite(L.
stations[i].nservers))
continue;
2324 double ceff = L.
stations[i].nservers;
2325 for (
const T& v : L.
stations[i].lldscaling)
2327 for (std::size_t r = 0; r < L.
nclasses; ++r) {
2329 const T st = L.
rates(i, r) > zero ? T(one / L.
rates(i, r)) : zero;
2360 "solver_mva_sum: the summation method locates the root of its population constraint "
2361 "by bisection and evaluates the Erlang-C waiting probability, neither of which exact "
2362 "arithmetic has a representation for; use the double or real backend");
2364 std::vector<std::size_t> rows;
2365 std::vector<sum::Servers> mi;
2366 for (std::size_t i = 0; i < M; ++i) {
2368 if (sc == SchedStrategy::EXT)
continue;
2369 if (sc == SchedStrategy::INF) {
2374 if (sc == SchedStrategy::PS || sc == SchedStrategy::LCFSPR ||
2375 sc == SchedStrategy::FCFS || sc == SchedStrategy::SIRO) {
2377 const double c = L.
stations[i].nservers;
2378 mi.push_back(std::isfinite(c) ?
sum::Servers::of(
static_cast<long>(std::llround(c)))
2387 const std::size_t Mr = rows.size();
2388 Matrix<T> Lm(Mr, K, zero), scv(Mr, K, one);
2389 for (std::size_t a = 0; a < Mr; ++a) {
2390 const std::size_t i = rows[a];
2391 const bool sensitive = L.
stations[i].sched == SchedStrategy::FCFS ||
2392 L.
stations[i].sched == SchedStrategy::SIRO;
2393 for (std::size_t c = 0; c < K; ++c) {
2395 if (!sensitive)
continue;
2401 std::vector<long> N(K, 0);
2402 std::vector<T> Z(K, zero);
2403 std::vector<std::size_t> ocl;
2404 for (std::size_t c = 0; c < K; ++c) {
2405 if (std::isfinite(d.
Nchain[c])) N[c] =
static_cast<long>(std::llround(d.
Nchain[c]));
2406 else ocl.push_back(c);
2410 std::vector<T> Xchain;
2411 std::size_t iters = 0;
2415 so.
maxiter =
static_cast<std::size_t
>(
opt.iter_max);
2422 std::vector<T> lambda(K, zero), scva(K, one);
2423 for (std::size_t c : ocl) {
2433 "solver_mva_sum: open chain " + std::to_string(c + 1) +
2434 " has a non-positive service time at its reference station, so it carries no "
2435 "arrival rate; the summation method cannot place it");
2436 lambda[c] = T(one / st);
2450 Matrix<T> Qchain(M, K, zero), Uchain(M, K, zero), Tchain(M, K, zero), Rchain(M, K, zero);
2451 for (std::size_t a = 0; a < Mr; ++a)
2452 for (std::size_t c = 0; c < K; ++c) {
2453 Qchain(rows[a], c) = Qrows(a, c);
2454 Uchain(rows[a], c) = Urows(a, c);
2456 for (std::size_t i = 0; i < M; ++i)
2457 for (std::size_t c = 0; c < K; ++c) {
2458 Tchain(i, c) = T(Xchain[c] * d.
Vchain(i, c));
2459 if (Tchain(i, c) > zero) Rchain(i, c) = T(Qchain(i, c) / Tchain(i, c));
2461 for (std::size_t c = 0; c < K; ++c) {
2462 if (d.
Nchain[c] != 0.0)
continue;
2464 for (std::size_t i = 0; i < M; ++i) {
2465 Qchain(i, c) = zero;
2466 Uchain(i, c) = zero;
2467 Rchain(i, c) = zero;
2468 Tchain(i, c) = zero;
2482 out.
iter =
static_cast<int>(iters);
2514 "solver_sqd: the blocking-after-service calibration evaluates exp, log and real "
2515 "powers, which exact rational arithmetic cannot represent");
2521 "solver_sqd: Smith queue decomposition supports single-chain closed networks only; "
2522 "this model has " + std::to_string(L.
nchains) +
" chains");
2530 "solver_sqd: Smith queue decomposition is defined for a CLOSED population; this model "
2531 "has an open class, whose jobs the fixed point cannot count");
2533 std::vector<T> ST(M, zero), V(M, zero), cap(M, zero);
2534 std::vector<bool> isDelay(M,
false);
2535 std::vector<std::size_t> s2sf(M, 0);
2537 for (std::size_t i = 0; i < M; ++i) {
2540 isDelay[i] = (L.
stations[i].sched == SchedStrategy::INF ||
2541 L.
stations[i].sched == SchedStrategy::EXT);
2543 const double c = L.
cap.empty() ? std::numeric_limits<double>::infinity() : L.
cap[i];
2544 cap[i] = (isDelay[i] || !(c <= 1e14)) ? inf : num_traits<T>::from_double(c);
2551 static_cast<int>(std::llround(L.
nclosedjobs())), sopt);
2556 Matrix<T> Tchain(M, 1, zero), Qchain(M, 1, zero), Uchain(M, 1, zero), Rchain(M, 1, zero);
2557 for (std::size_t i = 0; i < M; ++i) {
2558 Tchain(i, 0) = r.
X[i];
2559 Qchain(i, 0) = r.
Q[i];
2560 Uchain(i, 0) = r.
U[i];
2561 Rchain(i, 0) = r.
R[i];
2563 std::vector<T> Xchain(1, r.
X[refstat - 1]);
2575 out.
lG = std::numeric_limits<double>::quiet_NaN();
2597 const std::string alt =
" Use SolverCTMC or SolverJMT instead.";
2598 for (
const auto& c : L.
classes)
2599 if (std::isinf(c.population))
2600 return {
"MVABLO is defined for closed networks only; this model has an open class." + alt,
"OpenClass"};
2602 return {
"MVABLO supports a single closed class; this model has " + std::to_string(L.
nclasses) +
2603 " classes (class switching included)." + alt,
"MultiClass"};
2604 if (!(L.
nclosedjobs() > 0.0))
return {
"MVABLO requires a positive closed population." + alt,
"ClosedClass"};
2605 for (
const auto& n : L.
nodes)
2606 if (n.nodetype == qn::NodeType::Fork || n.nodetype == qn::NodeType::Join)
2607 return {
"MVABLO does not support fork-join." + alt,
"Fork"};
2609 return {
"MVABLO supports networks whose stateful nodes are all stations (queues and delays)." + alt,
"Node"};
2611 for (std::size_t i = 0; i < M; ++i) {
2613 if (!st.lldscaling.empty() || st.cdscaling || st.jdscaling)
2614 return {
"MVABLO does not support load-, class- or joint-dependent service." + alt,
"LoadDependence"};
2616 auto is_delay = [&](std::size_t i) {
return L.
stations[i].sched == SchedStrategy::INF; };
2617 for (std::size_t i = 0; i < M; ++i) {
2619 if (!is_delay(i) && st.sched != SchedStrategy::FCFS) {
2621 for (
char& ch : s) ch =
static_cast<char>(std::toupper(
static_cast<unsigned char>(ch)));
2622 return {
"MVABLO supports FCFS queues and INF delays; station " + st.name +
" is " + s +
"." + alt,
2625 if (!is_delay(i) && st.nservers != 1.0)
2626 return {
"MVABLO supports single-server queues; station " + st.name +
" has " +
2627 std::to_string(
static_cast<long>(st.nservers)) +
" servers." + alt,
"MultiServer"};
2629 return {
"MVABLO requires exponential service; station " + st.name +
" is not exponential." + alt,
2634 auto rt = [&](std::size_t j, std::size_t i) {
2637 auto is_bas = [&](std::size_t i) {
2640 for (std::size_t i = 0; i < M; ++i) {
2641 const double cap = L.
cap.empty() ? std::numeric_limits<double>::infinity() : L.
cap[i];
2642 if (is_delay(i) || std::isinf(cap) || cap >= N)
continue;
2643 bool bas = is_bas(i);
2644 for (std::size_t j = 0; j < M && !bas; ++j) bas = is_bas(j) && rt(j, i);
2646 return {
"MVABLO models Blocking-After-Service only; the finite buffer of station " +
2647 L.
stations[i].name +
" has no BAS drop rule." + alt,
"FiniteCapacity"};
2648 for (std::size_t j = 0; j < M; ++j)
2649 if (is_delay(j) && rt(j, i))
2650 return {
"MVABLO cannot block a delay: " + L.
stations[j].name +
" feeds the finite buffer of " +
2651 L.
stations[i].name +
"." + alt,
"Delay"};
2653 return {std::string(), std::string()};
2673 std::vector<T> S(M, zero);
2674 std::vector<double> K(M, std::numeric_limits<double>::infinity());
2675 std::vector<bool> isdelay(M,
false);
2677 for (std::size_t i = 0; i < M; ++i) {
2678 isdelay[i] = L.
stations[i].sched == qn::SchedStrategy::INF;
2679 S[i] = T(one / L.
service[i][0].rate());
2680 if (!isdelay[i] && !L.
cap.empty()) K[i] = L.
cap[i];
2681 for (std::size_t j = 0; j < M; ++j)
2686 const std::size_t ref = L.
classes[0].refstat - 1;
2692 for (std::size_t i = 0; i < M; ++i) {
2693 out.
Q(i, 0) = r.
Q[i];
2694 out.
U(i, 0) = r.
U[i];
2695 out.
R(i, 0) = r.
R[i];
2696 out.
Tp(i, 0) = r.
X[i];
2703 out.
lG = std::numeric_limits<double>::quiet_NaN();
2725 const std::string alt =
" Use SolverCTMC or SolverJMT instead.";
2726 for (
const auto& c : L.
classes)
2727 if (std::isinf(c.population))
2728 return {
"debeMVA is defined for closed networks only; this model has an open class." + alt,
"OpenClass"};
2730 return {
"debeMVA supports a single closed class; this model has " + std::to_string(L.
nclasses) +
2731 " classes (class switching included)." + alt,
"MultiClass"};
2732 if (!(L.
nclosedjobs() > 0.0))
return {
"debeMVA requires a positive closed population." + alt,
"ClosedClass"};
2733 for (
const auto& n : L.
nodes)
2734 if (n.nodetype == qn::NodeType::Fork || n.nodetype == qn::NodeType::Join)
2735 return {
"debeMVA does not support fork-join." + alt,
"Fork"};
2737 return {
"debeMVA supports networks whose stateful nodes are all stations (queues and delays)." + alt,
"Node"};
2739 for (std::size_t i = 0; i < M; ++i) {
2741 if (!st.lldscaling.empty() || st.cdscaling || st.jdscaling)
2742 return {
"debeMVA does not support load-, class- or joint-dependent service." + alt,
"LoadDependence"};
2744 auto is_delay = [&](std::size_t i) {
return L.
stations[i].sched == SchedStrategy::INF; };
2745 for (std::size_t i = 0; i < M; ++i) {
2747 if (!is_delay(i) && st.sched != SchedStrategy::FCFS) {
2749 for (
char& ch : s) ch =
static_cast<char>(std::toupper(
static_cast<unsigned char>(ch)));
2750 return {
"debeMVA supports FCFS queues and INF delays; station " + st.name +
" is " + s +
"." + alt,
2753 if (!is_delay(i) && st.nservers != 1.0)
2754 return {
"debeMVA supports single-server queues; station " + st.name +
" has " +
2755 std::to_string(
static_cast<long>(st.nservers)) +
" servers." + alt,
"MultiServer"};
2758 return {
"debeMVA requires exponential service at queues; station " + st.name +
" is not exponential." +
2759 alt,
"Distribution"};
2762 const double inf = std::numeric_limits<double>::infinity();
2763 for (std::size_t i = 0; i < M; ++i) {
2764 const double cap = L.
cap.empty() ? inf : L.
cap[i];
2765 if (is_delay(i) && !std::isinf(cap) && cap < N)
2766 return {
"debeMVA treats a delay as never full; station " + L.
stations[i].name +
" has capacity " +
2767 std::to_string(
static_cast<long>(cap)) +
" below the population." + alt,
"FiniteCapacity"};
2770 auto rt = [&](std::size_t j, std::size_t i) {
2773 auto is_bas = [&](std::size_t i) {
2776 for (std::size_t i = 0; i < M; ++i) {
2777 const double cap = L.
cap.empty() ? inf : L.
cap[i];
2778 if (is_delay(i) || std::isinf(cap) || cap >= N)
continue;
2779 bool bas = is_bas(i);
2780 for (std::size_t j = 0; j < M && !bas; ++j) bas = is_bas(j) && rt(j, i);
2782 return {
"debeMVA models Blocking-After-Service only; the finite buffer of station " +
2783 L.
stations[i].name +
" has no BAS drop rule." + alt,
"FiniteCapacity"};
2785 return {std::string(), std::string()};
2803 std::vector<T> S(M, zero);
2804 std::vector<double> K(M, std::numeric_limits<double>::infinity());
2805 std::vector<bool> isdelay(M,
false);
2807 for (std::size_t i = 0; i < M; ++i) {
2808 isdelay[i] = L.
stations[i].sched == qn::SchedStrategy::INF;
2809 S[i] = T(one / L.
rates(i, 0));
2810 if (!isdelay[i] && !L.
cap.empty()) K[i] = L.
cap[i];
2811 for (std::size_t j = 0; j < M; ++j)
2815 const long budget = std::max<long>(
opt.iter_max, 100000L);
2819 const std::size_t ref = L.
classes[0].refstat - 1;
2825 for (std::size_t i = 0; i < M; ++i) {
2826 out.
Q(i, 0) = r.
Q[i];
2827 out.
U(i, 0) = r.
U[i];
2828 out.
R(i, 0) = r.
R[i];
2829 out.
Tp(i, 0) = r.
X[i];
2834 out.
iter =
static_cast<int>(std::min<long>(r.
iter, std::numeric_limits<int>::max()));
2836 out.
lG = std::numeric_limits<double>::quiet_NaN();
2865 const std::string alt =
" Use SolverCTMC, SolverLDES or SolverJMT instead.";
2867 auto refuse = [&](
const std::string& why,
const char* kind) {
2875 if (L.
regions.empty())
return refuse(
"OQNRC needs a finite capacity region (addRegion) holding the inner system.",
"Region");
2877 return refuse(
"OQNRC supports a single finite capacity region; this model has " +
2878 std::to_string(L.
regions.size()) +
".",
"Region");
2879 for (
const auto& c : L.
classes)
2880 if (!std::isinf(c.population))
2881 return refuse(
"OQNRC is defined for open networks only; this model has a closed class.",
"ClosedClass");
2882 for (
const auto& n : L.
nodes)
2883 if (n.nodetype == qn::NodeType::Fork || n.nodetype == qn::NodeType::Join)
2884 return refuse(
"OQNRC does not support fork-join.",
"Fork");
2886 return refuse(
"OQNRC supports networks whose stateful nodes are all stations (Source, queues and delays).",
2888 for (std::size_t i = 0; i < M; ++i) {
2890 if (!st.lldscaling.empty() || st.cdscaling || st.jdscaling)
2891 return refuse(
"OQNRC does not support load-, class- or joint-dependent service.",
"LoadDependence");
2893 const auto& rg = L.
regions[0];
2894 auto member = [&](std::size_t i) {
return i < rg.members.size() && rg.members[i]; };
2896 for (std::size_t i = 0; i < M; ++i) {
2898 if (st.nodetype == qn::NodeType::Source) {
2899 if (member(i))
return refuse(
"OQNRC cannot place the Source inside the region.",
"Region");
2900 if (src < 0) src =
static_cast<long>(i);
2903 if (st.sched != SchedStrategy::FCFS && st.sched != SchedStrategy::PS && st.sched != SchedStrategy::INF) {
2905 for (
char& ch : s) ch =
static_cast<char>(std::toupper(
static_cast<unsigned char>(ch)));
2906 return refuse(
"OQNRC supports FCFS, PS and INF stations; station " + st.name +
" is " + s +
".",
2909 const double cp = L.
cap.size() > i ? L.
cap[i] : std::numeric_limits<double>::infinity();
2910 if (std::isfinite(cp) && cp >= 0 && st.sched != SchedStrategy::INF)
2911 return refuse(
"OQNRC models the region cap only; station " + st.name +
2912 " also has a finite buffer (setCapacity).",
"FiniteCapacity");
2914 return refuse(
"OQNRC needs the region to hold every station but the Source; station " + st.name +
2915 " is outside it.",
"Region");
2917 for (std::size_t i = 0; i < M && i < rg.maxmem.size(); ++i)
2918 if (member(i) && rg.maxmem[i] != -1)
2919 return refuse(
"OQNRC does not support a region memory budget (setGlobalMaxMemory).",
"Region");
2920 bool allW =
true, allD =
true;
2921 for (std::size_t r = 0; r < K; ++r) {
2927 return refuse(
"OQNRC needs the same drop rule on every class of the region, either WAITQ (the paper's "
2928 "external queue) or DROP (loss).",
"Region");
2930 std::size_t first = M;
2931 for (std::size_t i = 0; i < M && first == M; ++i)
2932 if (member(i)) first = i;
2933 if (first == M)
return refuse(
"OQNRC needs the region to hold the inner stations.",
"Region");
2934 auto capat = [&](std::size_t r) {
2935 return first < rg.cap.size() && r < rg.cap[first].size() ? rg.cap[first][r] : -1.0;
2937 const double gcap = capat(K);
2938 bool unset =
true, allpos =
true;
2939 for (std::size_t r = 0; r < K; ++r) {
2940 unset = unset && capat(r) == -1;
2941 allpos = allpos && capat(r) > 0;
2943 if (rg.lincon_A.rows() > 0) {
2944 if (gcap != -1 || !unset)
2945 return refuse(
"OQNRC supports linear constraints only without a global or per-class cap on the same "
2946 "region.",
"Region");
2947 const std::size_t C = rg.lincon_A.rows();
2948 bool ok = rg.lincon_A.cols() == K && rg.lincon_b.size() >= C;
2949 sc.
pool.assign(K, 0);
2950 sc.
Ncap.assign(C, 0);
2951 for (std::size_t r = 0; ok && r < K; ++r) {
2953 for (std::size_t c = 0; c < C; ++c) {
2955 ok = ok && (a == 0 || a == 1);
2957 if (a == 1) sc.
pool[r] =
static_cast<int>(c);
2959 ok = ok && colsum == 1;
2961 for (std::size_t c = 0; ok && c < C; ++c) {
2963 for (std::size_t r = 0; r < K; ++r) rowsum += num_traits<T>::to_double(rg.lincon_A(c, r));
2965 ok = ok && rowsum > 0 && b >= 1 && b == std::rint(b);
2966 if (ok) sc.
Ncap[c] =
static_cast<int>(b);
2969 return refuse(
"OQNRC supports linear constraints only as a partition of the classes into groups with "
2970 "unit weights and a positive integer cap per group (dedicated token pools).",
"Region");
2971 }
else if (gcap > 0 && unset) {
2972 sc.
pool.assign(K, 0);
2973 sc.
Ncap.assign(1,
static_cast<int>(gcap));
2974 }
else if (gcap == -1 && allpos) {
2975 sc.
pool.assign(K, 0);
2976 sc.
Ncap.assign(K, 0);
2977 for (std::size_t r = 0; r < K; ++r) {
2978 sc.
pool[r] =
static_cast<int>(r);
2979 sc.
Ncap[r] =
static_cast<int>(capat(r));
2982 return refuse(
"OQNRC needs either a global cap alone (setGlobalMaxJobs) or a per-class cap on every class "
2983 "(setClassMaxJobs), not both and not a partial set.",
"Region");
2985 for (std::size_t c = 0; c < L.
nchains; ++c) {
2987 for (std::size_t r = 0; r < K; ++r)
2989 if (p >= 0 && sc.
pool[r] != p)
2990 return refuse(
"OQNRC needs class switching to stay within one token pool; a chain here switches "
2991 "between classes with separate caps.",
"ClassSwitch");
2995 for (std::size_t g = 0; g < sc.
Ncap.size(); ++g) {
2997 for (std::size_t r = 0; r < K; ++r)
2998 if (src >= 0 && sc.
pool[r] ==
static_cast<int>(g) && !L.
disabled[src][r])
3001 return refuse(
"OQNRC needs a positive arrival rate into every token pool; pool " + std::to_string(g + 1) +
3002 " has none.",
"Structure");
3028 std::size_t src = M;
3029 std::vector<std::size_t> inner;
3030 for (std::size_t i = 0; i < M; ++i) {
3031 if (L.
stations[i].nodetype == qn::NodeType::Source) {
3032 if (src == M) src = i;
3037 const std::size_t nin = inner.size();
3038 std::vector<double> lam(K, 0.0);
3039 for (std::size_t r = 0; r < K; ++r) lam[r] = L.
disabled[src][r] ? 0.0 : td(L.
rates(src, r));
3042 for (std::size_t c = 0; c < L.
nchains; ++c) {
3044 double vref = 0, lamc = 0;
3045 for (std::size_t r = 0; r < K; ++r)
3047 vref += td(Vc(srcSf, r));
3050 if (vref <= 0)
continue;
3051 for (std::size_t r = 0; r < K; ++r)
3053 for (std::size_t k = 0; k < nin; ++k)
3056 std::vector<double> nservers(nin, 1.0);
3057 std::vector<bool> isps(nin,
false);
3058 for (std::size_t k = 0; k < nin; ++k) {
3059 const std::size_t i = inner[k];
3060 for (std::size_t r = 0; r < K; ++r) {
3062 const double mu = td(L.
rates(i, r));
3063 S(k, r) = mu > 0 && std::isfinite(mu) ? 1.0 / mu : 0.0;
3064 const double v = td(L.
scv(i, r));
3065 SCV(k, r) = std::isfinite(v) ? v : 1.0;
3068 nservers[k] = sch == qn::SchedStrategy::INF ? std::numeric_limits<double>::infinity() : L.
stations[i].nservers;
3069 isps[k] = sch == qn::SchedStrategy::PS;
3072 pfqn::pfqn_oqnrc(lam, A, S, SCV, nservers, isps, sc.
pool, sc.
Ncap, sc.
waitq,
opt.tol,
opt.iter_max);
3079 for (std::size_t k = 0; k < nin; ++k)
3080 for (std::size_t r = 0; r < K; ++r) {
3081 out.
Q(inner[k], r) = fd(res.
Q(k, r));
3082 out.
U(inner[k], r) = fd(res.
U(k, r));
3083 out.
R(inner[k], r) = fd(res.
R(k, r));
3084 out.
Tp(inner[k], r) = fd(res.
T(k, r));
3086 for (std::size_t r = 0; r < K; ++r) out.
Tp(src, r) = fd(lam[r]);
3089 for (std::size_t c = 0; c < L.
nchains; ++c) {
3090 double x = 0, qs = 0;
3091 for (std::size_t r = 0; r < K; ++r)
3094 for (std::size_t k = 0; k < nin; ++k) qs += res.
Q(k, r);
3097 out.
C[c] = fd(x > 0 ? qs / x : 0.0);
3099 out.
QNfcr.assign(K, zero);
3100 out.
TNfcr.assign(K, zero);
3101 out.
RNfcr.assign(K, zero);
3103 for (std::size_t r = 0; r < K; ++r) {
3104 double qs = res.
Qext[r];
3105 for (std::size_t k = 0; k < nin; ++k) qs += res.
Q(k, r);
3106 out.
QNfcr[r] = fd(qs);
3107 out.
TNfcr[r] = fd(res.
X[r]);
3108 out.
RNfcr[r] = fd(res.
X[r] > 0 ? qs / res.
X[r] : 0.0);
3114 out.
lG = std::numeric_limits<double>::quiet_NaN();
3126 for (
const auto& c : L.
classes)
3127 if (std::isinf(c.population))
return false;
3146 for (
const auto& c : L.
classes)
3147 if (std::isinf(c.population))
return false;
3164 std::size_t nsrc = 0, nq = 0, nsnk = 0;
3166 if (nd.
nodetype == qn::NodeType::Source) ++nsrc;
3167 else if (nd.
nodetype == qn::NodeType::Queue) ++nq;
3168 else if (nd.
nodetype == qn::NodeType::Sink) ++nsnk;
3170 if (nsrc != 1 || nq != 1 || nsnk != 1)
return false;
3171 std::size_t qist = 0, sist = 0;
3172 for (std::size_t i = 0; i < L.
stations.size(); ++i) {
3173 if (L.
stations[i].nodetype == qn::NodeType::Queue) qist = i + 1;
3174 else if (L.
stations[i].nodetype == qn::NodeType::Source) sist = i + 1;
3176 if (qist == 0 || sist == 0)
return false;
3177 if (L.
stations[qist - 1].nservers != 1.0)
return false;
3178 if (L.
droprule.size() < qist || L.
droprule[qist - 1].empty())
return false;
3180 if (L.
cap.size() < qist)
return false;
3181 if (!std::isfinite(L.
cap[qist - 1]) || L.
cap[qist - 1] <= 0.0)
return false;
3184 if (std::fabs(scvs - 1.0) > 1e-6 || std::fabs(scvq - 1.0) > 1e-6)
return false;
3204 bool has_ld =
false;
3206 if (!st.lldscaling.empty() || st.cdscaling || st.jdscaling) has_ld =
true;
3228 for (
const auto& nd : L.
nodes)
3229 if (nd.nodetype == qn::NodeType::Fork)
return false;
3230 const std::string& method =
opt.method;
3231 bool has_open =
false, has_closed =
false, integral =
true, has_finite_server =
false;
3232 double maxsrv = -1.0, Nsum = 0.0;
3233 for (
const auto& c : L.
classes) {
3234 if (std::isinf(c.population)) {
3237 if (c.population > 0.0) has_closed =
true;
3238 if (c.population != std::floor(c.population)) integral =
false;
3240 Nsum += c.population;
3243 if (std::isfinite(st.nservers)) {
3244 has_finite_server =
true;
3245 maxsrv = std::max(maxsrv, st.nservers);
3248 const bool pfqn_mva_can_take_it = !has_open && integral && (maxsrv < 0.0 || maxsrv <= 1.0);
3250 if (method ==
"exact" || method ==
"mva")
return pfqn_mva_can_take_it;
3251 static const char* amva_methods[] = {
3252 "amva",
"bs",
"qd",
"qli",
"fli",
"lin",
"qdlin",
"sqni",
3253 "gflin",
"egflin",
"ab",
"schmidt",
"schmidt-ext",
"tay",
"scat",
"aql",
3254 "qsa",
"lcp",
"chow",
"pamb",
"pami",
"pamt",
"clust",
"dmlin",
3256 for (
const char* m : amva_methods)
3258 if (method ==
"default") {
3260 const bool exact_mixed = has_open && has_closed && has_finite_server && maxsrv == 1.0 &&
3264 if (exact_mixed || exact_small)
return pfqn_mva_can_take_it;
3280 bool converged =
true;
3291 if (
opt.method ==
"qna")
3293 "solver_mva_analyzer: 'qna' is dispatched by mva_dispatch, not by the analyzer");
3294 if (
opt.method ==
"rqt")
3296 "solver_mva_analyzer: 'rqt' is dispatched by mva_dispatch, not by the analyzer");
3297 if (
opt.method ==
"rqna")
3299 "solver_mva_analyzer: 'rqna' is dispatched by mva_dispatch, not by the analyzer");
3300 if (
opt.method !=
"default") {
3312 if (st.cdscaling || st.jdscaling) {
3320 bool il_needs_amva =
false;
3321 if (!
opt.interlock.empty()) {
3324 if (std::isfinite(st.nservers) && st.nservers > 1.0) il_needs_amva =
true;
3329 bool anyopen =
false, anyclosed =
false, integral =
true;
3330 for (
const auto& cl : L.
classes) {
3331 if (std::isinf(cl.population)) {
3335 if (cl.population > 0.0) anyclosed =
true;
3336 if (cl.population != std::floor(cl.population)) integral =
false;
3338 bool anyfinite =
false, allone =
true;
3340 if (std::isfinite(st.nservers)) {
3342 if (st.nservers != 1.0) allone =
false;
3344 if (anyopen && anyclosed && anyfinite && allone && integral && L.
has_product_form())
3358 if (!il_needs_amva) {
3359 bool all_open =
true, has_finite_server =
false, has_lld =
false;
3360 for (
const auto& cl : L.
classes)
3361 if (!std::isinf(cl.population)) all_open =
false;
3362 for (
const auto& st : L.
stations) {
3363 if (std::isfinite(st.nservers) && st.nservers >= 1.0) has_finite_server =
true;
3364 if (!st.lldscaling.empty()) has_lld =
true;
3377 for (std::size_t c = 0; c < L.
nchains; ++c) Nsum += d.
Nchain[c];
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
bool has_multi_class_heter_fcfs() const
bool has_class_switching() const
std::size_t stateful_of_station(std::size_t st) const
std::size_t nof_stateful() const
std::vector< std::size_t > stateful_nodes
1-based node indices, ascending
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 > > chains
(nchains x nclasses)
std::vector< bool > fjauxclass
sn.fjauxclass: (nclasses+1, 1-based) true where the class is an MMT AUXILIARY OPEN class,...
std::vector< std::vector< bool > > disabled
Matrix< T > rt
sn.rt and sn.rtnodes: the class-expanded routing.
bool has_priorities() const
std::vector< double > cap
sn.cap and sn.classcap: the total and per-class buffers.
std::vector< JobClass > classes
bool has_product_form_not_het_fcfs(bool check_means=true) const
Port of sn_has_product_form_not_het_fcfs: LCFS is excluded, and at FCFS the service must be exponenti...
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
bool has_multi_server() const
std::vector< NodeDef > nodes
every node, in creation order
bool has_sd_routing() const
sn_has_sd_routing: RROBIN, WRROBIN, JSQ, SQ or SDR at some node.
bool has_open_classes() const
bool sched_is_product_form() const
std::vector< std::vector< DropStrategy > > droprule
bool has_blocking() const
Some station can REFUSE a job: its own buffer BINDS, or a finite capacity region caps a set of statio...
std::vector< Matrix< T > > visits
(nchains) each (nstateful x nclasses)
bool has_homogeneous_scheduling(SchedStrategy strategy) const
Port of sn_has_homogeneous_scheduling: true when EVERY station uses strategy, the reference's length(...
double nclosedjobs() const
sn.nclosedjobs: the total population of the closed classes.
std::vector< std::pair< std::size_t, std::size_t > > fj
fj(f,j): the Join node j that closes the Fork node f, 1-based.
bool has_product_form() const
sn_has_product_form, conjunct for conjunct.
bool has_fractional_populations() const
std::vector< Region > regions
static void loop(const char *fmt,...)
Announce an iteration loop and reset its reporting budget.
static void iter(long k, const char *fmt,...)
Report iteration k of the current loop.
static bool owns_log()
True only inside the OUTERMOST open run; gates EMISSION.
The exception types the port throws.
Running progress log of a LINE solver run (the "solver console").
options.timeout: one wall-clock budget per top-level solve, on a per-THREAD deadline stack.
The option and result types every MVA analyzer shares.
bool sn_has_product_form(const qn::NetworkStruct< T > &sn)
Port of sn_has_product_form.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
DropStrategy
Blocking and loss rules, with the values of MATLAB DropStrategy.
const char * sched_to_text(SchedStrategy s)
std::function< std::vector< T >(const std::vector< T > &)> CdScaling
A class-dependent scaling map, sn.cdscaling.
std::pair< std::string, std::string > mvablo_scope_reason(const qn::NetworkStruct< T > &L)
Port of mvablo_scope_reason.m: why method 'mvablo' cannot solve L, as {reason, kind}...
PfChainParams< T > sn_get_product_form_chain_params(const qn::NetworkStruct< T > &L, const ChainDemands< T > &d)
Port of sn_get_product_form_chain_params.
MvaSolution< T > solver_oqnrc(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_oqnrc.m.
MvaSolution< T > solver_mva(const qn::NetworkStruct< T > &L, const ChainDemands< T > &d, const MvaOptions &opt)
Port of solver_mva.m, closed and mixed product-form networks.
MvaSolution< T > solver_mvablo(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mvablo.m.
MvaSolution< T > solver_amvald(const qn::NetworkStruct< T > &L, const ChainDemands< T > &d, const MvaOptions &opt, const std::string &method, bool &converged, const Matrix< T > &init_sol=Matrix< T >())
Port of solver_amvald.m together with solver_amvald_forward.m, restricted to the INF / PS / FCFS-fami...
std::string mva_schmidt_ext_reason(const std::vector< double > &njobs, const std::vector< bool > &fcfs, const std::string &method)
The extended Schmidt method needs a customer of every class to tag.
bool sn_is_mm1k_loss(const qn::NetworkStruct< T > &L)
Port of matlab/src/api/sn/sn_is_mm1k_loss.m: a single-class open Source-Queue-Sink system whose queue...
bool amva_uses_pf_kernels(const qn::NetworkStruct< T > &L)
Conservative form of the branch test in solver_amva: true when this model may be solved by the produc...
std::string amva_method_alias(const std::string &m)
The amva.
OqnrcScope oqnrc_scope(const qn::NetworkStruct< T > &L)
Port of oqnrc_scope_reason.m: why method 'oqnrc' cannot solve L, with the error kind of the refusal,...
bool sn_is_bas_model(const qn::NetworkStruct< T > &L)
Port of matlab/src/api/sn/sn_is_bas_model.m: a closed single-CLASS model with a BAS drop rule.
Matrix< T > sn_interlock_chain(const qn::NetworkStruct< T > &L, const std::vector< std::vector< double > > &ILclass)
Aggregate a class-indexed interlock matrix to the chain basis the MVA analyzers work in.
MvaSolution< T > solver_mva_sum(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_sum.m: the SUM / ESUM summation method (Bolch et al., Secs.
bool mva_is_bas_model(const qn::NetworkStruct< T > &L)
Port of isBasModel in solver_mva_analyzer.m: a closed single-CHAIN model with at least one blocking-a...
std::pair< std::string, std::string > debemva_scope_reason(const qn::NetworkStruct< T > &L)
Port of debemva_scope_reason.m: why method 'debemva' cannot solve L, as {reason, kind}...
ClassResults< T > sn_deaggregate_chain_results(const qn::NetworkStruct< T > &L, const ChainDemands< T > &d, const Matrix< T > &Qchain, const Matrix< T > &Uchain, const Matrix< T > &Rchain, const Matrix< T > &Tchain, const std::vector< T > &Xchain)
Port of sn_deaggregate_chain_results.
MvaSolution< T > solver_sqd(const qn::NetworkStruct< T > &L, const ChainDemands< T > &d)
Port of solver_sqd.m: Smith queue decomposition for blocking-after-service.
std::string mva_closed_population_reason(const qn::NetworkStruct< T > &L, const std::string &method)
The closed-population AMVA family: an open chain, or a network outside strict product form,...
MvaSolution< T > solver_mvald(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mvald.m: exact MVA on a load-dependent model, through pfqn_mvaldmx.
MvaSolution< T > solver_mva_lcfsqn(const qn::NetworkStruct< T > &L, std::size_t lcfs_ist, std::size_t lcfspr_ist)
Port of solver_mva_lcfsqn.m: the closed two-station LCFS + LCFS-PR network.
MvaSolution< T > solver_debemva(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_debemva.m.
MvaSolution< T > solver_amva(const qn::NetworkStruct< T > &L, const ChainDemands< T > &d, MvaOptions opt, const Matrix< T > &init_sol, bool &converged)
bool mva_carries_interlock(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
True when the MVA path this model already dispatches to carries a class-level interlock matrix (Frank...
std::pair< std::string, std::string > oqnrc_scope_reason(const qn::NetworkStruct< T > &L)
{reason, kind} of oqnrc_scope, two empty strings when 'oqnrc' can solve L.
MvaSolution< T > solver_mva_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt, const Matrix< T > &init_sol)
Port of solver_mva_analyzer.m, default and the explicit method names.
ChainDemands< T > sn_get_demands_chain(const qn::NetworkStruct< T > &L)
Port of sn_get_demands_chain.
SqdResult< T > npfqn_sqd(const std::vector< T > &ST, const std::vector< T > &V, const std::vector< T > &cap, const std::vector< bool > &isDelay, const Matrix< T > &rt, const std::vector< std::size_t > &stationToStateful, std::size_t nclasses, int N, const SqdOptions< T > &opt)
Smith Queue Decomposition (SQD): approximate MVA for closed networks under Blocking-After-Service (ma...
SqniResult< T > pfqn_sqni(const std::vector< T > &N, const std::vector< T > &L, const std::vector< T > &Z)
Square-root non-iterative (SQNI) approximation for a single queueing station with per-class delay.
SchmidtExtResult< T > pfqn_schmidt_ext(const Matrix< T > &D, const std::vector< int > &N, const Matrix< int > &S, const std::vector< SchedStrategy > &sched)
Extended Schmidt MVA with queue-aware alpha corrections.
LinearizerResult< T > pfqn_scat(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< SchedStrategy > &type, double tol, int maxiter, const Matrix< T > &QN0)
Neuse-Chandy SCAT (Self-Correcting Approximation Technique) approximate MVA.
AmvaResult< T > pfqn_clust(const Matrix< T > &L, const std::vector< T > &N, const std::vector< T > &Z, const std::vector< std::vector< std::size_t > > &subnets, const std::vector< std::vector< std::size_t > > &localclasses, ClustInner inner=ClustInner::Linearizer, double tol=1e-6, std::size_t maxiter=1000)
de Souza e Silva-Lavenberg-Muntz Clustering Approximation (CA).
OqnrcResult pfqn_oqnrc(const std::vector< double > &lam, const Matrix< double > &A, const Matrix< double > &S, const Matrix< double > &SCV, const std::vector< double > &nservers, const std::vector< bool > &isps, const std::vector< int > &pool, const std::vector< int > &Ncap, bool waitq, double tol, int iter_max)
Runs OQNRC.
AmvaResult< T > pfqn_pam(const Matrix< T > &L, const std::vector< T > &N, const std::vector< T > &Z, PamVariant variant=PamVariant::Basic)
Hsieh-Lam Proportional Approximation Methods (PAMB / PAMI / PAMT).
MvaResult< T > pfqn_mvams(const std::vector< T > &lambda, const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< int > &mi, const std::vector< int > &S)
General-purpose exact MVA for mixed networks with multiserver stations.
constexpr int OPEN_CLASS
Marks an open (infinite-population) class in a population vector.
LinearizerMxMethod
Which Linearizer variant solves the closed subnetwork.
MvabloResult< T > pfqn_mvablo(long N, const std::vector< T > &S, const Matrix< T > &P, const std::vector< double > &K, std::vector< bool > isdelay, double tol=1e-4, int iter_max=1000)
Runs MVABLO.
std::vector< T > pfqn_jdfun(const Matrix< T > &nvec, const std::vector< JdScaling< T > > &jdscaling, std::size_t classIdx)
AMVA joint-dependence function for non-product-form scaling.
LinearizerResult< T > pfqn_conwayms(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< int > &nservers, const std::vector< SchedStrategy > &type, double tol, int maxiter, const Matrix< T > &QN0)
Conway's multiserver Linearizer for chain-dependent FCFS queues (Conway 1989, "Fast Approximate Solut...
LinearizerResult< T > pfqn_dmlin(const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< SchedStrategy > &type, double tol, int maxiter, const Matrix< T > &QN0, int npasses=3)
de Souza e Silva-Muntz Improved Linearizer (IL).
AmvaResult< T > pfqn_tay(const Matrix< T > &L, const std::vector< T > &N, const std::vector< T > &Z, double tol=1e-6, std::size_t maxiter=1000, const Matrix< T > &QN0=Matrix< T >())
Tay's arrival-instant approximate MVA.
DebemvaResult< T > pfqn_debemva(long N, const std::vector< T > &S, const Matrix< T > &P, const std::vector< double > &K, std::vector< bool > isdelay, double tol=0.0, long iter_max=100000)
Runs debeMVA.
AmvaResult< T > pfqn_qsa(const Matrix< T > &L, const std::vector< T > &N, const std::vector< T > &Z, const std::vector< AmvaSched > &type, double tol=1e-10, std::size_t maxiter=100, int levels=3)
Queue-Shift Approximation (QSA) for closed product-form networks.
std::vector< T > pfqn_lldfun(const std::vector< T > &n, const Matrix< T > &lldscaling, const std::vector< double > &nservers)
AMVA-QD limited-load-dependence function.
SchmidtResult< T > pfqn_schmidt(const Matrix< T > &D, const std::vector< int > &N, const Matrix< int > &S, const std::vector< SchedStrategy > &sched, const Matrix< T > &v)
Schmidt's MVA for closed networks with general scheduling disciplines and class-dependent multiserver...
AmvaResult< T > pfqn_chow(const Matrix< T > &L, const std::vector< T > &N, const std::vector< T > &Z, const std::vector< AmvaSched > &type, double tol=1e-6, std::size_t maxiter=1000, const Matrix< T > &QN0=Matrix< T >(), ChowVariant variant=ChowVariant::Forward)
JMT-compatible Chow approximate MVA.
MvaResult< T > pfqn_mvaldmx(const std::vector< T > &lambda, const Matrix< T > &D, const std::vector< int > &N, const Matrix< T > &Z, const Matrix< T > &mu)
Exact MVA for mixed open/closed networks with limited load dependence.
constexpr int kOpenClass
Population sentinel marking an open class, standing in for MATLAB's Inf.
LinearizerResult< T > pfqn_linearizermx(const std::vector< T > &lambda, const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< int > &nservers, const std::vector< SchedStrategy > &type, double tol, int maxiter, LinearizerMxMethod method, const Matrix< T > &QN0)
Linearizer for mixed open/closed queueing networks.
AmvaResult< T > pfqn_bs(const Matrix< T > &L, const std::vector< T > &N, const std::vector< T > &Z, const std::vector< AmvaSched > &type, double tol=1e-6, std::size_t maxiter=1000, const Matrix< T > &QN0=Matrix< T >())
Bard-Schweitzer approximate MVA.
AbAmvaResult< T > pfqn_ab_amva(const Matrix< T > &S, const std::vector< int > &N, const Matrix< T > &v, const std::vector< int > &nservers, const std::vector< SchedStrategy > &sched, bool fcfsSchmidt, AbMarginalMethod method)
Akyildiz-Bolch approximate MVA for multi-server BCMP networks.
AmvaResult< T > pfqn_lcp(const Matrix< T > &L, const std::vector< T > &N, const std::vector< T > &Z, const std::vector< AmvaSched > &type, double tol=1e-6, std::size_t maxiter=1000, const Matrix< T > &QN0=Matrix< T >())
Bard Large Customer Population (LCP) approximate MVA.
AmvaResult< T > pfqn_aql(const Matrix< T > &L, const std::vector< T > &N, const std::vector< T > &Z, double tol=1e-7, std::size_t maxiter=1000)
Aggregate Queue Length (AQL) approximate MVA.
PamVariant
Which of the three proportional approximations to run.
std::vector< T > pfqn_cdfun(const Matrix< T > &nvec, const std::vector< CdScaling< T > > &cdscaling, std::size_t classIdx)
AMVA-QD class-dependence function.
MvaResult< T > pfqn_mvams_ilock(const std::vector< T > &lambda, const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const std::vector< int > &mi, const std::vector< int > &S, const Matrix< T > &IL)
MVA entry point for models carrying the interlocked-flow correction.
LcfsMvaResult< T > pfqn_lcfsqn_mva(const std::vector< T > &alpha, const std::vector< T > &beta, const std::vector< int > &N)
Exact mean value analysis of the two-station multiclass LCFS network of Casale, QUESTA 2026 (station ...
@ Ab
the Akyildiz-Bolch weight function
SumClosedResult< T > sum_closed(const Matrix< T > &L, const std::vector< long > &N, const std::vector< T > &Z, const std::vector< Servers > &mi, const Matrix< T > &scv, const SumOptions &options=SumOptions())
Summation method (SUM) and its extension (ESUM) for closed queueing networks, including non-product-f...
SumClosingResult< T > sum_closing(const std::vector< T > &lambda0, const std::vector< T > &scva, const Matrix< T > &L, const std::vector< Servers > &mi, const Matrix< T > &scv, const std::vector< long > &N, const std::vector< T > &Z, const ClosingOptions &options=ClosingOptions())
Closing method for open and mixed non-product-form queueing networks, solved with the summation metho...
bool timeout_exceeded()
The checkpoint: true when the innermost budget has run out, marking it tripped.
Conservation laws of a layered queueing network, enumerated from its structure.
T num_pow_int(const T &base, unsigned e)
Integer power, valid in any field (no transcendental requirement).
std::vector< T > ones(std::size_t n)
Column vector of ones, the ubiquitous e in MAP algebra.
A queueing network and its refreshed NetworkStruct.
Smith Queue Decomposition (SQD): approximate MVA for closed networks under Blocking-After-Service (ma...
Akyildiz-Bolch approximate MVA for multi-server BCMP networks.
Aggregate Queue Length (AQL) approximate MVA.
Bard-Schweitzer approximate MVA.
AMVA-QD class-dependence function.
JMT-compatible Chow approximate MVA.
de Souza e Silva-Lavenberg-Muntz Clustering Approximation (CA).
Conway's multiserver Linearizer for chain-dependent FCFS queues (Conway 1989, "Fast Approximate Solut...
debeMVA: MVA-based approximation of closed networks with finite (BAS) buffers.
de Souza e Silva-Muntz Improved Linearizer (IL).
AMVA joint-dependence function for non-product-form scaling.
Exact mean value analysis of the two-station multiclass LCFS network of Casale, QUESTA 2026 (station ...
Bard Large Customer Population (LCP) approximate MVA.
Linearizer for mixed open/closed queueing networks.
AMVA-QD limited-load-dependence function.
MVABLO: approximate MVA for closed networks with Blocking-After-Service (BAS).
Exact Mean Value Analysis for mixed open/closed networks with multiserver stations.
OQNRC: approximate MVA for open queueing networks with restricted capacity.
Hsieh-Lam Proportional Approximation Methods (PAMB / PAMI / PAMT).
Queue-Shift Approximation (QSA) for closed product-form networks.
Neuse-Chandy SCAT (Self-Correcting Approximation Technique) approximate MVA.
Schmidt's MVA for closed networks with general scheduling disciplines and class-dependent multiserver...
Extended Schmidt MVA with queue-aware alpha corrections.
Square-root non-iterative (SQNI) approximation for a single queueing station with per-class delay.
Tay's arrival-instant approximate MVA.
Chain aggregation and de-aggregation.
Ports of the sn_has_* / sn_is_* predicate family of matlab/src/api/sn.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
The chain-level view of a layer, as sn_get_demands_chain returns it.
std::vector< std::size_t > refstatchain
(C) 1-based reference station
std::vector< double > Nchain
(C) population, infinite for an open chain
Matrix< T > STchain
(M x C) mean service time
Matrix< T > Lchain
(M x C) demand
Matrix< T > Vchain
(M x C) visits
Matrix< T > SCVchain
(M x C)
Class-level results, as sn_deaggregate_chain_results returns them.
The options SolverMVA reads.
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
std::vector< T > QNfcr
Finite capacity region row (1 x K each), filled by solver_oqnrc alone and EMPTY otherwise: jobs in th...
double lG
log of the normalizing constant, the reference's lG.
std::vector< T > DropRateNfcr
std::optional< bool > converged
Whether the fixed point met its tolerance, or empty when the handler reports none.
Scope of a model inside OQNRC: token pool of each class (0-based), tokens per pool,...
std::string kind
empty when the model is in scope
Product-form chain parameters, the split into queueing and delay stations.
Matrix< T > D
(Mq x C) demands at queueing stations
std::vector< T > lambda
(C) chain arrival rates, zero on a closed chain
Matrix< T > Z
(Md x C) demands at delay stations
std::vector< std::size_t > delay_stations
1-based
std::vector< std::size_t > queue_stations
1-based
std::vector< double > S
(Mq) server counts
The four option switches of the reference, with its defaults.
Return value of npfqn_sqd, mirroring [X, Q, U, R].
std::vector< T > R
(M) per-station residence time
std::vector< T > Q
(M) per-station queue length
std::vector< T > U
(M) per-station utilization, capped at one
std::vector< T > X
(M) per-station throughput
Return value of pfqn_ab_amva, mirroring [QN,UN,RN,CN,XN,totiter].
Matrix< T > UN
(M x R) utilization
std::size_t totiter
iterations of the final core pass
std::vector< T > XN
(R) class throughput AT STATION 1
Matrix< T > QN
(M x R) mean queue length
std::vector< T > XN
(R) throughput
Matrix< T > UN
(M x R) utilization
Matrix< T > QN
(M x R) queue length
Return value of pfqn_debemva, mirroring [X,Q,U,R,BT,z,theta,iter,converged]; vectors are (M).
std::vector< T > Q
mean number of jobs, blocked jobs at the source
std::vector< T > U
utilization X.*S, blocked time excluded
std::vector< T > X
throughput of each station
std::vector< T > R
mean residence time per visit, blocking time included
long iter
total number of passes over all populations
bool converged
false if a population exhausted iter_max passes
Matrix< T > Q
(2 x R) mean queue lengths
std::vector< T > T_
(R) per-class throughput
Matrix< T > U
(2 x R) utilizations
Return value of the Linearizer family, mirroring [Q,U,W,C,X,totiter].
Matrix< T > U
(M x R) utilization
std::vector< T > X
(R) per-class throughput
Matrix< T > Q
(M x R) mean queue length
int totiter
total inner iterations across all Core calls
std::vector< T > XN
(R) per-class throughput
Matrix< T > QN
(M x R) mean queue length
double lG
log of the normalizing constant
Matrix< T > UN
(M x R) utilization
Return value of pfqn_mvablo, mirroring [X,Q,U,R,BT,iter,converged]; vectors are (M).
std::vector< T > Q
mean number of jobs, blocked jobs at the source
int iter
total number of passes over all populations
std::vector< T > X
throughput of each station
std::vector< T > U
utilization X.*S, blocked time excluded
bool converged
false if a population exhausted iter_max passes (deadlock)
std::vector< T > R
mean residence time per visit, blocking time included
int iter
multi-pool fixed point iterations
std::vector< double > Ploss
loss probability of each class (DROP)
std::vector< double > X
carried throughput of each class
Matrix< double > R
queue length, throughput, utilization, response time per visit
std::vector< double > Qext
mean class-r arrivals waiting outside (WAITQ)
Return value of pfqn_schmidt_ext, mirroring [XN,QN,UN,CN].
Matrix< T > QN
(M x R) mean queue length
std::vector< T > XN
(R) per-class throughput
Return value of pfqn_schmidt, mirroring [XN,QN,UN,CN].
std::vector< T > XN
(R) per-class throughput
Matrix< T > QN
(M x R) mean queue length
Return value of pfqn_sqni, mirroring [Q, U, X] for the single station.
One station of the network.
CdScaling< T > jdscaling
sn.jdscaling for this station: MATLAB's Station.ljdScaling, the JOINT dependence map eta_i(n),...
std::vector< T > lldscaling
sn.lldscaling for this station: the multiplier at population 1, 2, ... Empty when the station is not ...
CdScaling< T > cdscaling
sn.cdscaling for this station: the class-dependence map, empty when unset.
Closing controls; Kclosed is the population given to the open classes.
static Servers of(long m)
Mirrors the [XN, QN, UN, RN, it] return list of the MATLAB function.
Matrix< T > QN
(M x R) mean queue lengths
Matrix< T > UN
(M x R) utilizations, per server at queueing stations
std::size_t it
iterations of the outer loop
std::vector< T > XN
(R) class throughputs
Mirrors the [XN, QN, UN, RN, TN, it] return list of the MATLAB function.
std::vector< T > XN
(R) class throughputs
Matrix< T > QN
(M x R) queue lengths at the original stations
Matrix< T > UN
(M x R) utilizations at the original stations
Convergence controls, mirroring the trailing (tol, maxiter) arguments.
Summation method (SUM) and its extension (ESUM) for closed queueing networks, including non-product-f...
Closing method for open and mixed non-product-form queueing networks, solved with the summation metho...