LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
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
33
#include "
line/api/qsys/qsys_retrial_policy.h
"
34
#include "
line/num/number.h
"
35
#include "
line/util/error.h
"
36
37
namespace
line
{
38
namespace
qsys
{
39
40
/** The optional `res` struct of qsys_mg11_retrial. */
41
template
<
class
T>
42
struct
Mg11RetrialRes
{
43
T
meanQueueLength
;
44
T
meanOrbitLength
;
45
T
meanResponseTime
;
46
T
meanOrbitTime
;
47
T
utilization
;
48
T
probIdle
;
49
T
probBlock
;
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)
54
T
throughput
;
55
RetrialPolicy
policy
=
RetrialPolicy::LINEAR
;
56
};
57
58
/** The outputs [N, Norb, R, U, res] of qsys_mg11_retrial. */
59
template
<
class
T>
60
struct
Mg11RetrialResult
{
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
65
Mg11RetrialRes<T>
res
;
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
*/
75
template
<
class
T>
76
Mg11RetrialResult<T>
qsys_mg11_retrial
(
const
T& lambda,
const
T& mu,
const
T& cs,
const
T& nu,
77
RetrialPolicy
policy =
RetrialPolicy::LINEAR
) {
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));
85
Mg11RetrialResult<T>
out;
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
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:105
error.h
The exception types the port throws.
line::qsys
Definition
qsys_bmapm1.h:58
line::qsys::RetrialPolicy
RetrialPolicy
Retrial admission policy (RetrialPolicy in MATLAB).
Definition
qsys_retrial_policy.h:18
line::qsys::RetrialPolicy::LINEAR
@ LINEAR
each orbiting customer retries at rate alpha (orbit rate i*alpha)
Definition
qsys_retrial_policy.h:19
line::qsys::qsys_mg11_retrial
Mg11RetrialResult< T > qsys_mg11_retrial(const T &lambda, const T &mu, const T &cs, const T &nu, RetrialPolicy policy=RetrialPolicy::LINEAR)
Definition
qsys_mg11_retrial.h:76
line
Conservation laws of a layered queueing network, enumerated from its structure.
Definition
aoi_dist2ph.h:51
number.h
Number-type abstraction for the templated API port.
qsys_retrial_policy.h
The retrial policy shared by the qsys retrial functions (MATLAB RetrialPolicy).
line::ErrorKind::ErrorKind
ErrorKind(std::string n)
Definition
error.h:39
line::num_traits
Definition
number.h:123
line::qsys::Mg11RetrialRes
The optional res struct of qsys_mg11_retrial.
Definition
qsys_mg11_retrial.h:42
line::qsys::Mg11RetrialRes::hasProbEmpty
bool hasProbEmpty
false under LINEAR (MATLAB NaN)
Definition
qsys_mg11_retrial.h:52
line::qsys::Mg11RetrialRes::probBlock
T probBlock
Definition
qsys_mg11_retrial.h:49
line::qsys::Mg11RetrialRes::throughput
T throughput
Definition
qsys_mg11_retrial.h:54
line::qsys::Mg11RetrialRes::utilization
T utilization
Definition
qsys_mg11_retrial.h:47
line::qsys::Mg11RetrialRes::meanResponseTime
T meanResponseTime
Definition
qsys_mg11_retrial.h:45
line::qsys::Mg11RetrialRes::probEmpty
T probEmpty
P(N = 0) = 1 - rho/a (CONSTANT only).
Definition
qsys_mg11_retrial.h:53
line::qsys::Mg11RetrialRes::meanOrbitTime
T meanOrbitTime
Definition
qsys_mg11_retrial.h:46
line::qsys::Mg11RetrialRes::probIdle
T probIdle
Definition
qsys_mg11_retrial.h:48
line::qsys::Mg11RetrialRes::meanOrbitLength
T meanOrbitLength
Definition
qsys_mg11_retrial.h:44
line::qsys::Mg11RetrialRes::meanRetrials
T meanRetrials
mean retrials per customer (LINEAR only)
Definition
qsys_mg11_retrial.h:51
line::qsys::Mg11RetrialRes::hasMeanRetrials
bool hasMeanRetrials
false under CONSTANT (MATLAB NaN)
Definition
qsys_mg11_retrial.h:50
line::qsys::Mg11RetrialRes::meanQueueLength
T meanQueueLength
Definition
qsys_mg11_retrial.h:43
line::qsys::Mg11RetrialRes::policy
RetrialPolicy policy
Definition
qsys_mg11_retrial.h:55
line::qsys::Mg11RetrialResult
The outputs [N, Norb, R, U, res] of qsys_mg11_retrial.
Definition
qsys_mg11_retrial.h:60
line::qsys::Mg11RetrialResult::res
Mg11RetrialRes< T > res
Definition
qsys_mg11_retrial.h:65
line::qsys::Mg11RetrialResult::N
T N
mean number in system (orbit + service)
Definition
qsys_mg11_retrial.h:61
line::qsys::Mg11RetrialResult::U
T U
server utilization
Definition
qsys_mg11_retrial.h:64
line::qsys::Mg11RetrialResult::Norb
T Norb
mean orbit size
Definition
qsys_mg11_retrial.h:62
line::qsys::Mg11RetrialResult::R
T R
mean response time
Definition
qsys_mg11_retrial.h:63
include
line
api
qsys
qsys_mg11_retrial.h
Generated by
1.18.0