LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
aoi_fcfs_md1.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_MD1_H
6#define LINE_API_AOI_FCFS_MD1_H
7
8/**
9 * @file
10 * @ingroup api_aoi
11 * Mean, variance and peak Age of Information of an M/D/1 FCFS queue.
12 *
13 * Templated port of matlab/src/api/aoi/aoi_fcfs_md1.m, cross-checked against
14 * jar/src/main/java/jline/api/aoi/Aoi_fcfs_md1.java (identical).
15 *
16 * rho = lambda d, E[W] = lambda d^2 / (2(1-rho)), E[T] = E[W] + d
17 * E[A] = d (1/2 + 1/(2(1-rho)) + ((1-rho)/rho) exp(rho))
18 * E[Apeak] = E[T] + 1/lambda
19 * Var[A] = 1/lambda^2 + 2 E[W] d/(1-rho) + d^2 rho/(1-rho)^2
20 *
21 * from Inoue et al. (2019). The exp(rho) in the mean is what carries the
22 * negative correlation between the interarrival time and the waiting time.
23 *
24 * static_assert(num_traits<T>::has_transcendental) -- the single exp(rho).
25 * Everything else in the file is rational; a caller who wants the exact
26 * peak AoI and variance can get them from the M/GI/1 route with an Erlang
27 * approximating the constant.
28 *
29 * The variance is documented in the MATLAB source as an approximation, not the
30 * exact second moment: it is assembled from E[Y^2] - E[Y]^2 plus two waiting-
31 * time terms, not from the AoI transform. Treat it as such.
32 */
33
35#include "line/num/number.h"
36
37namespace line {
38namespace aoi {
39
40/**
41 * @brief Mean, variance and peak Age of Information of an M/D/1 FCFS queue.
42 *
43 * @param lambda arrival rate, > 0
44 * @param d deterministic service time, > 0
45 * @return [meanAoI, varAoI, peakAoI]
46 */
47template <class T>
48AoiResult<T> aoi_fcfs_md1(const T& lambda, const T& d) {
50 "aoi_fcfs_md1 requires transcendental arithmetic");
51 detail::require_positive(lambda, "aoi_fcfs_md1", "the arrival rate lambda");
52 detail::require_positive(d, "aoi_fcfs_md1", "the service time d");
53 const T one = num_traits<T>::from_int(1), two = num_traits<T>::from_int(2);
54 const T rho = lambda * d;
55 detail::require_stable(rho, "aoi_fcfs_md1");
56
57 const T E_H = d, E_H2 = d * d;
58 const T E_W = lambda * E_H2 / (two * (one - rho));
59 const T E_T = E_W + E_H;
60 const T E_Y = one / lambda;
61 const T E_Y2 = two / (lambda * lambda);
62
63 const T meanAoI = d * (num_traits<T>::from_rational(1, 2) + one / (two * (one - rho)) +
64 ((one - rho) / rho) * detail::num_exp(rho));
65 const T peakAoI = E_T + E_Y;
66
67 T varAoI = E_Y2 - E_Y * E_Y + two * E_W * E_H / (one - rho) +
68 E_H2 * rho / ((one - rho) * (one - rho));
69 if (varAoI < num_traits<T>::from_int(0)) varAoI = num_traits<T>::from_int(0);
70 return {meanAoI, varAoI, peakAoI};
71}
72
73} // namespace aoi
74} // namespace line
75
76#endif // LINE_API_AOI_FCFS_MD1_H
Shared return types and arithmetic helpers for the templated Age of Information port.
AoiResult< T > aoi_fcfs_md1(const T &lambda, const T &d)
Mean, variance and peak Age of Information of an M/D/1 FCFS queue.
Number-type abstraction for the templated API port.
[meanAoI, varAoI, peakAoI], mirroring jline.api.aoi.AoiResult.
Definition aoi_types.h:45