LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
aoi_lst_ph.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_AOI_LST_PH_H
6#define LINE_API_AOI_LST_PH_H
7
8/**
9 * @file
10 * @ingroup api_aoi
11 * Laplace-Stieltjes transform of a phase-type distribution PH(alpha, T).
12 *
13 * Templated port of matlab/src/api/aoi/aoi_lst_ph.m, cross-checked against
14 * Aoi_lst.ph in jar/src/main/java/jline/api/aoi/Aoi_lst.java (identical).
15 *
16 * H*(s) = alpha (s I - T)^{-1} t, t = -T e
17 *
18 * MATLAB evaluates it as the linear solve alpha * ((sI - T) \ t) rather than
19 * by forming the inverse, and this port does the same through the LU in
20 * line/util/lu.h. A linear solve stays in the field, so a PH with rational
21 * parameters has an exactly representable transform at every rational s --
22 * which makes this the natural exact stand-in for aoi_lst_det, since an
23 * Erlang-k with k -> inf approaches a constant while staying rational.
24 */
25
26#include <cstddef>
27#include <vector>
28
30#include "line/num/number.h"
31#include "line/util/error.h"
32#include "line/util/linalg.h"
33#include "line/util/lu.h"
34#include "line/util/matrix.h"
35
36namespace line {
37namespace aoi {
38
39/**
40 * @brief Laplace-Stieltjes transform of a phase-type distribution PH(alpha,
41 * T).
42 *
43 * @param alpha initial probability row vector, length n
44 * @param Tmat sub-generator, n x n
45 * @return s -> alpha (sI - Tmat)^{-1} (-Tmat e)
46 */
47template <class T>
48Lst<T> aoi_lst_ph(const std::vector<T>& alpha, const Matrix<T>& Tmat) {
49 const std::size_t n = alpha.size();
50 if (n == 0) throw InputError("aoi_lst_ph: alpha must be non-empty");
51 if (Tmat.rows() != n || Tmat.cols() != n)
52 throw InputError("aoi_lst_ph: the sub-generator must be square and match the length of alpha");
53
54 // Exit rate vector t = -T e.
55 std::vector<T> t = mulvec(Tmat, ones<T>(n));
56 for (std::size_t i = 0; i < n; ++i) t[i] = -t[i];
57
58 return [alpha, Tmat, t, n](const T& s) {
60 for (std::size_t i = 0; i < n; ++i)
61 for (std::size_t j = 0; j < n; ++j) A(i, j) = (i == j ? T(s - Tmat(i, j)) : T(-Tmat(i, j)));
62 std::vector<T> x = t;
63 const std::vector<std::size_t> piv = lu_factor(A);
64 lu_solve(A, piv, x);
66 for (std::size_t i = 0; i < n; ++i) v += alpha[i] * x[i];
67 return v;
68 };
69}
70
71} // namespace aoi
72} // namespace line
73
74#endif // LINE_API_AOI_LST_PH_H
Shared return types and arithmetic helpers for the templated Age of Information port.
InputError(const std::string &what)
Definition error.h:39
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
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.
std::function< T(const T &)> Lst
A Laplace-Stieltjes transform evaluated at real arguments.
Definition aoi_types.h:41
Lst< T > aoi_lst_ph(const std::vector< T > &alpha, const Matrix< T > &Tmat)
Laplace-Stieltjes transform of a phase-type distribution PH(alpha, T).
Definition aoi_lst_ph.h:48
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
std::vector< std::size_t > lu_factor(Matrix< T > &A)
In-place LU of A (n x n).
Definition lu.h:48
std::vector< T > mulvec(const Matrix< T > &A, const std::vector< T > &v)
Matrix times column vector, A v.
Definition linalg.h:62
std::vector< T > ones(std::size_t n)
Column vector of ones, the ubiquitous e in MAP algebra.
Definition linalg.h:104
Number-type abstraction for the templated API port.