5#ifndef LINE_API_QSYS_QSYS_MMAPMAP1_H
6#define LINE_API_QSYS_QSYS_MMAPMAP1_H
68 const std::size_t n = m.
D0.rows();
69 if (n == 1)
return true;
71 double err = 0.0, nrm = 0.0;
72 for (std::size_t i = 0; i < n; ++i) {
74 for (std::size_t j = 0; j < n; ++j) ti += num_traits<T>::to_double(m.
D1(i, j));
75 for (std::size_t j = 0; j < n; ++j) {
82 return std::sqrt(err) < 1e-9 * std::max(1.0, std::sqrt(nrm));
97 std::vector<bool> carry = std::vector<bool>()) {
99 const std::size_t K = arrival.
Dc.size();
101 throw InputError(
"qsys_mmapmap1: svc must give one service MAP per arrival mark");
102 const std::size_t ma = arrival.
D0.rows();
104 std::vector<T> lamk(K, zero);
105 for (std::size_t k = 0; k < K; ++k)
106 for (std::size_t i = 0; i < ma; ++i)
107 for (std::size_t j = 0; j < ma; ++j) lamk[k] += piA[i] * arrival.
Dc[k](i, j);
109 carry.assign(K,
false);
112 if (carry.size() != K)
throw InputError(
"qsys_mmapmap1: carry must give one flag per class");
114 for (std::size_t k = 0; k < K; ++k) carry[k] = carry[k] && lamk[k] > zero;
116 std::vector<std::size_t> pk(K, 1), cidx;
118 for (std::size_t k = 0; k < K; ++k) {
119 if (!carry[k])
continue;
120 pk[k] = svc[k].D0.rows();
128 std::vector<mam::PhService<T> > ph;
129 std::vector<std::size_t> markClass;
131 for (std::size_t k = 0; k < K; ++k) {
137 markClass.push_back(k);
140 const std::size_t p = pk[k];
142 for (std::size_t i = 0; i < p; ++i)
143 for (std::size_t j = 0; j < p; ++j) negS0(i, j) = -S0(i, j);
145 for (std::size_t i = 0; i < p; ++i)
146 for (std::size_t j = 0; j < p; ++j)
147 if (V(i, j) < tiny && V(i, j) > -tiny) V(i, j) = zero;
148 for (std::size_t h = 0; h < p; ++h) {
149 for (std::size_t j = 0; j < p; ++j) {
150 if (!(V(h, j) > zero))
continue;
153 for (std::size_t kk : cidx) {
163 std::vector<std::size_t> Jset;
164 for (std::size_t i = 0; i < p; ++i)
165 if (V(i, j) > zero) Jset.push_back(i);
166 const std::size_t nJ = Jset.size();
168 std::vector<T> sig(nJ, zero);
169 for (std::size_t a = 0; a < nJ; ++a) {
170 const std::size_t i = Jset[a];
172 for (std::size_t bb = 0; bb < nJ; ++bb) {
173 if (bb == a)
continue;
174 const std::size_t i2 = Jset[bb];
175 G(a, bb) = S0(i, i2) * V(i2, j) / V(i, j);
177 if (i == h) sig[a] = one;
181 markClass.push_back(k);
185 for (std::size_t m = 0; m < lifted.
Dc.size(); ++m)
186 for (std::size_t i = 0; i < ma * P; ++i)
187 for (std::size_t j = 0; j < ma * P; ++j) lifted.
D1(i, j) += lifted.
Dc[m](i, j);
193 for (std::size_t m = 0; m < markClass.size(); ++m) r.
meanQueueLength[markClass[m]] += Qm[m];
194 for (std::size_t k = 0; k < K; ++k)
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.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
Marked MAP (MMAP) algebra: per-class rates, class probabilities, superposition, normalization and sca...
The MMAP[K]/PH[K]/1 FCFS queue: per-class mean number in system and per-class queue-length distributi...
std::vector< T > mmapph1fcfs_ncmean(const Mmap< T > &arrival, const std::vector< PhService< T > > &svc)
Per-class mean number of customers in the system, BUTools' 'ncMoms', 1.
Matrix< T > kron(const Matrix< T > &A, const Matrix< T > &B)
Kronecker product.
std::vector< T > map_prob(const Map< T > &m)
Stationary distribution of the phase process, pi (D0 + D1) = 0.
std::vector< T > map_pie(const Map< T > &m)
Phase distribution seen by an arriving job, pie = pi D1 / (pi D1 e).
bool is_renewal(const mam::Map< T > &m)
D1 = (-D0 e) alpha to within tolerance, as mam_is_renewal_map.
MmapMap1Result< T > qsys_mmapmap1(const mam::Mmap< T > &arrival, const std::vector< mam::Map< T > > &svc, std::vector< bool > carry=std::vector< bool >())
MMAP[K]/MAP[K]/1 FCFS with per-class carried service phases, exactly.
Conservation laws of a layered queueing network, enumerated from its structure.
Matrix< T > inverse(const Matrix< T > &A)
Inverse by LU with one factorization and n back substitutions.
Matrix< T > matmul(const Matrix< T > &A, const Matrix< T > &B)
Matrix product A B.
Matrix< T > eye(std::size_t n)
Identity of order n.
Number-type abstraction for the templated API port.
A MAP as the pair of matrices (D0, D1).
An MMAP: the underlying MAP plus the per-class arrival matrices.
std::vector< Matrix< T > > Dc
per-class matrices, sum_c Dc = D1
One class's phase-type service law, He's (sigma_k, S_k).
Return value of qsys_mmapmap1, mirroring the MATLAB struct.
std::vector< T > arrivalRate
class arrival rates
std::vector< T > meanQueueLength
E[N_k].
std::vector< bool > carry
classes whose service phase is carried
std::vector< T > meanSojournTime
E[W_k], by Little's law.
std::size_t markCount
marks of the lifted MMAP