LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
qsys_gigk_rqt.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_GIGK_RQT_H
6#define LINE_API_QSYS_QSYS_GIGK_RQT_H
7
8/**
9 * @file
10 * @ingroup api_qsys
11 * Robust Queueing Theory (RQT) worst-case system time of a G/G/k FCFS queue.
12 *
13 * Templated port of matlab/src/api/qsys/qsys_gigk_rqt.m, cross-checked against
14 * jar/src/main/java/jline/api/qsys/Qsys_gigk_rqt.java.
15 *
16 * The arrival and service processes are not described by distributions but by
17 * the polyhedral uncertainty sets
18 *
19 * U^a = { T : (sum_{i=k+1}^n T_i - (n-k)/lambda)/(n-k)^(1/alpha_a) >= -Gamma_a }
20 * U^s = { X : (sum_{i=k}^n X_i - (n-k+1)/mu)/(n-k+1)^(1/alpha_s) <= Gamma_s }
21 *
22 * whose shape follows the (generalized) central limit theorem: alpha = 2 is the
23 * finite-variance regime, alpha in (1,2) the heavy-tailed one. Performance
24 * analysis is then a worst-case optimization rather than an expectation.
25 *
26 * W is the closed-form bound of Theorem 3 (Theorem 8 when the two tails differ,
27 * with ab = min(alpha_a,alpha_s)),
28 *
29 * W <= (ab-1)/ab^(ab/(ab-1)) lambda^(1/(ab-1))
30 * (Gamma_a + Gamma_s/k^(1/ab))^(ab/(ab-1)) / (1-rho)^(1/(ab-1)) + k/lambda,
31 *
32 * which for k = 1 reduces to Theorem 2 and, at ab = 2, to the Kingman-like form
33 * (lambda/4)(Gamma_a+Gamma_s)^2/(1-rho) + 1/lambda. Sworst is the exact worst
34 * case over the uncertainty sets, eq. (45): the supremum over the integer
35 * x = nu-j+1 >= 1 of
36 *
37 * x/mu + Gamma_s x^(1/alpha_s) - k(x-1)/lambda + Gamma_a (k(x-1))^(1/alpha_a).
38 *
39 * The arrival deviation ADDS to the worst case, since the adversary shortens the
40 * interarrival times; the sign printed in eq. (12) is easily misread as a
41 * subtraction of the whole arrival bracket, and reading it that way puts Sworst
42 * an order of magnitude below W.
43 *
44 * W is a SYSTEM time (waiting plus service), and its additive term is k/lambda
45 * rather than the mean service time 1/mu.
46 *
47 * ARITHMETIC. Real exponents make this transcendental. At rho >= 1 MATLAB
48 * returns W = Sworst = Inf and rhohat = 1, and so does every instantiation with
49 * an IEEE infinity; a type without one raises instead.
50 *
51 * Reference: C. Bandi, D. Bertsimas, N. Youssef (2015). Robust Queueing Theory.
52 * Operations Research 63(3), 676-700.
53 */
54
55#include <cmath>
56#include <cstddef>
57#include <limits>
58#include <vector>
59
61#include "line/num/number.h"
62#include "line/util/error.h"
63
64namespace line {
65namespace qsys {
66
67template <class T>
69 T W; ///< closed-form bound on the system time (Theorem 3 / Theorem 8)
70 T rhohat; ///< modified utilization, so that M/M/1 relations still hold
71 T Sworst; ///< exact worst-case system time over the uncertainty sets
72};
73
74/**
75 * @brief Robust Queueing Theory (RQT) worst-case system time of a G/G/k FCFS
76 * queue.
77 *
78 * @param lambda arrival rate
79 * @param mu service rate of each server
80 * @param Gamma_a variability parameter of the arrival uncertainty set
81 * @param Gamma_s variability parameter of the service uncertainty set
82 * @param k number of servers
83 * @param alpha_a arrival tail coefficient in (1,2]
84 * @param alpha_s service tail coefficient in (1,2]
85 */
86template <class T>
87GigkRqtResult<T> qsys_gigk_rqt(const T& lambda, const T& mu, const T& Gamma_a, const T& Gamma_s,
88 std::size_t k, const T& alpha_a, const T& alpha_s) {
90 "qsys_gigk_rqt requires transcendental arithmetic");
91 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
92 const T kk = num_traits<T>::from_int(static_cast<int>(k));
93 if (alpha_a <= one || alpha_a > T(one + one) || alpha_s <= one || alpha_s > T(one + one))
94 throw InputError("qsys_gigk_rqt: tail coefficients must lie in (1,2]");
95
97 const T rho = lambda / (kk * mu);
98 if (lambda <= zero) {
99 r.W = one / mu;
100 r.rhohat = zero;
101 r.Sworst = one / mu;
102 return r;
103 }
104 if (rho >= one) {
105 if constexpr (std::numeric_limits<T>::has_infinity) {
106 r.W = r.Sworst = std::numeric_limits<T>::infinity();
107 r.rhohat = one;
108 return r;
109 } else {
110 throw InputError("qsys_gigk_rqt: rho >= 1 has an infinite system time, which this type cannot represent");
111 }
112 }
113
114 // Theorem 8 collapses to Theorem 3 when the two tails agree.
115 const T ab = alpha_a < alpha_s ? alpha_a : alpha_s;
116 const T beta = Gamma_a + Gamma_s / detail::num_pow(kk, T(one / ab));
117 if (beta <= zero) {
118 // a nonpositive effective variability leaves only the deterministic term
119 r.W = kk / lambda;
120 } else {
121 const T e = ab / (ab - one);
122 r.W = (ab - one) / detail::num_pow(ab, e) * detail::num_pow(lambda, T(one / (ab - one))) *
123 detail::num_pow(beta, e) / detail::num_pow(T(one - rho), T(one / (ab - one))) +
124 kk / lambda;
125 }
126 r.rhohat = detail::rhohat_from_W(r.W, lambda);
127
128 // Exact worst case, eq. (45), over the integer lattice x >= 1.
129 auto obj = [&](const T& x) -> T {
130 T y = T(x - one);
131 if (y < zero) y = zero;
132 return x / mu + Gamma_s * detail::num_pow(x, T(one / alpha_s)) - kk * y / lambda +
133 Gamma_a * detail::num_pow(T(kk * y), T(one / alpha_a));
134 };
135 // the continuous maximizer of the bounding problem, eq. (16), sizes the scan
136 double xstar = 1.0;
137 if (beta > zero) {
138 const T xs = detail::num_pow(T(lambda * beta / (ab * (one - rho))), T(ab / (ab - one)));
139 xstar = num_traits<T>::to_double(xs);
140 }
141 double xhi = std::max(4.0, std::ceil(4.0 * xstar));
142 if (!(xhi > 0.0) || !std::isfinite(xhi)) xhi = 4.0;
143 const std::size_t NS = 400;
144 std::vector<double> xs;
145 xs.reserve(NS);
146 for (std::size_t i = 0; i < NS; ++i) {
147 const double e = std::log10(xhi) * static_cast<double>(i) / static_cast<double>(NS - 1);
148 const double x = std::max(1.0, std::floor(std::pow(10.0, e) + 0.5));
149 if (xs.empty() || x != xs.back()) xs.push_back(x); // unique(round(logspace(...)))
150 }
151 std::size_t imax = 0;
152 T best = obj(T(num_traits<T>::from_double(xs[0])));
153 for (std::size_t i = 1; i < xs.size(); ++i) {
154 const T v = obj(T(num_traits<T>::from_double(xs[i])));
155 if (v > best) {
156 best = v;
157 imax = i;
158 }
159 }
160 // Refine on the continuous relaxation, then round back onto the lattice.
161 T lo = num_traits<T>::from_double(xs[imax > 0 ? imax - 1 : 0]);
162 T hi = num_traits<T>::from_double(xs[imax + 1 < xs.size() ? imax + 1 : xs.size() - 1]);
163 if (hi > lo) {
164 const T tolx = num_traits<T>::from_double(1e-8);
165 const T invphi = num_traits<T>::from_double(0.6180339887498949);
166 T c = hi - (hi - lo) * invphi;
167 T d = lo + (hi - lo) * invphi;
168 T fc = obj(c), fd = obj(d);
169 for (unsigned it = 0; it < 500u && hi - lo > tolx; ++it) {
170 if (fc > fd) {
171 hi = d;
172 d = c;
173 fd = fc;
174 c = hi - (hi - lo) * invphi;
175 fc = obj(c);
176 } else {
177 lo = c;
178 c = d;
179 fc = fd;
180 d = lo + (hi - lo) * invphi;
181 fd = obj(d);
182 }
183 }
184 const double xc = num_traits<T>::to_double(T((lo + hi) / (one + one)));
185 const double cand[2] = {std::floor(xc), std::ceil(xc)};
186 for (int i = 0; i < 2; ++i) {
187 if (cand[i] >= 1.0) {
188 const T v = obj(T(num_traits<T>::from_double(cand[i])));
189 if (v > best) best = v;
190 }
191 }
192 }
193 r.Sworst = best;
194 return r;
195}
196
197} // namespace qsys
198} // namespace line
199
200#endif // LINE_API_QSYS_QSYS_GIGK_RQT_H
InputError(const std::string &what)
Definition error.h:105
The exception types the port throws.
GigkRqtResult< T > qsys_gigk_rqt(const T &lambda, const T &mu, const T &Gamma_a, const T &Gamma_s, std::size_t k, const T &alpha_a, const T &alpha_s)
Robust Queueing Theory (RQT) worst-case system time of a G/G/k FCFS queue.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Number-type abstraction for the templated API port.
Shared return type and arithmetic helpers for the templated qsys port.
T W
closed-form bound on the system time (Theorem 3 / Theorem 8)
T rhohat
modified utilization, so that M/M/1 relations still hold
T Sworst
exact worst-case system time over the uncertainty sets