LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
qsys_gigk_approx_cosmetatos.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_GIGK_APPROX_COSMETATOS_H
6
#define LINE_API_QSYS_GIGK_APPROX_COSMETATOS_H
7
8
/**
9
* @file
10
* @ingroup api_qsys
11
* Cosmetatos / Page interpolation approximation for the GI/G/k queue.
12
*
13
* Templated port of matlab/src/api/qsys/qsys_gigk_approx_cosmetatos.m.
14
*
15
* gamma = min(0.24, (1-rho)(k-1)(sqrt(4+5k)-2)/(16 k rho))
16
* phi1 = 1 + gamma (M/D/k factor)
17
* phi3 = (1-4 gamma) exp(-2(1-rho)/(3 rho)) (D/M/k factor)
18
* Wq = [ca^2 cs^2 + ca^2(1-cs^2) phi1/2 + (1-ca^2) cs^2 phi3/2] Wq(M/M/k)
19
*
20
* for ca^2 <= 1 and cs^2 <= 1; outside the unit box the Lee-Longton scaling
21
* Wq = ((ca^2+cs^2)/2) Wq(M/M/k) is used instead. W = Wq + 1/mu.
22
*
23
* DIVERGENCE: jar/.../Qsys_gigk_approx_cosmetatos.java names its arguments
24
* ca2 and cs2 and uses them unsquared, i.e. it expects squared coefficients of
25
* variation, whereas MATLAB takes ca, cs and squares them internally. MATLAB
26
* is ground truth, so this port takes ca, cs. The JAR also returns
27
* {L,W,Q,U} instead of [W,rhohat]; W agrees once the argument convention is
28
* matched.
29
*
30
* References: Cosmetatos (1975) INFOR 13, 328-331; Page (1982) J. Opl. Res.
31
* Soc. 33, 453-473; Whitt (1993) eq. (2.17) for the gamma safeguard.
32
*
33
* Carries sqrt and exp, so it requires transcendental arithmetic and cannot
34
* be instantiated at T = Rational.
35
*/
36
37
#include "
line/api/qsys/qsys_mmk.h
"
38
#include "
line/api/qsys/qsys_types.h
"
39
#include "
line/num/number.h
"
40
41
namespace
line
{
42
namespace
qsys
{
43
44
/**
45
* @brief Cosmetatos / Page interpolation approximation for the GI/G/k queue.
46
*
47
* @param lambda arrival rate
48
* @param mu service rate of a single server
49
* @param ca coefficient of variation of the interarrival time
50
* @param cs coefficient of variation of the service time
51
* @param k number of servers, k >= 1
52
*/
53
template
<
class
T>
54
QsysResult<T>
qsys_gigk_approx_cosmetatos
(
const
T& lambda,
const
T& mu,
const
T& ca,
const
T& cs,
55
unsigned
k) {
56
static_assert
(
num_traits<T>::has_transcendental
,
57
"qsys_gigk_approx_cosmetatos requires transcendental arithmetic"
);
58
const
T one =
num_traits<T>::from_int
(1);
59
const
T two =
num_traits<T>::from_int
(2);
60
const
T three =
num_traits<T>::from_int
(3);
61
const
T four =
num_traits<T>::from_int
(4);
62
const
T kT =
num_traits<T>::from_int
(
static_cast<
long
>
(k));
63
const
T ca2 =
num_pow_int
(ca, 2);
64
const
T cs2 =
num_pow_int
(cs, 2);
65
const
T rho = lambda / (kT * mu);
66
67
const
T Wq_mmk =
qsys_mmk
(lambda, mu, k).W - one / mu;
68
69
T Wq;
70
if
(ca2 <= one && cs2 <= one) {
71
const
T gamma = detail::num_min(
72
num_traits<T>::from_rational
(6, 25),
73
(one - rho) * (kT - one) *
74
(detail::num_sqrt(T(four +
num_traits<T>::from_int
(5) * kT)) - two) /
75
(
num_traits<T>::from_int
(16) * kT * rho));
76
const
T phi1 = one + gamma;
77
const
T phi3 = (one - four * gamma) * detail::num_exp(T(-two * (one - rho) / (three * rho)));
78
Wq = (ca2 * cs2 + ca2 * (one - cs2) * phi1 / two + (one - ca2) * cs2 * phi3 / two) * Wq_mmk;
79
}
else
{
80
Wq = ((ca2 + cs2) / two) * Wq_mmk;
81
}
82
const
T W = Wq + one / mu;
83
return
{W, detail::rhohat_from_W(W, lambda)};
84
}
85
86
}
// namespace qsys
87
}
// namespace line
88
89
#endif
// LINE_API_QSYS_GIGK_APPROX_COSMETATOS_H
line::qsys
Definition
qsys_bmapm1.h:58
line::qsys::qsys_gigk_approx_cosmetatos
QsysResult< T > qsys_gigk_approx_cosmetatos(const T &lambda, const T &mu, const T &ca, const T &cs, unsigned k)
Cosmetatos / Page interpolation approximation for the GI/G/k queue.
Definition
qsys_gigk_approx_cosmetatos.h:54
line::qsys::qsys_mmk
QsysResult< T > qsys_mmk(const T &lambda, const T &mu, unsigned k)
Exact mean response time of the M/M/k queue (Erlang-C).
Definition
qsys_mmk.h:60
line
Definition
aoi_dist2ph.h:52
line::num_pow_int
T num_pow_int(const T &base, unsigned e)
Integer power, valid in any field (no transcendental requirement).
Definition
number.h:192
number.h
Number-type abstraction for the templated API port.
qsys_mmk.h
Exact mean response time of the M/M/k queue (Erlang-C).
qsys_types.h
Shared return type and arithmetic helpers for the templated qsys port.
line::num_traits
Definition
number.h:111
line::qsys::QsysResult
Return value of the qsys family, mirroring MATLAB's [W,rhohat] and the JAR's Ret.qsys.
Definition
qsys_types.h:37
include
line
api
qsys
qsys_gigk_approx_cosmetatos.h
Generated by
1.18.0