5#ifndef LINE_API_MAM_MFQ_LD_MEAN_H
6#define LINE_API_MAM_MFQ_LD_MEAN_H
70 std::vector<std::vector<T>>
iniF;
71 std::vector<Matrix<T>>
KF;
72 std::vector<Matrix<T>>
cloF;
73 std::vector<std::vector<T>>
iniB;
74 std::vector<Matrix<T>>
KB;
75 std::vector<Matrix<T>>
cloB;
79namespace mfq_ld_detail {
88 const std::size_t n = M.
rows();
90 for (std::size_t i = 0; i < n; ++i) {
91 for (std::size_t j = 0; j < n; ++j) A(i, j) = M(i, j);
93 A(n + i, 2 * n + i) = one;
98 for (std::size_t i = 0; i < n; ++i)
99 for (std::size_t j = 0; j < n; ++j) {
100 J0(i, j) = W(i, n + j);
101 J1(i, j) = L * W(i, n + j) - W(i, 2 * n + j);
115 "mfq_ld_mean evaluates matrix exponentials");
117 const std::size_t K = b.
Thr.size();
118 if (K == 0)
throw InputError(
"mfq_ld_mean: at least one regime is required");
119 if (b.
masses.size() != K + 1)
120 throw InputError(
"mfq_ld_mean: expected K+1 point-mass vectors");
121 if (b.
iniF.size() != K || b.
KF.size() != K || b.
cloF.size() != K || b.
iniB.size() != K ||
122 b.
KB.size() != K || b.
cloB.size() != K)
123 throw InputError(
"mfq_ld_mean: expected K forward and K backward blocks");
124 const std::size_t N = b.
masses[0].size();
127 std::vector<T> Tv(K + 1, zero);
128 for (std::size_t k = 0; k < K; ++k) Tv[k + 1] = b.
Thr[k];
132 for (std::size_t j = 0; j <= K; ++j) {
133 if (b.
masses[j].size() != N)
134 throw InputError(
"mfq_ld_mean: the point-mass vectors have different lengths");
136 for (
const T& v : b.
masses[j]) s += v;
140 const std::vector<T> h =
ones<T>(N);
141 for (std::size_t k = 0; k < K; ++k) {
142 const T L = Tv[k + 1] - Tv[k];
144 mfq_ld_detail::exp_int_moments(b.
KF[k], L, J0F, J1F);
145 mfq_ld_detail::exp_int_moments(b.
KB[k], L, J0B, J1B);
147 for (std::size_t i = 0; i < WF.
rows(); ++i)
148 for (std::size_t j = 0; j < WF.
cols(); ++j) WF(i, j) += Tv[k] * J0F(i, j);
149 for (std::size_t i = 0; i < WB.rows(); ++i)
150 for (std::size_t j = 0; j < WB.cols(); ++j)
151 WB(i, j) = Tv[k + 1] * J0B(i, j) - WB(i, j);
154 for (std::size_t j = 0; j < N; ++j) res += t[j] * h[j];
158 for (std::size_t j = 0; j < N; ++j) res += t[j] * h[j];
The exception types the port throws.
Matrix exponential by scaling and squaring with a diagonal Pade approximant.
Dense linear algebra over the templated number type: products, identity, inverse, and powers.
Dense matrix and non-owning view.
T mfq_ld_mean(const LevelDependentFluidBlocks< T > &b)
Stationary mean fluid level of a level-dependent fluid queue.
std::vector< T > vecmul(const std::vector< T > &v, const Matrix< T > &A)
Row vector times matrix, v A.
std::vector< T > ones(std::size_t n)
Column vector of ones, the ubiquitous e in MAP algebra.
Matrix< T > expm(const Matrix< T > &A)
Matrix exponential exp(A).
Number-type abstraction for the templated API port.
The matrix-exponential building blocks of a multi-regime fluid queue, the output of mfq_ld_solve.
std::vector< std::vector< T > > masses
K+1 point-mass vectors of length N.
std::vector< T > Thr
K regime thresholds T(1)..T(K).
std::vector< Matrix< T > > KF
K forward matrix exponents.
std::vector< std::vector< T > > iniB
K backward initial vectors.
std::vector< Matrix< T > > KB
K backward matrix exponents.
std::vector< std::vector< T > > iniF
K forward initial vectors.
std::vector< Matrix< T > > cloF
K forward closing matrices.
std::vector< Matrix< T > > cloB
K backward closing matrices.