LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
aoi_lcfsd_mgi1.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_LCFSD_MGI1_H
6#define LINE_API_AOI_LCFSD_MGI1_H
7
8/**
9 * @file
10 * @ingroup api_aoi
11 * Mean Age of Information, its transform and the peak age of an M/GI/1
12 * non-preemptive LCFS queue with discarding (LCFS-D, equivalently M/GI/1/2*).
13 *
14 * Templated port of matlab/src/api/aoi/aoi_lcfsd_mgi1.m, cross-checked against
15 * jar/src/main/java/jline/api/aoi/Aoi_lcfsd_mgi1.java (identical).
16 *
17 * Exact, Inoue et al. (2019, Section 3.3, NP-LCFS (C)), H* the service LST:
18 *
19 * E[A] = (lambda E[H^2]/2 + H*(lambda)/lambda - H*'(lambda))/(rho + H*(lambda))
20 * + (1 - H*(lambda))/lambda + H*'(lambda) + E[H] (eq. 68)
21 * E[Apeak] = 1/lambda + H*'(lambda) + 2 E[H]
22 * A*(s) = eq. (64)
23 *
24 * Discarding keeps at most one update waiting, so rho >= 1 is accepted.
25 *
26 * static_assert(num_traits<T>::has_transcendental) -- MATLAB's
27 * finite-difference derivative of H* at lambda.
28 */
29
31#include "line/num/number.h"
32#include "line/util/error.h"
33
34namespace line {
35namespace aoi {
36
37/**
38 * @brief Mean Age of Information, its transform and the peak age of an M/GI/1
39 * non-preemptive LCFS queue with discarding (LCFS-D).
40 *
41 * @param lambda arrival rate, > 0
42 * @param H_lst LST of the service time
43 * @param E_H mean service time, > 0
44 * @param E_H2 second raw moment of the service time, >= E_H^2
45 * @return [meanAoI, peakAoI, A*(s)]
46 */
47template <class T>
48AoiLstResult<T> aoi_lcfsd_mgi1(const T& lambda, const Lst<T>& H_lst, const T& E_H, const T& E_H2) {
50 "aoi_lcfsd_mgi1 requires transcendental arithmetic");
51 detail::require_positive(lambda, "aoi_lcfsd_mgi1", "the arrival rate lambda");
52 detail::require_positive(E_H, "aoi_lcfsd_mgi1", "the mean service time E_H");
53 if (!H_lst) throw InputError("aoi_lcfsd_mgi1: the service-time LST must be callable");
54 if (E_H2 < E_H * E_H) throw InputError("aoi_lcfsd_mgi1: E_H2 must be at least E_H^2");
55 const T one = num_traits<T>::from_int(1), two = num_traits<T>::from_int(2);
56 const T rho = lambda * E_H;
57
58 const T hL = H_lst(lambda); // P(no arrival in a service)
59 const T mdH = T(-detail::lst_derivative<T>(H_lst, lambda)); // E[H exp(-lambda H)]
60
61 const T meanAoI = (lambda * E_H2 / two + hL / lambda + mdH) / (rho + hL) +
62 (one - hL) / lambda - mdH + E_H;
63 const T peakAoI = one / lambda - mdH + two * E_H;
64
65 Lst<T> lstAoI = [lambda, H_lst, E_H, rho, hL, one](const T& s) {
66 if (num_traits<T>::to_double(s < T(0) ? T(-s) : s) < 1e-12)
67 return one; // removable singularity of the residual-service LST
68 const T Hs = H_lst(s);
69 const T HsL = H_lst(T(s + lambda));
70 const T hres_s = (one - Hs) / (s * E_H);
71 const T hres_sL = (one - HsL) / ((s + lambda) * E_H);
72 return T((hL + rho * hres_sL) * Hs * (rho * hres_s + HsL * lambda / (s + lambda)) /
73 (rho + hL));
74 };
75 return {meanAoI, peakAoI, lstAoI, true};
76}
77
78} // namespace aoi
79} // namespace line
80
81#endif // LINE_API_AOI_LCFSD_MGI1_H
Shared return types and arithmetic helpers for the templated Age of Information port.
InputError(const std::string &what)
Definition error.h:39
The exception types the port throws.
AoiLstResult< T > aoi_lcfsd_mgi1(const T &lambda, const Lst< T > &H_lst, const T &E_H, const T &E_H2)
Mean Age of Information, its transform and the peak age of an M/GI/1 non-preemptive LCFS queue with d...
std::function< T(const T &)> Lst
A Laplace-Stieltjes transform evaluated at real arguments.
Definition aoi_types.h:41
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:52
Number-type abstraction for the templated API port.
[meanAoI, lstAoI, peakAoI], mirroring jline.api.aoi.AoiLstResult.
Definition aoi_types.h:59