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 jar/src/main/java/jline/api/mc/Ctmc_stmonotone.java, which
14
* has no MATLAB twin. Given a row-stochastic P the algorithm of Abu-Kamel and
15
* Stewart builds the smallest st-monotone Q that dominates P in the strong
16
* stochastic order, by filling the tail sums from the last column backwards:
17
* Q(0,l..n-1) = P(0,l..n-1),
18
* Q(i,l..n-1) = max( Q(i-1,l..n-1), P(i,l..n-1) ),
19
* and recovering Q(i,l) as that tail sum minus the tail already assigned. Every
20
* row tail of Q then dominates the corresponding row tail of P and is
21
* nondecreasing in i, which is exactly st-monotonicity.
22
*
23
* The CTMC entry uniformizes Q at max|Q| (the rate the reference uses), repairs
24
* the rounding through dtmc_makestochastic, bounds the embedded chain and maps
25
* the bound back to a generator with ctmc_makeinfgen. Uniformization is a
26
* bijection between the two, so the bound is preserved.
27
*
28
* ARITHMETIC: field plus comparisons. Exact under Rational.
29
*/
30
31
#include <cstddef>
32
33
#include "
line/api/mc/ctmc_randomization.h
"
34
#include "
line/api/mc/ctmc_solve.h
"
35
#include "
line/api/mc/dtmc_makestochastic.h
"
36
#include "
line/num/number.h
"
37
#include "
line/util/error.h
"
38
#include "
line/util/matrix.h
"
39
40
namespace
line
{
41
namespace
mc
{
42
43
/**
44
* @param P (n x n) row-stochastic transition matrix
45
* @return the st-monotone upper bound of P, itself row-stochastic
46
*/
47
template
<
class
T>
48
Matrix<T>
dtmc_stmonotone
(
const
Matrix<T>
& P) {
49
const
std::size_t n = P.
rows
();
50
if
(n == 0)
throw
InputError
(
"dtmc_stmonotone: the matrix is empty"
);
51
if
(P.
cols
() != n)
throw
InputError
(
"dtmc_stmonotone: the matrix is not square"
);
52
const
T zero =
num_traits<T>::from_int
(0);
53
Matrix<T>
Q(n, n, zero);
54
55
Q(0, n - 1) = P(0, n - 1);
56
for
(std::size_t i = 1; i < n; ++i)
57
Q(i, n - 1) = Q(i - 1, n - 1) > P(i, n - 1) ? Q(i - 1, n - 1) : P(i, n - 1);
58
59
for
(std::size_t
lp
= n - 1;
lp
-- > 0;) {
60
Q(0,
lp
) = P(0,
lp
);
61
for
(std::size_t i = 1; i < n; ++i) {
62
T tailPrev = zero, tailP = zero, tailRight = zero;
63
for
(std::size_t k =
lp
; k < n; ++k) {
64
tailPrev += Q(i - 1, k);
65
tailP += P(i, k);
66
if
(k >
lp
) tailRight += Q(i, k);
67
}
68
Q(i,
lp
) = T((tailPrev > tailP ? tailPrev : tailP) - tailRight);
69
}
70
}
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 of the st-monotone upper bound of Q
79
*/
80
template
<
class
T>
81
Matrix<T>
ctmc_stmonotone
(
const
Matrix<T>
& Q) {
82
const
T m =
ctmc_maxabs
(Q);
83
// An all-zero generator has no rate to uniformize at; any positive q gives P = Id.
84
const
T q = (m ==
num_traits<T>::from_int
(0)) ?
num_traits<T>::from_int
(1) : m;
85
return
ctmc_makeinfgen
(
dtmc_stmonotone
(
ctmc_randomization
(Q, q).P));
86
}
87
88
}
// namespace mc
89
}
// namespace line
90
91
#endif
// LINE_API_MC_CTMC_STMONOTONE_H
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
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::lp
Definition
lp_highs.h:48
line::mc
Definition
ctmc_bicgstab.h:59
line::mc::dtmc_stmonotone
Matrix< T > dtmc_stmonotone(const Matrix< T > &P)
Definition
ctmc_stmonotone.h:48
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:58
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:81
line
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
line::num_traits
Definition
number.h:111
include
line
api
mc
ctmc_stmonotone.h
Generated by
1.18.0