LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
aoi_fcfs_mm1.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_AOI_FCFS_MM1_H
6#define LINE_API_AOI_FCFS_MM1_H
7
8/**
9 * @file
10 * @ingroup api_aoi
11 * Mean, variance and peak Age of Information of an M/M/1 FCFS queue.
12 *
13 * Templated port of matlab/src/api/aoi/aoi_fcfs_mm1.m, cross-checked against
14 * jar/src/main/java/jline/api/aoi/Aoi_fcfs_mm1.java (identical).
15 *
16 * E[A] = (1/mu)(1 + 1/rho + rho^2/(1-rho))
17 * E[Apeak] = (1/mu)(1 + 1/rho + rho/(1-rho))
18 * E[A^2] = (2/mu^2)(1 - rho - rho^3 + 4 rho^4 - 2 rho^5)/(rho^2 (1-rho)^2)
19 * Var[A] = E[A^2] - E[A]^2
20 *
21 * from Inoue, Masuyama, Takine and Tanaka (IEEE Trans. IT 65(12), 2019).
22 * Every quantity is a rational function of rho, so the triple is exact in the
23 * field. This is the reference AoI closed form: E[A] has an interior minimum
24 * in rho near 0.53, and the exact instantiation locates it as the root of a
25 * polynomial rather than by a rounded search.
26 *
27 * MATLAB clamps a negative variance to zero as a numerical safety net; the
28 * port keeps the clamp so the two agree, but note that in exact arithmetic the
29 * clamp can never fire, because E[A^2] - E[A]^2 is then evaluated without
30 * cancellation error.
31 */
32
34#include "line/num/number.h"
35
36namespace line {
37namespace aoi {
38
39/**
40 * @brief Mean, variance and peak Age of Information of an M/M/1 FCFS queue.
41 *
42 * @param lambda arrival rate, > 0
43 * @param mu service rate, > 0
44 * @return [meanAoI, varAoI, peakAoI]
45 */
46template <class T>
47AoiResult<T> aoi_fcfs_mm1(const T& lambda, const T& mu) {
48 detail::require_positive(lambda, "aoi_fcfs_mm1", "the arrival rate lambda");
49 detail::require_positive(mu, "aoi_fcfs_mm1", "the service rate mu");
50 const T one = num_traits<T>::from_int(1), two = num_traits<T>::from_int(2);
51 const T rho = lambda / mu;
52 detail::require_stable(rho, "aoi_fcfs_mm1");
53
54 const T meanAoI = (one / mu) * (one + one / rho + rho * rho / (one - rho));
55 const T peakAoI = (one / mu) * (one + one / rho + rho / (one - rho));
56
57 const T r2 = rho * rho, r3 = r2 * rho, r4 = r3 * rho, r5 = r4 * rho;
58 const T E_A2 = (two / (mu * mu)) * (one - rho - r3 + num_traits<T>::from_int(4) * r4 - two * r5) /
59 (r2 * (one - rho) * (one - rho));
60 T varAoI = E_A2 - meanAoI * meanAoI;
61 if (varAoI < num_traits<T>::from_int(0)) varAoI = num_traits<T>::from_int(0);
62 return {meanAoI, varAoI, peakAoI};
63}
64
65} // namespace aoi
66} // namespace line
67
68#endif // LINE_API_AOI_FCFS_MM1_H
Shared return types and arithmetic helpers for the templated Age of Information port.
AoiResult< T > aoi_fcfs_mm1(const T &lambda, const T &mu)
Mean, variance and peak Age of Information of an M/M/1 FCFS queue.
Number-type abstraction for the templated API port.
[meanAoI, varAoI, peakAoI], mirroring jline.api.aoi.AoiResult.
Definition aoi_types.h:45