LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
ctmc_stmonotone.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_MC_CTMC_STMONOTONE_H
6
#define LINE_API_MC_CTMC_STMONOTONE_H
7
8
/**
9
* @file
10
* @ingroup api_mc
11
* Stochastically monotone upper bound of a Markov chain.
12
*
13
* Templated port of matlab/src/api/mc/dtmc_stmonotone.m and
14
* matlab/src/api/mc/ctmc_stmonotone.m (JAR twin
15
* jline/api/mc/Ctmc_stmonotone.java). For a row-stochastic P on a totally
16
* ordered state space the algorithm of Abu-Amsha and Vincent (1998), as
17
* restated in Busic and Fourneau (SAINT-W 2005, Algorithm 1), returns the
18
* row-stochastic Q whose row tails are
19
*
20
* sum_{k>=l} Q(0,k) = sum_{k>=l} P(0,k)
21
* sum_{k>=l} Q(i,k) = max( sum_{k>=l} Q(i-1,k), sum_{k>=l} P(i,k) ), i >= 1,
22
*
23
* the least st-monotone matrix dominating P row-wise in the strong stochastic
24
* order. The first row of Q is the first row of P and every other entry is
25
* the difference of two consecutive tails, which are nonincreasing in the
26
* column index, so the entries are nonnegative. O(n^2), as MATLAB.
27
*
28
* The CTMC entry uniformizes Q at q = max|Q| (q = 1 when Q is all zero),
29
* repairs the chain I + Q/q through dtmc_makestochastic, bounds it, and maps
30
* the bound back to the generator q*(Pub - I) through ctmc_makeinfgen, so the
31
* bound runs on the time scale of Q itself and equals Q when I + Q/q is
32
* already st-monotone (user decision 2026-11-21; this port returned Pub - I, the
33
* bound divided by q, before).
34
*
35
* ARITHMETIC: field plus comparisons. Exact under Rational.
36
*/
37
38
#include <cstddef>
39
40
#include "
line/api/mc/ctmc_randomization.h
"
41
#include "
line/api/mc/ctmc_solve.h
"
42
#include "
line/api/mc/dtmc_makestochastic.h
"
43
#include "
line/num/number.h
"
44
#include "
line/util/error.h
"
45
#include "
line/util/matrix.h
"
46
47
namespace
line
{
48
namespace
mc
{
49
50
/**
51
* @param P (n x n) row-stochastic transition matrix
52
* @return the st-monotone upper bound of P, itself row-stochastic
53
*/
54
template
<
class
T>
55
Matrix<T>
dtmc_stmonotone
(
const
Matrix<T>
& P) {
56
const
std::size_t n = P.rows();
57
if
(n == 0)
throw
InputError
(
"dtmc_stmonotone: the matrix is empty"
);
58
if
(P.cols() != n)
throw
InputError
(
"dtmc_stmonotone: the matrix is not square"
);
59
const
T zero =
num_traits<T>::from_int
(0);
60
// tail sums TP(i,l) = sum_{k>=l} P(i,k), with a zero column at l = n
61
Matrix<T>
TQ(n, n + 1, zero);
62
for
(std::size_t i = 0; i < n; ++i)
63
for
(std::size_t l = n; l-- > 0;) TQ(i, l) = T(TQ(i, l + 1) + P(i, l));
64
for
(std::size_t i = 1; i < n; ++i)
65
for
(std::size_t l = 0; l <= n; ++l)
66
if
(TQ(i - 1, l) > TQ(i, l)) TQ(i, l) = TQ(i - 1, l);
67
Matrix<T>
Q(n, n, zero);
68
for
(std::size_t j = 0; j < n; ++j) Q(0, j) = P(0, j);
69
for
(std::size_t i = 1; i < n; ++i)
70
for
(std::size_t j = 0; j < n; ++j) Q(i, j) = T(TQ(i, j) - TQ(i, j + 1));
71
return
Q;
72
}
73
74
/**
75
* @brief Stochastically monotone upper bound of a Markov chain.
76
*
77
* @param Q (n x n) generator
78
* @return the generator q*(Pub - I) of the st-monotone upper bound of Q,
79
* q = max|Q| (1 for an all-zero Q)
80
*/
81
template
<
class
T>
82
Matrix<T>
ctmc_stmonotone
(
const
Matrix<T>
& Q) {
83
const
std::size_t n = Q.
rows
();
84
if
(n == 0)
throw
InputError
(
"ctmc_stmonotone: the matrix is empty"
);
85
if
(Q.
cols
() != n)
throw
InputError
(
"ctmc_stmonotone: the matrix is not square"
);
86
const
T m =
ctmc_maxabs
(Q);
87
// An all-zero generator has no rate to uniformize at; q = 1 gives P = Id.
88
const
T q = (m ==
num_traits<T>::from_int
(0)) ?
num_traits<T>::from_int
(1) : m;
89
const
Matrix<T>
Pub =
dtmc_stmonotone
(
ctmc_randomization
(Q, q).P);
90
Matrix<T>
R(n, n,
num_traits<T>::from_int
(0));
91
for
(std::size_t i = 0; i < n; ++i)
92
for
(std::size_t j = 0; j < n; ++j) R(i, j) = T(q * Pub(i, j));
93
return
ctmc_makeinfgen
(R);
94
}
95
96
}
// namespace mc
97
}
// namespace line
98
99
#endif
// LINE_API_MC_CTMC_STMONOTONE_H
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:105
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
ctmc_randomization.h
Uniformization (randomization) of a CTMC: the embedded DTMC P = I + Q/q.
ctmc_solve.h
Steady-state distribution of a continuous-time Markov chain.
dtmc_makestochastic.h
Normalize a non-negative matrix into a stochastic transition matrix.
error.h
The exception types the port throws.
matrix.h
Dense matrix and non-owning view.
line::mc
Definition
ctmc_accumulated.h:43
line::mc::dtmc_stmonotone
Matrix< T > dtmc_stmonotone(const Matrix< T > &P)
Definition
ctmc_stmonotone.h:55
line::mc::ctmc_makeinfgen
Matrix< T > ctmc_makeinfgen(const Matrix< T > &Q)
Set the diagonal so that every row sums to zero (ctmc_makeinfgen).
Definition
ctmc_solve.h:61
line::mc::ctmc_maxabs
T ctmc_maxabs(const Matrix< T > &Q)
Largest magnitude of any entry of Q; equals max_i |q_ii| for a generator.
Definition
ctmc_randomization.h:48
line::mc::ctmc_randomization
RandomizationResult< T > ctmc_randomization(const Matrix< T > &Q, const T &q)
Uniformization (randomization) of a CTMC: the embedded DTMC P = I + Q/q.
Definition
ctmc_randomization.h:66
line::mc::ctmc_stmonotone
Matrix< T > ctmc_stmonotone(const Matrix< T > &Q)
Stochastically monotone upper bound of a Markov chain.
Definition
ctmc_stmonotone.h:82
line
Conservation laws of a layered queueing network, enumerated from its structure.
Definition
aoi_dist2ph.h:51
number.h
Number-type abstraction for the templated API port.
line::num_traits
Definition
number.h:123
include
line
api
mc
ctmc_stmonotone.h
Generated by
1.18.0