LINE Solver (C++)
Templated C++ port of the LINE queueing solver
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
25#include "line/num/number.h"
26
27namespace line {
28namespace qsys {
29
30/**
31 * @brief Exact mean response time of the M/G/1 queue (Pollaczek-Khinchine).
32 *
33 * @param lambda arrival rate
34 * @param mu service rate
35 * @param cs coefficient of variation of the service time
36 * @return W = mean response time, rhohat = Q/(1+Q)
37 */
38template <class T>
39QsysResult<T> qsys_mg1(const T& lambda, const T& mu, const T& cs) {
40 const T one = num_traits<T>::from_int(1);
41 const T two = num_traits<T>::from_int(2);
42 const T rho = lambda / mu;
43 detail::require_no_pole(T(one - rho), "qsys_mg1");
44 const T Q = rho + num_pow_int(rho, 2) / (two * (one - rho)) +
45 num_pow_int(lambda, 2) * num_pow_int(cs, 2) / num_pow_int(mu, 2) /
46 (two * (one - rho));
47 const T W = Q / lambda;
48 return {W, Q / (one + Q)};
49}
50
51} // namespace qsys
52} // namespace line
53
54#endif // LINE_API_QSYS_MG1_H
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:39
T num_pow_int(const T &base, unsigned e)
Integer power, valid in any field (no transcendental requirement).
Definition number.h:192
Number-type abstraction for the templated API port.
Shared return type and arithmetic helpers for the templated qsys port.
Return value of the qsys family, mirroring MATLAB's [W,rhohat] and the JAR's Ret.qsys.
Definition qsys_types.h:37