LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
dqsys_geogeo1.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_DQSYS_DQSYS_GEOGEO1_H
6#define LINE_API_DQSYS_DQSYS_GEOGEO1_H
7
8/**
9 * @file
10 * @ingroup api_dqsys
11 * Geo/Geo/1: the discrete-time single-server queue with geometric
12 * interarrival and service times.
13 *
14 * Templated port of matlab/src/api/qsys/dqsys_geogeo1.m. Two timing conventions
15 * are in use in the literature and both are supported, as in MATLAB:
16 *
17 * LAS_DA (late arrival, delayed access): an arrival in a slot cannot be
18 * served in that slot. Empty probability 1 - rho, mean queue length
19 * a(1-a)/(s-a).
20 * EAS (early arrival): the arrival is eligible immediately. Empty
21 * probability 1 - r with r = a(1-s)/(s(1-a)), mean queue length
22 * a(1-s)/(s-a).
23 *
24 * The distinction is not cosmetic: the two conventions give different empty
25 * probabilities, different mean queue lengths and different mean service times
26 * for the same (a, s). Daduna (LNCS 2046, Cor. 2.7) is the reference that ties
27 * the LAS_DA form to the continuous-time Geo/Geo/1 term for term.
28 *
29 * Everything here is a rational function of a and s, so the exact
30 * instantiation gives the stationary quantities with no rounding. That is
31 * worth having in the slotted setting, where the interesting regime is
32 * s - a small and the double evaluation of a(1-s)/(s(s-a)) loses digits
33 * exactly there.
34 */
35
36#include <cstddef>
37#include <string>
38
39#include "line/num/number.h"
40#include "line/util/error.h"
41
42namespace line {
43namespace dqsys {
44
45enum class GeoConvention { LAS_DA, EAS };
46
47template <class T>
62
63/** Stationary queue-length pmf under the convention of the result. */
64template <class T>
66 if (n < 0) throw InputError("dqsys_geogeo1_pmf: queue length must be nonnegative");
67 const T one = num_traits<T>::from_int(1);
69 return (one - r.ratio) * num_pow_int(r.ratio, static_cast<unsigned>(n));
70 if (n == 0) return r.emptyProb;
71 return r.emptyProb * (r.utilization / (one - r.arrivalProb)) *
72 num_pow_int(r.ratio, static_cast<unsigned>(n - 1));
73}
74
75/**
76 * @brief Geo/Geo/1: the discrete-time single-server queue with geometric
77 * interarrival and service times.
78 *
79 * @param a arrival probability per slot, in (0,1]
80 * @param s service completion probability per slot, in (0,1]
81 * @param convention slot-boundary convention (late arrival, early arrival)
82 */
83template <class T>
84GeoGeo1Result<T> dqsys_geogeo1(const T& a, const T& s,
86 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
87 if (a <= zero || a > one) throw InputError("dqsys_geogeo1: a must lie in (0,1]");
88 if (s <= zero || s > one) throw InputError("dqsys_geogeo1: s must lie in (0,1]");
89 if (a >= s) throw InputError("dqsys_geogeo1: the load a/s must be strictly less than 1");
90
92 r.convention = convention;
93 r.arrivalProb = a;
94 r.serviceProb = s;
95 r.utilization = a / s;
96 r.throughput = a;
97 r.ratio = a * (one - s) / (s * (one - a));
98 r.meanWaitingTime = a * (one - s) / (s * (s - a));
100
101 if (convention == GeoConvention::LAS_DA) {
102 r.emptyProb = one - r.utilization;
103 r.meanQueueLength = a * (one - a) / (s - a);
104 r.meanSojournTime = (one - a) / (s - a);
105 r.meanServiceTime = one / s;
106 } else {
107 r.emptyProb = one - r.ratio;
108 r.meanQueueLength = a * (one - s) / (s - a);
109 r.meanSojournTime = (one - s) / (s - a);
110 r.meanServiceTime = (one - s) / s;
111 }
112 return r;
113}
114
115} // namespace dqsys
116} // namespace line
117
118#endif // LINE_API_DQSYS_DQSYS_GEOGEO1_H
InputError(const std::string &what)
Definition error.h:39
The exception types the port throws.
T dqsys_geogeo1_pmf(const GeoGeo1Result< T > &r, int n)
Stationary queue-length pmf under the convention of the result.
GeoGeo1Result< T > dqsys_geogeo1(const T &a, const T &s, GeoConvention convention=GeoConvention::LAS_DA)
Geo/Geo/1: the discrete-time single-server queue with geometric interarrival and service times.
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.
T ratio
r = a(1-s)/(s(1-a))