LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
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
29
#include "
line/api/aoi/aoi_types.h
"
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
36
namespace
line
{
37
namespace
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
*/
47
template
<
class
T>
48
Lst<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) {
59
Matrix<T>
A(n, n,
num_traits<T>::from_int
(0));
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);
65
T v =
num_traits<T>::from_int
(0);
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
aoi_types.h
Shared return types and arithmetic helpers for the templated Age of Information port.
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
line::Matrix
Definition
matrix.h:56
line::Matrix::cols
std::size_t cols() const
Definition
matrix.h:90
line::Matrix::rows
std::size_t rows() const
Definition
matrix.h:89
error.h
The exception types the port throws.
linalg.h
Dense linear algebra over the templated number type: products, identity, inverse, and powers.
lu.h
LU factorization with partial pivoting, templated on the number type.
matrix.h
Dense matrix and non-owning view.
line::aoi
Definition
aoi_dist2ph.h:53
line::aoi::Lst
std::function< T(const T &)> Lst
A Laplace-Stieltjes transform evaluated at real arguments.
Definition
aoi_types.h:41
line::aoi::aoi_lst_ph
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
line
Definition
aoi_dist2ph.h:52
line::lu_solve
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
line::lu_factor
std::vector< std::size_t > lu_factor(Matrix< T > &A)
In-place LU of A (n x n).
Definition
lu.h:48
line::mulvec
std::vector< T > mulvec(const Matrix< T > &A, const std::vector< T > &v)
Matrix times column vector, A v.
Definition
linalg.h:62
line::ones
std::vector< T > ones(std::size_t n)
Column vector of ones, the ubiquitous e in MAP algebra.
Definition
linalg.h:104
number.h
Number-type abstraction for the templated API port.
line::num_traits
Definition
number.h:111
include
line
api
aoi
aoi_lst_ph.h
Generated by
1.18.0