LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
qsys_gig1_approx_myskja2.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_QSYS_QSYS_GIG1_APPROX_MYSKJA2_H
6#define LINE_API_QSYS_QSYS_GIG1_APPROX_MYSKJA2_H
7
8/**
9 * @file
10 * @ingroup api_qsys
11 * Myskja's enhanced third-moment approximation of the mean response time of a
12 * G/I/G/1 queue.
13 *
14 * Templated port of matlab/src/api/qsys/qsys_gig1_approx_myskja2.m.
15 *
16 * ra = (1+ca^2)/2, rs = (1+cs^2)/2, rho = lambda/mu
17 * theta = [ rho(qa-ra) - (qa-ra^2) ] / [ 2 rho (ra-1) ]
18 * d = (1+1/ra)(1-rs)(1-(q0/qa)^3)(1-rho^3)
19 * D = (rs-theta)^2 + (2 rs - 1 + d)(ra-1), clamped at 0
20 * Wq = (rho/(1-rho))/mu [ rs + (1/rho)( sqrt(D) - (rs-theta) ) ], W = Wq + 1/mu
21 *
22 * The waiting-time bracket is scaled by 1/mu (not 1/lambda): with that scale the
23 * formula is exact for every H2/M/1 queue (cs = 1, any qa) and tends to the
24 * exact M/G/1 anchor as ca -> 1. The 1/lambda scale used before 2026-11-23
25 * missed both.
26 *
27 * At ca = 1 the interpolation parameter theta is a 0/0 form, so the exact
28 * M/G/1 answer is returned instead; that is also the anchor the method
29 * interpolates from.
30 *
31 * ARITHMETIC. sqrt(D) and the cube of q0/qa make this transcendental (the cube
32 * alone would not, but the square root does), so the function is gated.
33 *
34 * ca and cs are coefficients of variation in all four codebases (the JAR once
35 * read them as SCVs; that was fixed in favour of MATLAB).
36 */
37
40#include "line/num/number.h"
41
42namespace line {
43namespace qsys {
44
45/**
46 * @brief Myskja's enhanced third-moment approximation of the mean response
47 * time of a G/I/G/1 queue.
48 *
49 * @param lambda arrival rate
50 * @param mu service rate
51 * @param ca coefficient of variation of the interarrival time
52 * @param cs coefficient of variation of the service time
53 * @param q0 smallest third relative moment for the given mean and SCV
54 * @param qa third relative moment E[A^3]/(6 E[A]^3) of the interarrival time
55 */
56template <class T>
57QsysResult<T> qsys_gig1_approx_myskja2(const T& lambda, const T& mu, const T& ca, const T& cs,
58 const T& q0, const T& qa) {
60 "qsys_gig1_approx_myskja2 requires transcendental arithmetic");
61 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
62 const T two = num_traits<T>::from_int(2);
63 if (num_abs(T(ca * ca - one)) < T(num_traits<T>::from_double(1e-8)))
64 return qsys_mg1(lambda, mu, cs); // M/G/1 case: exact
65
66 const T ra = (one + ca * ca) / two;
67 const T rs = (one + cs * cs) / two;
68 const T rho = lambda / mu;
69 if (detail::saturated(rho, "qsys_gig1_approx_myskja2")) return {detail::num_inf<T>(), one};
70 const T theta = (rho * (qa - ra) - (qa - ra * ra)) / (two * rho * (ra - one));
71 const T d = (one + one / ra) * (one - rs) * (one - num_pow_int(T(q0 / qa), 3)) *
72 (one - num_pow_int(rho, 3));
73 T D = num_pow_int(T(rs - theta), 2) + (two * rs - one + d) * (ra - one);
74 if (D < zero) D = zero; // guard small negative values due to round-off
75 const T Wq = (rho / (one - rho)) / mu *
76 (rs + (one / rho) * (detail::num_sqrt(D) - (rs - theta)));
77 const T W = Wq + one / mu;
78 return {W, detail::rhohat_from_W(W, lambda)};
79}
80
81} // namespace qsys
82} // namespace line
83
84#endif // LINE_API_QSYS_QSYS_GIG1_APPROX_MYSKJA2_H
QsysResult< T > qsys_gig1_approx_myskja2(const T &lambda, const T &mu, const T &ca, const T &cs, const T &q0, const T &qa)
Myskja's enhanced third-moment approximation of the mean response time of a G/I/G/1 queue.
QsysResult< T > qsys_mg1(const T &lambda, const T &mu, const T &cs)
Exact mean response time of the M/G/1 queue (Pollaczek-Khinchine).
Definition qsys_mg1.h:40
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
T num_abs(const T &v)
Definition number.h:184
T num_pow_int(const T &base, unsigned e)
Integer power, valid in any field (no transcendental requirement).
Definition number.h:204
Number-type abstraction for the templated API port.
Exact mean response time of the M/G/1 queue (Pollaczek-Khinchine).
Shared return type and arithmetic helpers for the templated qsys port.
Return value of the qsys family, mirroring MATLAB's [W,rhohat] and the JAR's Ret.qsys.
Definition qsys_types.h:38