LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
ldqbd_censor.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_MAM_LDQBD_CENSOR_H
6#define LINE_API_MAM_LDQBD_CENSOR_H
7
8/**
9 * @file
10 * @ingroup api_mam
11 * Stationary distribution of a chain of connected LDQBDs by successive
12 * censoring.
13 *
14 * Templated port of matlab/src/api/mam/ldqbd_censor.m, implementing the
15 * algorithm of N. Baer, A. Al Hanbali, R. J. Boucherie, J. C. W. van Ommeren,
16 * "A successive censoring algorithm for a system of connected
17 * LDQBD-processes", Annals of Operations Research 310:389-410, 2022.
18 *
19 * The state space is split into S sets, each a level-dependent QBD on its
20 * own; set s has levels 1..L_s and level l of set s has phases[s][l] phases.
21 * States are ordered by (set, level, phase). Transitions between sets are
22 * arbitrary. Sets 1..S-1 are censored out in turn,
23 *
24 * Q^{k+1}_{ij} = Q^k_{ij} + Q^k_{ik} (-Q^k_{kk})^{-1} Q^k_{kj}, i, j > k,
25 *
26 * the last LDQBD is solved by level reduction (Gaver), and the vector is
27 * expanded back with pi_k = (sum_{i>k} pi_i Q^k_{ik}) (-Q^k_{kk})^{-1}. Each
28 * transient LDQBD is factored once by block-tridiagonal LU (block Thomas,
29 * S_l = D_l - W_l S_{l-1}^{-1} U_{l-1}), each S_l by LU with partial pivoting;
30 * no inverse is ever formed. An explicit inverse is not accurate enough here: a
31 * chain with vanishing states (a Router's immediate transitions at rate
32 * GlobalConstants::Immediate) has blocks whose condition reaches 1e8, and
33 * multiplying by their inverses moved a 41-state M/M/1 behind a Router by
34 * 2.3e-7 in its mean queue length, where the LU solve is exact to round-off.
35 *
36 * STRUCTURE. The method applies exactly when every censored diagonal block
37 * Q^k_{kk} is block tridiagonal by level. The update is a sum of nonnegative
38 * terms, so the numerical pattern equals the structural one and the check is
39 * made directly on Q^k_{kk}; a failure raises LINE:unsupported:Structure
40 * (another order of the sets may succeed, Remark 2 of the paper).
41 *
42 * ARITHMETIC. The algorithm is finite (no tolerance, no iteration), so it
43 * instantiates at Rational and returns the exact stationary law. Exact T
44 * raises NumericError on an exactly singular Schur complement; inexact T also
45 * raises when the 1-norm reciprocal condition of a block is below machine
46 * epsilon, matching the MATLAB rcond test (the inverse norm is Hager's
47 * estimate from the LU factors, as rcond's is). The row-sum check is exact at
48 * Rational and relative (tol) otherwise.
49 */
50
51#include <algorithm>
52#include <cmath>
53#include <cstddef>
54#include <map>
55#include <string>
56#include <utility>
57#include <vector>
58
59#include "line/num/number.h"
60#include "line/util/error.h"
61#include "line/util/linalg.h"
62#include "line/util/lu.h"
63#include "line/util/matrix.h"
64
65namespace line {
66namespace mam {
67
68/** Stationary distribution of a chain of connected LDQBDs. */
69template <class T>
71 std::vector<T> pi; ///< in the ordering of Q
72 std::vector<std::vector<std::vector<T>>> pi_cells; ///< pi_cells[s][l], level l of set s
73};
74
76
77template <class T>
78T zero() { return num_traits<T>::from_int(0); }
79
80template <class T>
81double norm1(const Matrix<T>& A) {
82 double best = 0.0;
83 for (std::size_t j = 0; j < A.cols(); ++j) {
84 double s = 0.0;
85 for (std::size_t i = 0; i < A.rows(); ++i) s += num_traits<T>::to_double(num_abs(T(A(i, j))));
86 if (s > best) best = s;
87 }
88 return best;
89}
90
91/** x with x A = y (A' x' = y'), from the factors of lu_factor. */
92template <class T>
93std::vector<T> lu_solve_trans(const Matrix<T>& LU, const std::vector<std::size_t>& piv, std::vector<T> x) {
94 const std::size_t n = LU.rows();
95 // P A = L U, so A' = U' L' P: solve U' z = y, then L' w = z, then x = P' w
96 for (std::size_t i = 0; i < n; ++i) {
97 T s = x[i];
98 for (std::size_t k = 0; k < i; ++k) s -= LU(k, i) * x[k];
99 x[i] = s / LU(i, i);
100 }
101 for (std::size_t i = n; i-- > 0;) {
102 T s = x[i];
103 for (std::size_t k = i + 1; k < n; ++k) s -= LU(k, i) * x[k];
104 x[i] = s;
105 }
106 for (std::size_t k = n; k-- > 0;)
107 if (piv[k] != k) std::swap(x[k], x[piv[k]]);
108 return x;
109}
110
111/**
112 * 1-norm of A^{-1} from the LU factors of A, by Hager's estimator (the one
113 * behind LAPACK's condition estimate and MATLAB's rcond), so the singularity
114 * test does not need the inverse it exists to avoid.
115 */
116template <class T>
117double inv_norm1(const Matrix<T>& LU, const std::vector<std::size_t>& piv) {
118 const std::size_t n = LU.rows();
119 if (n == 0) return 0.0;
120 std::vector<T> x(n, num_traits<T>::from_double(1.0 / static_cast<double>(n)));
121 double est = 0.0;
122 std::size_t last = n;
123 for (int it = 0; it < 5; ++it) {
124 std::vector<T> y = x;
125 lu_solve(LU, piv, y);
126 double ny = 0.0;
127 for (const T& v : y) ny += num_traits<T>::to_double(num_abs(v));
128 if (it > 0 && ny <= est) break;
129 est = ny;
130 std::vector<T> xi(n);
131 for (std::size_t i = 0; i < n; ++i)
132 xi[i] = num_traits<T>::from_int(num_traits<T>::to_double(y[i]) >= 0.0 ? 1 : -1);
133 const std::vector<T> z = lu_solve_trans(LU, piv, xi);
134 std::size_t j = 0;
135 double zx = 0.0;
136 for (std::size_t i = 0; i < n; ++i) {
137 if (std::abs(num_traits<T>::to_double(z[i])) > std::abs(num_traits<T>::to_double(z[j]))) j = i;
139 }
140 if (std::abs(num_traits<T>::to_double(z[j])) <= zx || j == last) break;
141 std::fill(x.begin(), x.end(), zero<T>());
142 x[j] = num_traits<T>::from_int(1);
143 last = j;
144 }
145 return est;
146}
147
148/** LU with partial pivoting of a Schur complement (in place), refusing a singular one. */
149template <class T>
150std::vector<std::size_t> checked_lu(Matrix<T>& F, std::size_t level, std::size_t set) {
151 const std::string msg = "ldqbd_censor: the Schur complement of level " + std::to_string(level + 1) +
152 " of set " + std::to_string(set + 1) + " is singular; the chain may be reducible.";
153 const double nD = num_traits<T>::is_exact ? 0.0 : norm1(F);
154 std::vector<std::size_t> piv;
155 try {
156 piv = lu_factor(F);
157 } catch (const NumericError&) {
158 throw NumericError(ErrorKind{"Singular"}, msg);
159 }
161 const double rc = 1.0 / (nD * inv_norm1(F, piv));
162 if (!(rc >= 2.220446049250313e-16)) throw NumericError(ErrorKind{"Singular"}, msg);
163 }
164 return piv;
165}
166
167template <class T>
168Matrix<T> block(const Matrix<T>& M, std::size_t r0, std::size_t nr, std::size_t c0, std::size_t nc) {
169 Matrix<T> B(nr, nc, zero<T>());
170 for (std::size_t i = 0; i < nr; ++i)
171 for (std::size_t j = 0; j < nc; ++j) B(i, j) = M(r0 + i, c0 + j);
172 return B;
173}
174
175/**
176 * Block-tridiagonal LU of M = -Q_kk: S on the diagonal, G below, U above.
177 * Each S_l is held as its LU with partial pivoting (lu, piv); products with
178 * S_l^{-1} are triangular solves, never an explicit inverse.
179 */
180template <class T>
181struct Factor {
182 std::vector<std::size_t> P, off;
183 std::vector<Matrix<T>> S, lu, G, U;
184 std::vector<std::vector<std::size_t>> piv;
185
186 Factor(const Matrix<T>& M, const std::vector<std::size_t>& P_, std::size_t set, bool last_singular)
187 : P(P_), off(P_.size() + 1, 0) {
188 const std::size_t L = P.size();
189 for (std::size_t l = 0; l < L; ++l) off[l + 1] = off[l] + P[l];
190 S.resize(L);
191 lu.resize(L);
192 piv.resize(L);
193 G.resize(L);
194 U.resize(L);
195 for (std::size_t l = 0; l < L; ++l) {
196 Matrix<T> D = block(M, off[l], P[l], off[l], P[l]);
197 if (l > 0) {
198 const Matrix<T> W = block(M, off[l], P[l], off[l - 1], P[l - 1]);
199 // G_l = W S_{l-1}^{-1}, row by row
200 G[l] = Matrix<T>(P[l], P[l - 1], zero<T>());
201 for (std::size_t i = 0; i < P[l]; ++i) {
202 std::vector<T> wi(P[l - 1]);
203 for (std::size_t j = 0; j < P[l - 1]; ++j) wi[j] = W(i, j);
204 const std::vector<T> g = lu_solve_trans(lu[l - 1], piv[l - 1], wi);
205 for (std::size_t j = 0; j < P[l - 1]; ++j) G[l](i, j) = g[j];
206 }
207 const Matrix<T> GU = matmul(G[l], U[l - 1]);
208 for (std::size_t i = 0; i < D.rows(); ++i)
209 for (std::size_t j = 0; j < D.cols(); ++j) D(i, j) -= GU(i, j);
210 }
211 if (l + 1 < L) U[l] = block(M, off[l], P[l], off[l + 1], P[l + 1]);
212 S[l] = D;
213 if (l + 1 < L || !last_singular) {
214 lu[l] = D;
215 piv[l] = checked_lu(lu[l], l, set);
216 }
217 }
218 }
219
220 /** X = S_l^{-1} Z, column by column. */
221 Matrix<T> left_solve(std::size_t l, const Matrix<T>& Z) const {
222 const std::size_t m = Z.cols();
223 Matrix<T> X(P[l], m, zero<T>());
224 std::vector<T> col(P[l]);
225 for (std::size_t j = 0; j < m; ++j) {
226 for (std::size_t i = 0; i < P[l]; ++i) col[i] = Z(i, j);
227 lu_solve(lu[l], piv[l], col);
228 for (std::size_t i = 0; i < P[l]; ++i) X(i, j) = col[i];
229 }
230 return X;
231 }
232
233 std::size_t levels() const { return P.size(); }
234
235 /** X = M^{-1} Y. */
236 Matrix<T> colsolve(const Matrix<T>& Y) const {
237 const std::size_t L = levels(), m = Y.cols();
238 std::vector<Matrix<T>> Z(L), X(L);
239 for (std::size_t l = 0; l < L; ++l) {
240 Z[l] = block(Y, off[l], P[l], 0, m);
241 if (l > 0) {
242 const Matrix<T> GZ = matmul(G[l], Z[l - 1]);
243 for (std::size_t i = 0; i < P[l]; ++i)
244 for (std::size_t j = 0; j < m; ++j) Z[l](i, j) -= GZ(i, j);
245 }
246 }
247 X[L - 1] = left_solve(L - 1, Z[L - 1]);
248 for (std::size_t l = L - 1; l-- > 0;) {
249 const Matrix<T> UX = matmul(U[l], X[l + 1]);
250 for (std::size_t i = 0; i < P[l]; ++i)
251 for (std::size_t j = 0; j < m; ++j) Z[l](i, j) -= UX(i, j);
252 X[l] = left_solve(l, Z[l]);
253 }
254 Matrix<T> out(Y.rows(), m, zero<T>());
255 for (std::size_t l = 0; l < L; ++l)
256 for (std::size_t i = 0; i < P[l]; ++i)
257 for (std::size_t j = 0; j < m; ++j) out(off[l] + i, j) = X[l](i, j);
258 return out;
259 }
260
261 /** x = y M^{-1}. */
262 std::vector<T> rowsolve(const std::vector<T>& y) const {
263 const std::size_t L = levels();
264 std::vector<std::vector<T>> w(L);
265 for (std::size_t l = 0; l < L; ++l) {
266 std::vector<T> r(y.begin() + off[l], y.begin() + off[l + 1]);
267 if (l > 0) {
268 const std::vector<T> wu = vecmul(w[l - 1], U[l - 1]);
269 for (std::size_t i = 0; i < r.size(); ++i) r[i] -= wu[i];
270 }
271 w[l] = lu_solve_trans(lu[l], piv[l], r);
272 }
273 std::vector<T> x(y.size(), zero<T>());
274 for (std::size_t i = 0; i < P[L - 1]; ++i) x[off[L - 1] + i] = w[L - 1][i];
275 for (std::size_t l = L - 1; l-- > 0;) {
276 const std::vector<T> xn(x.begin() + off[l + 1], x.begin() + off[l + 2]);
277 const std::vector<T> xg = vecmul(xn, G[l + 1]);
278 for (std::size_t i = 0; i < P[l]; ++i) x[off[l] + i] = w[l][i] - xg[i];
279 }
280 return x;
281 }
282};
283
284/** Throws LINE:unsupported:Structure if M is not block tridiagonal by level. */
285template <class T>
286void check(const Matrix<T>& M, const std::vector<std::size_t>& P, std::size_t set) {
287 std::vector<std::size_t> lev;
288 for (std::size_t l = 0; l < P.size(); ++l)
289 for (std::size_t i = 0; i < P[l]; ++i) lev.push_back(l + 1);
290 for (std::size_t i = 0; i < M.rows(); ++i)
291 for (std::size_t j = 0; j < M.cols(); ++j) {
292 const std::size_t d = lev[i] > lev[j] ? lev[i] - lev[j] : lev[j] - lev[i];
293 if (d > 1 && !(M(i, j) == zero<T>()))
294 throw UnsupportedError(
295 ErrorKind{"Structure"},
296 "ldqbd_censor: set " + std::to_string(set + 1) +
297 " is not block tridiagonal by level after censoring out the sets before it "
298 "(transition from level " + std::to_string(lev[i]) + " to level " +
299 std::to_string(lev[j]) + "); successive censoring does not apply in this set order.");
300 }
301}
302
303} // namespace ldqbd_censor_detail
304
305/**
306 * Stationary distribution of a chain of connected LDQBDs (ldqbd_censor.m).
307 *
308 * @param Q generator ordered by (set, level, phase)
309 * @param phases phases[s][l] is the number of phases of level l of set s
310 * @param tol relative tolerance on the row sums (ignored at exact T,
311 * where the rows must sum to exactly zero)
312 */
313template <class T>
314LdqbdCensorResult<T> ldqbd_censor(const Matrix<T>& Q, const std::vector<std::vector<std::size_t>>& phases,
315 double tol = 1e-10) {
316 using namespace ldqbd_censor_detail;
317 if (phases.empty()) throw InputError(ErrorKind{"Argument"}, "ldqbd_censor: phases must give one vector of phase counts per set.");
318 const std::size_t S = phases.size();
319 std::vector<std::size_t> nset(S, 0), setOff(S + 1, 0);
320 for (std::size_t s = 0; s < S; ++s) {
321 if (phases[s].empty())
322 throw InputError(ErrorKind{"Argument"}, "ldqbd_censor: phases{" + std::to_string(s + 1) +
323 "} must be a non-empty vector of positive integers.");
324 for (std::size_t p : phases[s]) {
325 if (p < 1)
326 throw InputError(ErrorKind{"Argument"}, "ldqbd_censor: phases{" + std::to_string(s + 1) +
327 "} must be a non-empty vector of positive integers.");
328 nset[s] += p;
329 }
330 setOff[s + 1] = setOff[s] + nset[s];
331 }
332 const std::size_t n = setOff[S];
333 if (Q.rows() != Q.cols()) throw InputError(ErrorKind{"Argument"}, "ldqbd_censor: Q must be square.");
334 if (Q.rows() != n)
335 throw InputError(ErrorKind{"Argument"}, "ldqbd_censor: Q has order " + std::to_string(Q.rows()) +
336 " but the phase counts add up to " + std::to_string(n) + ".");
337
338 // sparse row store of the working generator, indexed by global state
339 std::vector<std::map<std::size_t, T>> rows(n);
340 double scale = 1.0;
341 for (std::size_t i = 0; i < n; ++i) {
342 const double d = num_traits<T>::to_double(num_abs(T(Q(i, i))));
343 if (d > scale) scale = d;
344 }
345 for (std::size_t i = 0; i < n; ++i) {
346 T rs = zero<T>();
347 for (std::size_t j = 0; j < n; ++j) {
348 const T v = Q(i, j);
349 if (v == zero<T>()) continue;
350 if (i != j && v < zero<T>())
351 throw InputError(ErrorKind{"Argument"}, "ldqbd_censor: the off-diagonal entries of Q must be nonnegative.");
352 rows[i][j] = v;
353 rs += v;
354 }
355 const bool bad = num_traits<T>::is_exact ? !(rs == zero<T>())
356 : num_traits<T>::to_double(num_abs(rs)) > tol * scale;
357 if (bad) throw InputError(ErrorKind{"Argument"}, "ldqbd_censor: the rows of Q must sum to zero.");
358 }
359
360 // successive censoring of sets 1..S-1
361 std::vector<Factor<T>> fac;
362 std::vector<std::vector<std::size_t>> bRows(S);
363 std::vector<std::vector<std::vector<T>>> bVals(S);
364 for (std::size_t k = 0; k + 1 < S; ++k) {
365 const std::size_t o0 = setOff[k], o1 = setOff[k + 1], nk = nset[k];
366 Matrix<T> M(nk, nk, zero<T>());
367 std::map<std::size_t, std::size_t> colPos;
368 for (std::size_t i = 0; i < nk; ++i)
369 for (const auto& e : rows[o0 + i]) {
370 if (e.first >= o0 && e.first < o1) M(i, e.first - o0) = -e.second;
371 else if (e.first >= o1) colPos[e.first] = 0;
372 }
373 check(M, phases[k], k);
374 fac.emplace_back(M, phases[k], k, false);
375 std::vector<std::size_t> cols;
376 for (auto& c : colPos) {
377 c.second = cols.size();
378 cols.push_back(c.first);
379 }
380 Matrix<T> QkB(nk, cols.size(), zero<T>());
381 for (std::size_t i = 0; i < nk; ++i)
382 for (const auto& e : rows[o0 + i])
383 if (e.first >= o1) QkB(i, colPos[e.first]) = e.second;
384 for (std::size_t r = o1; r < n; ++r) {
385 std::vector<T> v;
386 for (const auto& e : rows[r]) {
387 if (e.first >= o0 && e.first < o1 && !(e.second == zero<T>())) {
388 if (v.empty()) v.assign(nk, zero<T>());
389 v[e.first - o0] = e.second;
390 }
391 }
392 if (!v.empty()) {
393 bRows[k].push_back(r);
394 bVals[k].push_back(v);
395 }
396 }
397 if (!cols.empty() && !bRows[k].empty()) {
398 const Matrix<T> X = fac.back().colsolve(QkB);
399 for (std::size_t i = 0; i < bRows[k].size(); ++i) {
400 const std::vector<T> u = vecmul(bVals[k][i], X);
401 auto& row = rows[bRows[k][i]];
402 for (std::size_t j = 0; j < cols.size(); ++j) {
403 if (u[j] == zero<T>()) continue;
404 auto it = row.find(cols[j]);
405 if (it == row.end()) row[cols[j]] = u[j];
406 else it->second += u[j];
407 }
408 }
409 }
410 }
411
412 // intermediate step: level reduction on the last LDQBD
413 const std::size_t oS = setOff[S - 1], nS = nset[S - 1];
414 Matrix<T> MS(nS, nS, zero<T>());
415 for (std::size_t i = 0; i < nS; ++i)
416 for (const auto& e : rows[oS + i])
417 if (e.first >= oS) MS(i, e.first - oS) = -e.second;
418 check(MS, phases[S - 1], S - 1);
419 const Factor<T> f(MS, phases[S - 1], S - 1, true);
420 const std::size_t L = f.levels();
421 Matrix<T> A = f.S[L - 1];
422 for (std::size_t i = 0; i < A.rows(); ++i) A(i, 0) = num_traits<T>::from_int(1);
423 // x A = e1 <=> A' x' = e1'
424 Matrix<T> At(A.cols(), A.rows(), zero<T>());
425 for (std::size_t i = 0; i < A.rows(); ++i)
426 for (std::size_t j = 0; j < A.cols(); ++j) At(j, i) = A(i, j);
427 std::vector<T> e1(A.rows(), zero<T>());
428 e1[0] = num_traits<T>::from_int(1);
429 std::vector<T> xL;
430 try {
431 xL = solve(At, e1);
432 } catch (const NumericError&) {
433 throw NumericError(ErrorKind{"Singular"}, "ldqbd_censor: the last level of set " + std::to_string(S) +
434 " has no unique stationary vector; the chain may be reducible.");
435 }
436 std::vector<T> pB(n, zero<T>());
437 for (std::size_t i = 0; i < xL.size(); ++i) pB[oS + f.off[L - 1] + i] = xL[i];
438 for (std::size_t l = L - 1; l-- > 0;) {
439 const std::vector<T> xn(pB.begin() + oS + f.off[l + 1], pB.begin() + oS + f.off[l + 2]);
440 const std::vector<T> xg = vecmul(xn, f.G[l + 1]);
441 for (std::size_t i = 0; i < f.P[l]; ++i) pB[oS + f.off[l] + i] = -xg[i];
442 }
443
444 // expansion back through sets S-1..1
445 for (std::size_t k = S - 1; k-- > 0;) {
446 std::vector<T> y(nset[k], zero<T>());
447 for (std::size_t i = 0; i < bRows[k].size(); ++i) {
448 const T p = pB[bRows[k][i]];
449 if (p == zero<T>()) continue;
450 for (std::size_t t = 0; t < nset[k]; ++t) y[t] += p * bVals[k][i][t];
451 }
452 const std::vector<T> x = fac[k].rowsolve(y);
453 for (std::size_t t = 0; t < nset[k]; ++t) pB[setOff[k] + t] = x[t];
454 }
455 T tot = zero<T>();
456 for (const T& v : pB) tot += v;
458 res.pi.resize(n);
459 for (std::size_t i = 0; i < n; ++i) res.pi[i] = pB[i] / tot;
460 std::size_t pos = 0;
461 res.pi_cells.resize(S);
462 for (std::size_t s = 0; s < S; ++s)
463 for (std::size_t p : phases[s]) {
464 res.pi_cells[s].emplace_back(res.pi.begin() + pos, res.pi.begin() + pos + p);
465 pos += p;
466 }
467 return res;
468}
469
470} // namespace mam
471} // namespace line
472
473#endif // LINE_API_MAM_LDQBD_CENSOR_H
InputError(const std::string &what)
Definition error.h:105
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
The algorithm cannot produce a trustworthy answer on this instance: LINE:numerical:<kind>.
Definition error.h:110
NumericError(const std::string &what)
Definition error.h:112
UnsupportedError(const std::string &what)
Definition error.h:119
The exception types the port throws.
Dense linear algebra over the templated number type: products, identity, inverse, and powers.
LU factorization with partial pivoting, templated on the number type.
Dense matrix and non-owning view.
Matrix< T > block(const Matrix< T > &M, std::size_t r0, std::size_t nr, std::size_t c0, std::size_t nc)
double norm1(const Matrix< T > &A)
std::vector< std::size_t > checked_lu(Matrix< T > &F, std::size_t level, std::size_t set)
LU with partial pivoting of a Schur complement (in place), refusing a singular one.
void check(const Matrix< T > &M, const std::vector< std::size_t > &P, std::size_t set)
Throws LINE:unsupported:Structure if M is not block tridiagonal by level.
std::vector< T > lu_solve_trans(const Matrix< T > &LU, const std::vector< std::size_t > &piv, std::vector< T > x)
x with x A = y (A' x' = y'), from the factors of lu_factor.
double inv_norm1(const Matrix< T > &LU, const std::vector< std::size_t > &piv)
1-norm of A^{-1} from the LU factors of A, by Hager's estimator (the one behind LAPACK's condition es...
LdqbdCensorResult< T > ldqbd_censor(const Matrix< T > &Q, const std::vector< std::vector< std::size_t > > &phases, double tol=1e-10)
Stationary distribution of a chain of connected LDQBDs (ldqbd_censor.m).
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
void lu_solve(const Matrix< T > &LU, const std::vector< std::size_t > &piv, std::vector< T > &b)
Solve LUx = Pb in place on b, using the factors from lu_factor.
Definition lu.h:94
T num_abs(const T &v)
Definition number.h:205
std::vector< T > vecmul(const std::vector< T > &v, const Matrix< T > &A)
Row vector times matrix, v A.
Definition linalg.h:50
std::vector< std::size_t > lu_factor(Matrix< T > &A)
In-place LU of A (n x n).
Definition lu.h:48
Matrix< T > matmul(const Matrix< T > &A, const Matrix< T > &B)
Matrix product A B.
Definition linalg.h:36
std::vector< T > solve(const Matrix< T > &A, const std::vector< T > &b)
Convenience: solve Ax = b, leaving A and b untouched.
Definition lu.h:158
Number-type abstraction for the templated API port.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
Stationary distribution of a chain of connected LDQBDs.
std::vector< T > pi
in the ordering of Q
std::vector< std::vector< std::vector< T > > > pi_cells
pi_cells[s][l], level l of set s
std::vector< std::vector< std::size_t > > piv
std::vector< T > rowsolve(const std::vector< T > &y) const
x = y M^{-1}.
Matrix< T > left_solve(std::size_t l, const Matrix< T > &Z) const
X = S_l^{-1} Z, column by column.
Factor(const Matrix< T > &M, const std::vector< std::size_t > &P_, std::size_t set, bool last_singular)
Matrix< T > colsolve(const Matrix< T > &Y) const
X = M^{-1} Y.
std::vector< std::size_t > off
std::vector< Matrix< T > > lu