LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
qsys_mm1_transient.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_API_QSYS_QSYS_MM1_TRANSIENT_H
6#define LINE_API_QSYS_QSYS_MM1_TRANSIENT_H
7
8/**
9 * @file
10 * @ingroup api_qsys
11 * Transient queue-length distribution of the M/M/1 queue.
12 *
13 * Port of matlab/src/api/qsys/qsys_mm1_transient.m together with its private
14 * helpers matlab/src/api/qsys/private/qsys_transient_poiswin.m and
15 * qsys_transient_lpois.m (native Python twin:
16 * python/line_solver/api/qsys/transient.py). The M/M/1 queue started with N0
17 * jobs: P(r, j) = P(N(t_r) = j | N(0) = N0), j = 0..nmax, the mean
18 * EN(r) = E[N(t_r)] over ALL states and P0(r) = P(N(t_r) = 0), for any load.
19 *
20 * Methods:
21 * 'uniformization' Jensen's uniformization at rate lambda+mu with the closed
22 * form of the n-step probabilities of the uniformized chain (Rubino 2020,
23 * eqs. (4.1)-(4.6)), every term a product of two Poisson pmfs summed in
24 * the log domain with Loader's saddle-point pmf, over a Poisson window
25 * whose left-out mass is bounded rigorously, so every probability has
26 * absolute truncation error <= errBound (<= tol) and the mean
27 * <= errBoundMean (Rubino 2020 Secs. 2.2 and 4.1).
28 * 'bessel' the modified-Bessel form (Rubino 2020 eq. (3.3), the exponent of
29 * I_{j+1} corrected to (j-1)/2, for any N0), with exponentially scaled
30 * Bessel functions. errBound is the Chernoff bound on P(N(t) > J) plus
31 * the computed mass defect.
32 * 'auto' 'uniformization' when (lambda+mu) t <= 1000, else 'bessel', per time.
33 *
34 * THE SCALED BESSEL FUNCTIONS. MATLAB reads besseli(k, z, 1) where it does not
35 * underflow and continues it past that point with the ratios
36 * r_k = I_{k+1}(z)/I_k(z) of the stable backward recurrence
37 * r_{k-1} = 1/(2k/z + r_k). C++ has no exponentially scaled modified Bessel
38 * function, so the port takes the ratios for every k, from the same recurrence
39 * and the same starting value, and fixes the level by Neumann's identity
40 * e^{-z} (I_0(z) + 2 sum_{k>=1} I_k(z)) = 1, a sum of positive terms (Miller's
41 * normalization). That is the same function evaluated by a different
42 * algorithm; it agrees with besseli to rounding and never overflows.
43 *
44 * ARITHMETIC: double only (log-gamma, log1p, expm1 and the Bessel ratios).
45 *
46 * References: G. Rubino, "Transient analysis of Markovian queueing systems: a
47 * survey with focus on closed-forms and uniformization", Advanced Trends in
48 * Queueing Theory 2, ISTE/Wiley, 2020; C. Loader, "Fast and accurate
49 * computation of binomial probabilities", 2000.
50 */
51
52#include <algorithm>
53#include <cctype>
54#include <cmath>
55#include <cstddef>
56#include <limits>
57#include <string>
58#include <vector>
59
60#include "line/util/error.h"
61#include "line/util/matrix.h"
62
63namespace line {
64namespace qsys {
65
66namespace detail {
67
68constexpr double kTransientEps = 2.220446049250313e-16; // MATLAB eps
69constexpr double kTransientPi = 3.14159265358979323846;
70
71/** log(n!) - log(sqrt(2 pi n) (n/e)^n) for an integer n >= 1. */
72inline double transient_stirlerr(double n) {
73 if (n <= 15.0) return std::lgamma(n + 1.0) - (n + 0.5) * std::log(n) + n - 0.5 * std::log(2.0 * kTransientPi);
74 const double nn = n * n;
75 const double S0 = 1.0 / 12, S1 = 1.0 / 360, S2 = 1.0 / 1260, S3 = 1.0 / 1680, S4 = 1.0 / 1188;
76 return (S0 - (S1 - (S2 - (S3 - S4 / nn) / nn) / nn) / nn) / n;
77}
78
79/** Deviance k log(k/x) + x - k without cancellation. */
80inline double transient_bd0(double k, double x) {
81 if (std::fabs(k - x) < 0.1 * (k + x)) {
82 double v = (k - x) / (k + x);
83 double s = (k - x) * v;
84 double ej = 2.0 * k * v;
85 const double v2 = v * v;
86 for (int jj = 1; jj <= 13; ++jj) {
87 ej *= v2;
88 s += ej / (2 * jj + 1);
89 }
90 return s;
91 }
92 return k * std::log(k / x) + x - k;
93}
94
95/**
96 * Logarithm of the Poisson(x) pmf at the nonnegative integer k, by Loader's
97 * saddle-point form (qsys_transient_lpois.m).
98 */
99inline double transient_lpois(double k, double x) {
100 if (k <= 0.0) return -x;
101 return -transient_stirlerr(k) - transient_bd0(k, x) - 0.5 * std::log(2.0 * kTransientPi * k);
102}
103
104/** Chernoff bound on P(X >= m) for m > x, or on P(X <= m) for m < x (poiswin_chernoff). */
105inline double transient_poiswin_chernoff(double x, double m) {
106 const double u = (m - x) / x;
107 if (u <= -1.0) return std::exp(-x);
108 return std::exp(-x * ((1.0 + u) * std::log1p(u) - u));
109}
110
111/** Poisson window of qsys_transient_poiswin.m. */
112struct PoissonWindow {
113 long nL = 0, nR = 0;
114 std::vector<double> w; ///< P(Poisson(x) = nL..nR)
115 double bound = 0.0, left = 0.0, right = 0.0;
116};
117
118inline PoissonWindow transient_poiswin(double x, double tol) {
119 PoissonWindow pw;
120 if (x == 0.0) {
121 pw.w.assign(1, 1.0);
122 return pw;
123 }
124 const double a = 12.0 * std::sqrt(x) + 40.0;
125 const long lo = static_cast<long>(std::max(0.0, std::floor(x - a)));
126 const long hi = static_cast<long>(std::ceil(x + a));
127 const std::size_t nw = static_cast<std::size_t>(hi - lo + 1);
128 std::vector<double> w(nw);
129 for (std::size_t k = 0; k < nw; ++k) {
130 const double n = static_cast<double>(lo + static_cast<long>(k));
131 w[k] = std::exp(-x + n * std::log(x) - std::lgamma(n + 1.0));
132 }
133 double left = lo > 0 ? transient_poiswin_chernoff(x, static_cast<double>(lo - 1)) : 0.0;
134 double right = transient_poiswin_chernoff(x, static_cast<double>(hi + 1));
135 std::vector<double> cl(nw), cr(nw);
136 double acc = 0.0;
137 for (std::size_t k = 0; k < nw; ++k) cl[k] = (acc += w[k]);
138 acc = 0.0;
139 for (std::size_t k = 0; k < nw; ++k) cr[k] = (acc += w[nw - 1 - k]);
140 std::size_t kL = 0, kR = 0;
141 for (std::size_t k = 0; k < nw; ++k)
142 if (cl[k] <= tol / 4) ++kL;
143 for (std::size_t k = 0; k < nw; ++k)
144 if (cr[k] <= tol / 4) ++kR;
145 kL = std::min(kL, nw - 1);
146 kR = std::min(kR, nw - 1 - kL);
147 if (kL > 0) left += cl[kL - 1];
148 if (kR > 0) right += cr[kR - 1];
149 pw.w.assign(w.begin() + static_cast<std::ptrdiff_t>(kL), w.end() - static_cast<std::ptrdiff_t>(kR));
150 pw.nL = lo + static_cast<long>(kL);
151 pw.nR = hi - static_cast<long>(kR);
152 pw.left = left;
153 pw.right = right;
154 pw.bound = left + right;
155 return pw;
156}
157
158/** Running log-sum-exp, s[k] = log sum_{m<=k} exp(a[m]). */
159inline std::vector<double> transient_logcumsumexp(const std::vector<double>& a) {
160 std::vector<double> s = a;
161 for (std::size_t k = 1; k < a.size(); ++k) {
162 const double hi = std::max(s[k - 1], a[k]);
163 if (hi == -std::numeric_limits<double>::infinity())
164 s[k] = hi;
165 else
166 s[k] = hi + std::log1p(std::exp(-std::fabs(s[k - 1] - a[k])));
167 }
168 return s;
169}
170
171/** Chernoff upper-tail bound exp(-x h((m-x)/x)) (mm1t_chernoff_upper). */
172inline double transient_chernoff_upper(double x, double m) {
173 const double u = (m - x) / x;
174 return std::exp(-x * ((1.0 + u) * std::log1p(u) - u));
175}
176
177/**
178 * log(exp(-z) I_k(z)), k = 0..kmax: ratios r_k = I_{k+1}/I_k from the backward
179 * recurrence r_{k-1} = 1/(2k/z + r_k), started as mm1t_log_ive starts it, and
180 * the level from e^{-z}(I_0 + 2 sum_{k>=1} I_k) = 1 (see the file header).
181 */
182inline std::vector<double> transient_log_ive(std::size_t kmax, double z) {
183 const double ksd = std::max(static_cast<double>(kmax), std::ceil(z + 40.0 * std::sqrt(z))) + 60.0;
184 const std::size_t ks = static_cast<std::size_t>(ksd);
185 std::vector<double> rr(ks + 1); // rr[k] = r_k
186 const double k1 = static_cast<double>(ks + 1);
187 rr[ks] = z / (k1 + std::sqrt(k1 * k1 + z * z));
188 for (std::size_t kk = ks; kk >= 1; --kk) rr[kk - 1] = 1.0 / (2.0 * static_cast<double>(kk) / z + rr[kk]);
189 // cumulative log ratios c[k] = log(I_k/I_0), and the Neumann sum. The
190 // running sum reaches magnitudes of k^2/(2z), so it is compensated (Kahan):
191 // a plain sum loses ~1e-12 relative on the bulk of a z ~ 4000 window, which
192 // shows in the mean at the 1e-9 level.
193 std::vector<double> c(ks + 1, 0.0);
194 double acc = 0.0, comp = 0.0;
195 for (std::size_t k = 1; k <= ks; ++k) {
196 const double y = std::log(rr[k - 1]) - comp;
197 const double tt = acc + y;
198 comp = (tt - acc) - y;
199 acc = tt;
200 c[k] = acc;
201 }
202 double s = 0.0;
203 for (std::size_t k = ks; k >= 1; --k) s += std::exp(c[k]); // smallest first
204 const double l0 = -std::log1p(2.0 * s);
205 std::vector<double> out(kmax + 1);
206 for (std::size_t k = 0; k <= kmax; ++k) out[k] = l0 + c[k];
207 return out;
208}
209
210/** Per-time result of one method: the full row, its bounds and its window. */
211struct Mm1TransientRow {
212 std::vector<double> full;
213 double bound = 0.0, errmean = 0.0;
214 double nL = std::numeric_limits<double>::quiet_NaN(), nR = std::numeric_limits<double>::quiet_NaN();
215};
216
217/** Poisson-weighted n-step row w_n (U^n)(i, 0..i+n) of the uniformized chain (mm1t_row). */
218inline std::vector<double> mm1t_row(long n, long i, double a, double b, double logrho) {
219 std::vector<double> row(static_cast<std::size_t>(i + n + 1), 0.0);
220 const long vmax = std::min(n, (n + i) / 2);
221 const std::size_t nvv = static_cast<std::size_t>(vmax + 1);
222 std::vector<double> keep(nvv, 1.0);
223 // index q <-> v = vmax - q (decreasing number of down steps)
224 if (vmax >= i + 1) {
225 double logr0 = 0.0;
226 for (long l = 0; l <= i; ++l)
227 logr0 += std::log1p(static_cast<double>(2 * vmax - n - 1 - 2 * l) /
228 static_cast<double>(n - vmax + 1 + l));
229 const long nv = vmax - i; // entries v = vmax..i+1
230 double logr = logr0;
231 keep[0] = -std::expm1(std::min(logr, 0.0));
232 for (long q = 1; q < nv; ++q) {
233 const double vv = static_cast<double>(vmax - (q - 1));
234 logr += std::log1p(-static_cast<double>(i + 1) / vv) +
235 std::log1p(-static_cast<double>(i + 1) / (static_cast<double>(n) - vv + static_cast<double>(i) + 2.0));
236 keep[static_cast<std::size_t>(q)] = -std::expm1(std::min(logr, 0.0));
237 }
238 }
239 for (std::size_t q = 0; q < nvv; ++q) {
240 const long v = vmax - static_cast<long>(q);
241 const long u = n - v;
242 const long j = i + n - 2 * v;
243 const double kval = std::exp(transient_lpois(static_cast<double>(u), a) +
244 transient_lpois(static_cast<double>(v), b)) * keep[q];
245 row[static_cast<std::size_t>(j)] += kval;
246 }
247 if (n >= i + 1) {
248 const long kmax = (n - i - 1) / 2;
249 std::vector<double> logphi(static_cast<std::size_t>(kmax + 1));
250 for (long k = 0; k <= kmax; ++k)
251 logphi[static_cast<std::size_t>(k)] = std::log(static_cast<double>(n + 1 - 2 * k)) +
252 transient_lpois(static_cast<double>(k), a) +
253 transient_lpois(static_cast<double>(n + 1 - k), b) - std::log(b);
254 const std::vector<double> logS = transient_logcumsumexp(logphi);
255 for (long jj = 0; jj <= n - i - 1; ++jj) {
256 const long kk = (n - i - 1 - jj) / 2;
257 row[static_cast<std::size_t>(jj)] +=
258 std::exp(static_cast<double>(jj) * logrho + logS[static_cast<std::size_t>(kk)]);
259 }
260 }
261 return row;
262}
263
264inline Mm1TransientRow mm1t_uniformization(double lam, double mu, long i, double t, double tol) {
265 const double x = (lam + mu) * t;
266 const PoissonWindow pw = transient_poiswin(x, tol);
267 Mm1TransientRow out;
268 out.full.assign(static_cast<std::size_t>(i + pw.nR + 1), 0.0);
269 const double a = lam * t, b = mu * t, logrho = std::log(lam / mu);
270 for (long n = pw.nL; n <= pw.nR; ++n) {
271 const std::vector<double> row = mm1t_row(n, i, a, b, logrho);
272 for (std::size_t k = 0; k < row.size(); ++k) out.full[k] += row[k];
273 }
274 out.bound = pw.bound;
275 out.errmean = static_cast<double>(i + pw.nL) * pw.left + static_cast<double>(i) * pw.right +
276 x * (pw.w.back() + pw.right);
277 out.nL = static_cast<double>(pw.nL);
278 out.nR = static_cast<double>(pw.nR);
279 return out;
280}
281
282inline Mm1TransientRow mm1t_bessel(double lam, double mu, long i, double t) {
283 const double rho = lam / mu, logrho = std::log(rho);
284 const double z = 2.0 * t * std::sqrt(lam * mu);
285 const double delta = (std::sqrt(mu) - std::sqrt(lam)) * (std::sqrt(mu) - std::sqrt(lam));
286 // N(t) <= N(0) + A(t), A(t) ~ Poisson(lam t): truncate the states at J
287 const long J = i + static_cast<long>(std::ceil(lam * t + 12.0 * std::sqrt(lam * t) + 40.0));
288 double bound = transient_chernoff_upper(lam * t, static_cast<double>(J - i + 1));
289 std::size_t kmax = static_cast<std::size_t>(J + i + 2) +
290 static_cast<std::size_t>(std::ceil(12.0 * std::sqrt(z) + 40.0));
291 std::vector<double> logI, logterm;
292 while (true) {
293 logI = transient_log_ive(kmax, z);
294 logterm.assign(kmax + 1, 0.0);
295 double mx = -std::numeric_limits<double>::infinity();
296 for (std::size_t k = 0; k <= kmax; ++k) {
297 logterm[k] = -0.5 * static_cast<double>(k) * logrho + logI[k] - delta * t;
298 mx = std::max(mx, logterm[k]);
299 }
300 const bool tailok = logterm[kmax] < mx + std::log(kTransientEps) - 60.0 && logterm[kmax] <= logterm[kmax - 1];
301 if (tailok || !std::isfinite(logterm[kmax])) break;
302 kmax *= 2;
303 }
304 // logT[m] = log sum_{k >= m} exp(logterm[k])
305 std::vector<double> rev(logterm.rbegin(), logterm.rend());
306 const std::vector<double> cs = transient_logcumsumexp(rev);
307 std::vector<double> logT(cs.rbegin(), cs.rend());
308 Mm1TransientRow out;
309 out.full.assign(static_cast<std::size_t>(J + 1), 0.0);
310 double sum = 0.0;
311 for (long j = 0; j <= J; ++j) {
312 const long d = j > i ? j - i : i - j;
313 const double t1 = std::exp(0.5 * static_cast<double>(j - i) * logrho + logI[static_cast<std::size_t>(d)] - delta * t);
314 const double t2 = std::exp(0.5 * static_cast<double>(j - i - 1) * logrho +
315 logI[static_cast<std::size_t>(j + i + 1)] - delta * t);
316 const double t3 = (1.0 - rho) * std::exp(static_cast<double>(j) * logrho + logT[static_cast<std::size_t>(j + i + 2)]);
317 out.full[static_cast<std::size_t>(j)] = std::max(t1 + t2 + t3, 0.0);
318 sum += out.full[static_cast<std::size_t>(j)];
319 }
320 const double defect = std::fabs(1.0 - sum);
321 out.errmean = static_cast<double>(J) * defect + lam * t * bound;
322 out.bound = std::max(bound, defect);
323 return out;
324}
325
326inline void transient_arg_error(const char* fn, const std::string& msg) {
327 throw InputError(ErrorKind{"Argument"}, std::string(fn) + ": " + msg);
328}
329
330inline bool transient_is_int(double v) { return std::isfinite(v) && v == std::round(v); }
331
332} // namespace detail
333
334/** Return value of qsys_mm1_transient: [P, EN, P0, res]. */
336 Matrix<double> P; ///< (nt x nmax+1) probabilities
337 std::vector<double> EN; ///< (nt) mean over all states
338 std::vector<double> P0; ///< (nt) empty probability
339 double rho = 0.0;
340 long nmax = 0;
341 double tol = 0.0;
342 std::vector<std::string> method; ///< per time: 'uniformization', 'bessel' or 'exact'
343 std::vector<double> errBound, errBoundMean, tailMass;
344 Matrix<double> window; ///< (nt x 2) [nL nR], NaN for 'bessel'
345};
346
347/**
348 * @brief Transient distribution of the M/M/1 queue (Rubino 2020).
349 *
350 * @param lambda arrival rate, finite and positive
351 * @param mu service rate, finite and positive
352 * @param n0 initial number in system, integer >= 0
353 * @param t times, finite and >= 0 (t = 0 returns the initial condition)
354 * @param nmax last state reported; NaN for the smallest index beyond which the
355 * mass is <= tol at every requested time
356 * @param tol truncation tolerance in (0, 1)
357 * @param method 'auto', 'uniformization' or 'bessel'
358 */
359inline Mm1TransientResult qsys_mm1_transient(double lambda, double mu, double n0, const std::vector<double>& t,
360 double nmax = std::numeric_limits<double>::quiet_NaN(),
361 double tol = 1e-14, const std::string& method_in = "auto") {
362 using namespace detail;
363 const char* fn = "qsys_mm1_transient";
364 if (!std::isfinite(lambda) || lambda <= 0) transient_arg_error(fn, "lambda must be finite and positive");
365 if (!std::isfinite(mu) || mu <= 0) transient_arg_error(fn, "mu must be finite and positive");
366 if (!transient_is_int(n0) || n0 < 0) transient_arg_error(fn, "n0 must be an integer >= 0");
367 if (t.empty()) transient_arg_error(fn, "t must be a nonempty vector of finite nonnegative times");
368 for (double tv : t)
369 if (!std::isfinite(tv) || tv < 0)
370 transient_arg_error(fn, "t must be a nonempty vector of finite nonnegative times");
371 if (!std::isfinite(tol) || tol <= 0 || tol >= 1) transient_arg_error(fn, "tol must lie in (0, 1)");
372 std::string method = method_in;
373 std::transform(method.begin(), method.end(), method.begin(),
374 [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
375 if (method != "auto" && method != "uniformization" && method != "bessel")
376 transient_arg_error(fn, "method must be 'auto', 'uniformization' or 'bessel'");
377 const long i = static_cast<long>(n0);
378 const std::size_t nt = t.size();
379
381 res.rho = lambda / mu;
382 res.tol = tol;
383 res.method.assign(nt, "");
384 res.errBound.assign(nt, 0.0);
385 res.errBoundMean.assign(nt, 0.0);
386 res.window = Matrix<double>(nt, 2, std::numeric_limits<double>::quiet_NaN());
387 std::vector<std::vector<double> > fulls(nt);
388 for (std::size_t r = 0; r < nt; ++r) {
389 if (t[r] == 0.0) {
390 fulls[r].assign(static_cast<std::size_t>(i + 1), 0.0);
391 fulls[r][static_cast<std::size_t>(i)] = 1.0;
392 res.method[r] = "exact";
393 res.window(r, 0) = 0.0;
394 res.window(r, 1) = 0.0;
395 continue;
396 }
397 const double x = (lambda + mu) * t[r];
398 std::string m = method;
399 if (m == "auto") m = x <= 1000.0 ? "uniformization" : "bessel";
400 const Mm1TransientRow row = m == "uniformization" ? mm1t_uniformization(lambda, mu, i, t[r], tol)
401 : mm1t_bessel(lambda, mu, i, t[r]);
402 fulls[r] = row.full;
403 res.errBound[r] = row.bound;
404 res.errBoundMean[r] = row.errmean;
405 res.window(r, 0) = row.nL;
406 res.window(r, 1) = row.nR;
407 res.method[r] = m;
408 }
409 // assemble, compute the mean over all states, then cut at nmax
410 std::size_t width = 0;
411 for (const auto& f : fulls) width = std::max(width, f.size());
412 const std::size_t Jall = width - 1;
413 Matrix<double> F(nt, Jall + 1, 0.0);
414 for (std::size_t r = 0; r < nt; ++r)
415 for (std::size_t j = 0; j < fulls[r].size(); ++j) F(r, j) = fulls[r][j];
416 res.EN.assign(nt, 0.0);
417 for (std::size_t r = 0; r < nt; ++r)
418 for (std::size_t j = 0; j <= Jall; ++j) res.EN[r] += F(r, j) * static_cast<double>(j);
419 Matrix<double> tails(nt, Jall + 1, 0.0); // tails(r, m) = sum_{j >= m}
420 for (std::size_t r = 0; r < nt; ++r) {
421 double acc = 0.0;
422 for (std::size_t j = Jall + 1; j-- > 0;) tails(r, j) = (acc += F(r, j));
423 }
424 std::size_t nm = 0;
425 if (std::isnan(nmax)) {
426 bool found = false;
427 for (std::size_t j = Jall + 1; j-- > 0 && !found;) {
428 double mx = 0.0;
429 for (std::size_t r = 0; r < nt; ++r) mx = std::max(mx, tails(r, j));
430 if (mx > tol) {
431 nm = j;
432 found = true;
433 }
434 }
435 if (!found) nm = 0;
436 } else {
437 if (!transient_is_int(nmax) || nmax < 0) transient_arg_error(fn, "nmax must be an integer >= 0");
438 nm = static_cast<std::size_t>(nmax);
439 }
440 res.tailMass.assign(nt, 0.0);
441 res.P = Matrix<double>(nt, nm + 1, 0.0);
442 for (std::size_t r = 0; r < nt; ++r)
443 for (std::size_t j = 0; j <= std::min(nm, Jall); ++j) res.P(r, j) = F(r, j);
444 if (nm + 1 <= Jall)
445 for (std::size_t r = 0; r < nt; ++r) res.tailMass[r] = tails(r, nm + 1);
446 res.P0.assign(nt, 0.0);
447 for (std::size_t r = 0; r < nt; ++r) res.P0[r] = res.P(r, 0);
448 res.nmax = static_cast<long>(nm);
449 return res;
450}
451
452} // namespace qsys
453} // namespace line
454
455#endif // LINE_API_QSYS_QSYS_MM1_TRANSIENT_H
InputError(const std::string &what)
Definition error.h:105
The exception types the port throws.
Dense matrix and non-owning view.
double z(double v)
Definition lqn_focus.h:261
double delta(double t)
Mm1TransientResult qsys_mm1_transient(double lambda, double mu, double n0, const std::vector< double > &t, double nmax=std::numeric_limits< double >::quiet_NaN(), double tol=1e-14, const std::string &method_in="auto")
Transient distribution of the M/M/1 queue (Rubino 2020).
double sum(const Vec &a)
Definition spn_ispn.h:191
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Return value of qsys_mm1_transient: [P, EN, P0, res].
std::vector< double > P0
(nt) empty probability
Matrix< double > window
(nt x 2) [nL nR], NaN for 'bessel'
std::vector< double > EN
(nt) mean over all states
std::vector< std::string > method
per time: 'uniformization', 'bessel' or 'exact'
Matrix< double > P
(nt x nmax+1) probabilities