5#ifndef LINE_API_QSYS_QSYS_MAPG1_H
6#define LINE_API_QSYS_QSYS_MAPG1_H
128 throw InputError(
"qsys_mapg1: the mean service time must be positive");
137mam::Map<T> mapg1_erlang(
const T& mean, std::size_t k) {
138 if (k == 0)
throw InputError(
"qsys_mapg1: an Erlang fit needs at least one phase");
144 for (std::size_t i = 0; i < k; ++i) {
146 if (i + 1 < k) m.
D0(i, i + 1) = mu;
157mam::Map<T> mapg1_hyperexp2(
const T& mean,
const T& cv2) {
159 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
160 const T two = num_traits<T>::from_int(2);
161 const T p = T(T(one + sqrt(T(T(cv2 - one) / T(cv2 + one)))) / two);
162 const T l1 = T(two * p / mean), l2 = T(two * T(one - p) / mean);
169 m.D1(0, 1) = l1 * T(one - p);
171 m.D1(1, 1) = l2 * T(one - p);
189 "qsys_mapg1_service_fit requires transcendental arithmetic");
190 if (moments.empty())
throw InputError(
"qsys_mapg1: no service moments given");
192 const T m1 = moments[0];
194 if (moments.size() >= 3) {
196 return mam::aph_fit(moments[0], moments[1], moments[2]).aph;
198 if (moments.size() == 2) {
199 const T cv2 = T(T(moments[1] / T(m1 * m1)) - one);
204 const T den = cv2 > floored ? cv2 : floored;
206 const std::size_t k = kd < 1.0 ? 1u :
static_cast<std::size_t
>(kd);
208 return detail::mapg1_erlang(m1, k);
212 const std::size_t k = kd < 2.0 ? 2u :
static_cast<std::size_t
>(kd);
214 return detail::mapg1_erlang(m1, k);
218 return detail::mapg1_exponential(m1);
221 return detail::mapg1_hyperexp2(m1, cv2);
224 return detail::mapg1_exponential(m1);
237 std::size_t dist_size) {
239 "qsys_mapg1 requires transcendental arithmetic");
262 return qsys_mapg1(arrival, moments,
static_cast<std::size_t
>(100));
Minimal-order acyclic phase-type fit of the first three moments (matlab/lib/kpctoolbox/aph/aph_fit....
The exception types the port throws.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
AphFitResult< T > aph_fit(const T &e1, const T &e2, const T &e3, unsigned nmax, const T &tol)
Fit an APH(n) with n <= nmax to the raw moments e1, e2, e3.
T map_lambda(const Map< T > &m)
Stationary arrival rate, lambda = pi D1 e.
mam::Map< T > qsys_mapg1_service_fit(const std::vector< T > &moments, MapG1ServiceFit &kind)
Fit a general service time to a PH, following qsys_mapg1.m's fitServiceToPH.
MapG1ServiceFit
Which branch of fitServiceToPH was taken, for the caller and for tests.
@ Acyclic
three or more moments
@ Hyperexponential
cv2 > 1
@ Exponential
one moment, or cv2 exactly 1
@ Erlang
0 < cv2 < 1, or the cv2 <= 0 branch
MapMap1Result< T > qsys_mapmap1(const mam::Map< T > &arrival, const mam::Map< T > &service, std::size_t dist_size)
MAP/MAP/1 by the exact QBD solution.
MapG1Result< T > qsys_mapg1(const mam::Map< T > &arrival, const std::vector< T > &moments, std::size_t dist_size)
The MAP/G/1 FCFS queue.
Number-type abstraction for the templated API port.
The MAP/MAP/1 FCFS queue: mean number in system, waiting time, sojourn time, utilization and the queu...
A MAP as the pair of matrices (D0, D1).
MapG1ServiceFit fitKind
which branch produced it
T meanWaitingTime
max(0, E[W] - m1), as in the reference
T meanQueueLength
E[N], number in system.
std::size_t servicePhases
order of the fitted PH
mam::Map< T > serviceFit
the fitted PH as its renewal MAP
std::vector< T > queueLengthDist
P(N = n), n = 0, 1, ...
Return value of the MAP/MAP/1 family (qsys_mapmap1, qsys_mapph1, qsys_phph1), carrying the same quant...
T meanQueueLength
E[N], number in system.
T meanSojournTime
E[W] = E[Wq] + E[S].
std::vector< T > queueLengthDist
P(N = n), n = 0, 1, ...