LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
qsys_mginf.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_MGINF_H
6#define LINE_API_QSYS_MGINF_H
7
8/**
9 * @file
10 * @ingroup api_qsys
11 * Exact solution of the M/G/infinity queue.
12 *
13 * Templated port of matlab/src/api/qsys/qsys_mginf.m, cross-checked against
14 * jar/src/main/java/jline/api/qsys/Qsys_mginf.java. The JAR carries an extra
15 * cv2 argument that it never reads, and returns a HashMap rather than a tuple;
16 * the numbers are identical.
17 *
18 * L = rho, Lq = 0, W = 1/mu, Wq = 0, p0 = exp(-rho)
19 * pk = exp(-rho) rho^k / k!
20 *
21 * The number in system is Poisson(rho), so p0 and pk carry exp(-rho). That is
22 * a genuine transcendental: the function therefore requires
23 * num_traits<T>::has_transcendental and cannot be instantiated at exact
24 * arithmetic. L, Lq, W and Wq are field values, but they are not separable
25 * from the struct, so the whole function is gated.
26 */
27
29#include "line/num/number.h"
30
31namespace line {
32namespace qsys {
33
34/** Return value of qsys_mginf, mirroring MATLAB's [L,Lq,W,Wq,p0,pk]. */
35template <class T>
37 T L; ///< mean number in system
38 T Lq; ///< mean number queueing, always 0
39 T W; ///< mean response time, always 1/mu
40 T Wq; ///< mean waiting time, always 0
41 T p0; ///< probability of an empty system
42 T pk; ///< probability of exactly k in system, valid iff has_pk
43 bool has_pk; ///< true when the k overload was called
44};
45
46/**
47 * @brief Exact solution of the M/G/infinity queue.
48 *
49 * @param lambda arrival rate
50 * @param mu service rate, mean service time 1/mu
51 */
52template <class T>
53MginfResult<T> qsys_mginf(const T& lambda, const T& mu) {
55 "qsys_mginf requires transcendental arithmetic");
56 const T zero = num_traits<T>::from_int(0);
57 const T one = num_traits<T>::from_int(1);
58 const T rho = lambda / mu;
60 r.L = rho;
61 r.Lq = zero;
62 r.W = one / mu;
63 r.Wq = zero;
64 r.p0 = detail::num_exp(T(-rho));
65 r.pk = zero;
66 r.has_pk = false;
67 return r;
68}
69
70/**
71 * @brief Exact solution of the M/G/infinity queue.
72 *
73 * @param k state whose probability is additionally returned
74 * @param lambda arrival rate
75 * @param mu service rate
76 */
77template <class T>
78MginfResult<T> qsys_mginf(const T& lambda, const T& mu, unsigned k) {
80 "qsys_mginf requires transcendental arithmetic");
81 MginfResult<T> r = qsys_mginf(lambda, mu);
82 const T rho = lambda / mu;
83 r.pk = detail::num_exp(T(-rho)) * num_pow_int(rho, k) / num_factorial<T>(k);
84 r.has_pk = true;
85 return r;
86}
87
88} // namespace qsys
89} // namespace line
90
91#endif // LINE_API_QSYS_MGINF_H
MginfResult< T > qsys_mginf(const T &lambda, const T &mu)
Exact solution of the M/G/infinity queue.
Definition qsys_mginf.h:53
T num_factorial(unsigned n)
Factorial as a value of T.
Definition number.h:184
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 qsys_mginf, mirroring MATLAB's [L,Lq,W,Wq,p0,pk].
Definition qsys_mginf.h:36
T W
mean response time, always 1/mu
Definition qsys_mginf.h:39
T p0
probability of an empty system
Definition qsys_mginf.h:41
bool has_pk
true when the k overload was called
Definition qsys_mginf.h:43
T Wq
mean waiting time, always 0
Definition qsys_mginf.h:40
T L
mean number in system
Definition qsys_mginf.h:37
T pk
probability of exactly k in system, valid iff has_pk
Definition qsys_mginf.h:42
T Lq
mean number queueing, always 0
Definition qsys_mginf.h:38