LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
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
42
namespace
line
{
43
namespace
dqsys
{
44
45
enum class
GeoConvention
{
LAS_DA
,
EAS
};
46
47
template
<
class
T>
48
struct
GeoGeo1Result
{
49
GeoConvention
convention
=
GeoConvention::LAS_DA
;
50
T
arrivalProb
;
51
T
serviceProb
;
52
T
utilization
;
///< rho = a/s
53
T
throughput
;
///< a
54
T
emptyProb
;
55
T
ratio
;
///< r = a(1-s)/(s(1-a))
56
T
meanQueueLength
;
57
T
meanWaitingQueue
;
58
T
meanSojournTime
;
59
T
meanWaitingTime
;
60
T
meanServiceTime
;
61
};
62
63
/** Stationary queue-length pmf under the convention of the result. */
64
template
<
class
T>
65
T
dqsys_geogeo1_pmf
(
const
GeoGeo1Result<T>
& r,
int
n) {
66
if
(n < 0)
throw
InputError
(
"dqsys_geogeo1_pmf: queue length must be nonnegative"
);
67
const
T one =
num_traits<T>::from_int
(1);
68
if
(r.
convention
==
GeoConvention::EAS
)
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
*/
83
template
<
class
T>
84
GeoGeo1Result<T>
dqsys_geogeo1
(
const
T& a,
const
T& s,
85
GeoConvention
convention =
GeoConvention::LAS_DA
) {
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
91
GeoGeo1Result<T>
r;
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));
99
r.
meanWaitingQueue
= a * r.
meanWaitingTime
;
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
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
error.h
The exception types the port throws.
line::dqsys
Definition
dqsys_bernoulli1.h:46
line::dqsys::dqsys_geogeo1_pmf
T dqsys_geogeo1_pmf(const GeoGeo1Result< T > &r, int n)
Stationary queue-length pmf under the convention of the result.
Definition
dqsys_geogeo1.h:65
line::dqsys::GeoConvention
GeoConvention
Definition
dqsys_geogeo1.h:45
line::dqsys::GeoConvention::EAS
@ EAS
Definition
dqsys_geogeo1.h:45
line::dqsys::GeoConvention::LAS_DA
@ LAS_DA
Definition
dqsys_geogeo1.h:45
line::dqsys::dqsys_geogeo1
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.
Definition
dqsys_geogeo1.h:84
line
Definition
aoi_dist2ph.h:52
line::num_pow_int
T num_pow_int(const T &base, unsigned e)
Integer power, valid in any field (no transcendental requirement).
Definition
number.h:192
number.h
Number-type abstraction for the templated API port.
line::dqsys::GeoGeo1Result
Definition
dqsys_geogeo1.h:48
line::dqsys::GeoGeo1Result::throughput
T throughput
a
Definition
dqsys_geogeo1.h:53
line::dqsys::GeoGeo1Result::convention
GeoConvention convention
Definition
dqsys_geogeo1.h:49
line::dqsys::GeoGeo1Result::meanQueueLength
T meanQueueLength
Definition
dqsys_geogeo1.h:56
line::dqsys::GeoGeo1Result::serviceProb
T serviceProb
Definition
dqsys_geogeo1.h:51
line::dqsys::GeoGeo1Result::meanWaitingQueue
T meanWaitingQueue
Definition
dqsys_geogeo1.h:57
line::dqsys::GeoGeo1Result::arrivalProb
T arrivalProb
Definition
dqsys_geogeo1.h:50
line::dqsys::GeoGeo1Result::meanServiceTime
T meanServiceTime
Definition
dqsys_geogeo1.h:60
line::dqsys::GeoGeo1Result::utilization
T utilization
rho = a/s
Definition
dqsys_geogeo1.h:52
line::dqsys::GeoGeo1Result::emptyProb
T emptyProb
Definition
dqsys_geogeo1.h:54
line::dqsys::GeoGeo1Result::ratio
T ratio
r = a(1-s)/(s(1-a))
Definition
dqsys_geogeo1.h:55
line::dqsys::GeoGeo1Result::meanWaitingTime
T meanWaitingTime
Definition
dqsys_geogeo1.h:59
line::dqsys::GeoGeo1Result::meanSojournTime
T meanSojournTime
Definition
dqsys_geogeo1.h:58
line::num_traits
Definition
number.h:111
include
line
api
dqsys
dqsys_geogeo1.h
Generated by
1.18.0