LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
qsys_mg1.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_MG1_H
6
#define LINE_API_QSYS_MG1_H
7
8
/**
9
* @file
10
* @ingroup api_qsys
11
* Exact mean response time of the M/G/1 queue (Pollaczek-Khinchine).
12
*
13
* Templated port of matlab/src/api/qsys/qsys_mg1.m, cross-checked against
14
* jar/src/main/java/jline/api/qsys/Qsys_mg1.java (identical).
15
*
16
* rho = lambda/mu
17
* Q = rho + rho^2/(2(1-rho)) + lambda^2 cs^2 / mu^2 / (2(1-rho))
18
* W = Q/lambda, rhohat = Q/(1+Q)
19
*
20
* Only integer powers appear, so the function is exact for T = Rational.
21
* Note that cs is the coefficient of variation, squared inside the formula.
22
*/
23
24
#include "
line/api/qsys/qsys_res.h
"
25
#include "
line/api/qsys/qsys_types.h
"
26
#include "
line/num/number.h
"
27
28
namespace
line
{
29
namespace
qsys
{
30
31
/**
32
* @brief Exact mean response time of the M/G/1 queue (Pollaczek-Khinchine).
33
*
34
* @param lambda arrival rate
35
* @param mu service rate
36
* @param cs coefficient of variation of the service time
37
* @return W = mean response time, rhohat = Q/(1+Q)
38
*/
39
template
<
class
T>
40
QsysResult<T>
qsys_mg1
(
const
T& lambda,
const
T& mu,
const
T& cs) {
41
const
T one =
num_traits<T>::from_int
(1);
42
const
T two =
num_traits<T>::from_int
(2);
43
const
T rho = lambda / mu;
44
if
(detail::saturated(rho,
"qsys_mg1"
))
return
{detail::num_inf<T>(), one};
45
const
T Q = rho +
num_pow_int
(rho, 2) / (two * (one - rho)) +
46
num_pow_int
(lambda, 2) *
num_pow_int
(cs, 2) /
num_pow_int
(mu, 2) /
47
(two * (one - rho));
48
const
T W = Q / lambda;
49
return
{W, Q / (one + Q)};
50
}
51
52
/**
53
* @brief The `res` output of qsys_mg1 (Pollaczek-Khinchine and Takacs).
54
*
55
* Port of the `nargout > 2` branch of matlab/src/api/qsys/qsys_mg1.m. The
56
* variances need the third service moment and are set only when `ES3` is
57
* given (pass a negative value for MATLAB's []). Refuses an unstable queue with
58
* `LINE:input:Unstable`.
59
*/
60
inline
QsysRes
qsys_mg1_res
(
double
lambda,
double
mu,
double
cs,
double
ES3 = -1.0) {
61
using namespace
resdetail
;
62
const
double
rho = lambda / mu;
63
require_stable(rho,
"qsys_mg1"
);
64
const
double
ES = 1.0 / mu;
65
const
double
ES2 = (1.0 + cs * cs) / (mu * mu);
66
const
double
EW = lambda * ES2 / (2.0 * (1.0 - rho));
67
QsysRes
res;
68
res.
set
(
"meanQueueLength"
, lambda * EW + rho);
69
res.
set
(
"meanQueueLengthQ"
, lambda * EW);
70
res.
set
(
"meanWaitingTime"
, EW);
71
res.
set
(
"meanSojournTime"
, EW + ES);
72
res.
set
(
"probWait"
, rho);
73
res.
set
(
"condMeanWaitingTime"
, EW / rho);
74
res.
set
(
"throughput"
, lambda);
75
res.
set
(
"utilization"
, rho);
76
if
(ES3 >= 0.0) {
77
const
double
t3 = lambda * ES3 / (3.0 * (1.0 - rho));
78
const
double
VW = t3 + lambda * lambda * ES2 * ES2 / (4.0 * std::pow(1.0 - rho, 2));
79
const
double
h = lambda * lambda * ES2 / (2.0 * (1.0 - rho));
80
res.
set
(
"varWaitingTime"
, VW);
81
res.
set
(
"varSojournTime"
, VW + ES2 - ES * ES);
82
res.
set
(
"varQueueLengthQ"
, lambda * lambda * t3 + h * h + h);
83
res.
set
(
"varQueueLength"
, lambda * lambda * t3 + h * h +
84
lambda * lambda * (3.0 - 2.0 * rho) * ES2 / (2.0 * (1.0 - rho)) +
85
rho * (1.0 - rho));
86
}
87
res.
analyzer
=
"exact:M/G/1"
;
88
return
res;
89
}
90
91
}
// namespace qsys
92
}
// namespace line
93
94
#endif
// LINE_API_QSYS_MG1_H
line::qsys::resdetail
Definition
qsys_res.h:108
line::qsys
Definition
qsys_bmapm1.h:58
line::qsys::qsys_mg1_res
QsysRes qsys_mg1_res(double lambda, double mu, double cs, double ES3=-1.0)
The res output of qsys_mg1 (Pollaczek-Khinchine and Takacs).
Definition
qsys_mg1.h:60
line::qsys::qsys_mg1
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
line::qsys::QsysRes
QsysResT< double > QsysRes
Definition
qsys_res.h:96
line
Conservation laws of a layered queueing network, enumerated from its structure.
Definition
aoi_dist2ph.h:51
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:204
number.h
Number-type abstraction for the templated API port.
qsys_res.h
The res struct the exact queueing-system functions return, and the numeric helpers those functions sh...
qsys_types.h
Shared return type and arithmetic helpers for the templated qsys port.
line::num_traits
Definition
number.h:123
line::qsys::QsysResT::analyzer
std::string analyzer
Definition
qsys_res.h:59
line::qsys::QsysResT::set
void set(const std::string &name, const T &v)
Sets (or overwrites) a scalar field.
Definition
qsys_res.h:62
line::qsys::QsysResult
Return value of the qsys family, mirroring MATLAB's [W,rhohat] and the JAR's Ret.qsys.
Definition
qsys_types.h:38
include
line
api
qsys
qsys_mg1.h
Generated by
1.18.0