LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
qsys_mg11_retrial.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_MG11_RETRIAL_H
6#define LINE_API_QSYS_QSYS_MG11_RETRIAL_H
7
8/**
9 * @file
10 * @ingroup api_qsys
11 * Exact mean measures of the single-class M/G/1/1 retrial queue.
12 *
13 * Port of matlab/src/api/qsys/qsys_mg11_retrial.m. Poisson arrivals of rate
14 * lambda find the single server busy with probability rho = lambda/mu and
15 * then join an orbit, from which they retry after an exponential delay.
16 * Under LINEAR each orbiting customer retries at rate nu; under CONSTANT the
17 * orbit as a whole retries at rate nu. The service time has mean 1/mu and
18 * squared coefficient of variation cs^2, so b2 = (1+cs^2)/mu^2.
19 *
20 * LINEAR (Falin and Templeton 1997, Sec. 1.3), stable iff rho < 1:
21 * Norb = lambda^2 b2 / (2(1-rho)) + lambda rho / (nu (1-rho))
22 * CONSTANT (Fayolle 1986; Choi, Shin and Ahn 1992), a = nu/(lambda+nu),
23 * stable iff rho < a:
24 * Norb = (rho(1-rho) + lambda^2 b2 / 2) / (a - rho) - rho
25 *
26 * N = Norb + rho, R = N/lambda (Little), U = rho. An unstable queue raises
27 * LINE:input:Unstable. Every operation is rational, so the function is valid
28 * for any LINE number type.
29 */
30
31#include <string>
32
34#include "line/num/number.h"
35#include "line/util/error.h"
36
37namespace line {
38namespace qsys {
39
40/** The optional `res` struct of qsys_mg11_retrial. */
41template <class T>
50 bool hasMeanRetrials = false; ///< false under CONSTANT (MATLAB NaN)
51 T meanRetrials; ///< mean retrials per customer (LINEAR only)
52 bool hasProbEmpty = false; ///< false under LINEAR (MATLAB NaN)
53 T probEmpty; ///< P(N = 0) = 1 - rho/a (CONSTANT only)
56};
57
58/** The outputs [N, Norb, R, U, res] of qsys_mg11_retrial. */
59template <class T>
61 T N; ///< mean number in system (orbit + service)
62 T Norb; ///< mean orbit size
63 T R; ///< mean response time
64 T U; ///< server utilization
66};
67
68/**
69 * @param lambda arrival rate (> 0)
70 * @param mu service rate (> 0)
71 * @param cs coefficient of variation of the service time (>= 0)
72 * @param nu retrial rate (> 0)
73 * @param policy LINEAR (default) or CONSTANT
74 */
75template <class T>
76Mg11RetrialResult<T> qsys_mg11_retrial(const T& lambda, const T& mu, const T& cs, const T& nu,
78 const T zero = num_traits<T>::from_int(0);
79 const T one = num_traits<T>::from_int(1);
80 const T two = num_traits<T>::from_int(2);
81 if (!(lambda > zero) || !(mu > zero) || cs < zero || !(nu > zero))
82 throw InputError("qsys_mg11_retrial: Rates must be positive and the coefficient of variation non-negative.");
83 const T rho = lambda / mu;
84 const T b2 = T((one + cs * cs) / (mu * mu));
86 if (policy == RetrialPolicy::LINEAR) {
87 if (!(rho < one))
88 throw InputError(ErrorKind("Unstable"),
89 "qsys_mg11_retrial: unstable retrial queue: rho = " +
90 std::to_string(num_traits<T>::to_double(rho)) + " >= 1");
91 out.Norb = T(lambda * lambda * b2 / (two * (one - rho)) + lambda * rho / (nu * (one - rho)));
92 } else {
93 const T a = T(nu / (lambda + nu));
94 if (!(rho < a))
95 throw InputError(ErrorKind("Unstable"),
96 "qsys_mg11_retrial: unstable retrial queue: rho = " +
97 std::to_string(num_traits<T>::to_double(rho)) + " >= nu/(lambda+nu) = " +
98 std::to_string(num_traits<T>::to_double(a)));
99 out.Norb = T((rho * (one - rho) + lambda * lambda * b2 / two) / (a - rho) - rho);
100 }
101 out.U = rho;
102 out.N = T(out.Norb + rho);
103 out.R = T(out.N / lambda);
104
105 Mg11RetrialRes<T>& r = out.res;
106 r.meanQueueLength = out.N;
107 r.meanOrbitLength = out.Norb;
108 r.meanResponseTime = out.R;
109 r.meanOrbitTime = T(out.Norb / lambda);
110 r.utilization = out.U;
111 r.probIdle = T(one - rho);
112 r.probBlock = rho;
113 r.policy = policy;
114 r.throughput = lambda;
115 if (policy == RetrialPolicy::LINEAR) {
116 T m = T(nu * out.Norb - lambda * rho);
117 if (m < zero) m = zero;
118 r.hasMeanRetrials = true;
119 r.meanRetrials = T(m / lambda);
120 } else {
121 r.hasProbEmpty = true;
122 r.probEmpty = T(one - rho * (lambda + nu) / nu);
123 }
124 return out;
125}
126
127} // namespace qsys
128} // namespace line
129
130#endif // LINE_API_QSYS_QSYS_MG11_RETRIAL_H
InputError(const std::string &what)
Definition error.h:105
The exception types the port throws.
RetrialPolicy
Retrial admission policy (RetrialPolicy in MATLAB).
@ LINEAR
each orbiting customer retries at rate alpha (orbit rate i*alpha)
Mg11RetrialResult< T > qsys_mg11_retrial(const T &lambda, const T &mu, const T &cs, const T &nu, RetrialPolicy policy=RetrialPolicy::LINEAR)
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Number-type abstraction for the templated API port.
The retrial policy shared by the qsys retrial functions (MATLAB RetrialPolicy).
ErrorKind(std::string n)
Definition error.h:39
The optional res struct of qsys_mg11_retrial.
bool hasProbEmpty
false under LINEAR (MATLAB NaN)
T probEmpty
P(N = 0) = 1 - rho/a (CONSTANT only).
T meanRetrials
mean retrials per customer (LINEAR only)
bool hasMeanRetrials
false under CONSTANT (MATLAB NaN)
The outputs [N, Norb, R, U, res] of qsys_mg11_retrial.
T N
mean number in system (orbit + service)