LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
polling_qsys_klimited.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_POLLING_POLLING_QSYS_KLIMITED_H
6
#define LINE_API_POLLING_POLLING_QSYS_KLIMITED_H
7
8
/**
9
* @file
10
* @ingroup api_polling
11
* Approximate mean waiting times of a cyclic k-limited polling system.
12
*
13
* Templated port of matlab/src/api/polling/polling_qsys_klimited.m. Queue i
14
* is served K_i-limited: a visit ends after K_i services or when the queue
15
* empties, whichever comes first. The approximation is Fuhrmann's relation
16
* for symmetric k-limited systems (Fuhrmann 1985; Haverkort eq. 9.27; Takagi
17
* 1988 eq. 27), applied queue by queue:
18
*
19
* E[W_i] + b_i = (1-rho) / (1 - rho - lambda_i R/K_i) * (E[W_i^E] + b_i),
20
*
21
* with E[W_i^E] the exact exhaustive mean waiting time of the same system and
22
* R the mean total switchover time per cycle. In the symmetric case it is
23
* exact for K=1 and as K grows to infinity. Stability requires
24
* rho + lambda_i R/K_i < 1 at every queue.
25
*/
26
27
#include <cstddef>
28
#include <string>
29
#include <vector>
30
31
#include "
line/api/polling/polling_qsys_1limited.h
"
32
#include "
line/api/polling/polling_qsys_exhaustive.h
"
33
#include "
line/num/number.h
"
34
#include "
line/util/error.h
"
35
36
namespace
line
{
37
namespace
polling
{
38
39
/**
40
* @param m per-queue first two moments of arrivals, service and switchover
41
* @param K one positive limit, or one per queue
42
*/
43
template
<
class
T>
44
std::vector<T>
polling_qsys_klimited
(
const
PollingMoments<T>
& m, std::vector<long> K) {
45
m.
validate
(
"polling_qsys_klimited"
);
46
const
std::size_t n = m.
size
();
47
if
(K.size() == 1) K.assign(n, K[0]);
48
bool
bad = K.size() != n;
49
for
(
long
k : K) bad = bad || k < 1;
50
if
(bad)
51
throw
InputError
(
ErrorKind
{
"Argument"
},
52
"polling_qsys_klimited: K must be a positive integer, or one positive integer per queue."
);
53
const
T zero =
num_traits<T>::from_int
(0), one =
num_traits<T>::from_int
(1);
54
T rho = zero, R = zero;
55
for
(std::size_t i = 0; i < n; ++i) {
56
rho += m.
lambda
[i] * m.
b
[i];
57
R += m.
r
[i];
58
}
59
std::vector<T> den(n);
60
for
(std::size_t i = 0; i < n; ++i) {
61
den[i] = one - rho - m.
lambda
[i] * R /
num_traits<T>::from_int
(K[i]);
62
if
(den[i] <= zero)
63
throw
NumericError
(
ErrorKind
{
"Instability"
},
64
"polling_qsys_klimited: The k-limited polling system is unstable: "
65
"rho + lambda_i*R/K_i >= 1 at some queue."
);
66
}
67
const
std::vector<T> WE =
polling_qsys_exhaustive
(m);
68
std::vector<T> W(n);
69
for
(std::size_t i = 0; i < n; ++i) W[i] = (one - rho) / den[i] * (WE[i] + m.
b
[i]) - m.
b
[i];
70
return
W;
71
}
72
73
/** Scalar-K convenience overload. */
74
template
<
class
T>
75
std::vector<T>
polling_qsys_klimited
(
const
PollingMoments<T>
& m,
long
K) {
76
return
polling_qsys_klimited
(m, std::vector<long>{K});
77
}
78
79
}
// namespace polling
80
}
// namespace line
81
82
#endif
// LINE_API_POLLING_POLLING_QSYS_KLIMITED_H
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:105
line::NumericError::NumericError
NumericError(const std::string &what)
Definition
error.h:112
error.h
The exception types the port throws.
line::polling
Definition
polling_qsys_1limited.h:41
line::polling::polling_qsys_klimited
std::vector< T > polling_qsys_klimited(const PollingMoments< T > &m, std::vector< long > K)
Definition
polling_qsys_klimited.h:44
line::polling::polling_qsys_exhaustive
std::vector< T > polling_qsys_exhaustive(const PollingMoments< T > &m)
Exhaustive service: the server empties a queue completely before switching.
Definition
polling_qsys_exhaustive.h:104
line
Conservation laws of a layered queueing network, enumerated from its structure.
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
polling_qsys_1limited.h
Mean waiting times in polling systems: 1-limited and decrementing service, and the pseudo-conservatio...
polling_qsys_exhaustive.h
Mean waiting times of a polling system under exhaustive service.
line::ErrorKind
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition
error.h:37
line::num_traits
Definition
number.h:123
line::polling::PollingMoments
Per-queue first two moments of the arrival, service and switchover processes, the reduced form both f...
Definition
polling_qsys_1limited.h:48
line::polling::PollingMoments::validate
void validate(const char *who) const
Definition
polling_qsys_1limited.h:56
line::polling::PollingMoments::lambda
std::vector< T > lambda
arrival rate per queue
Definition
polling_qsys_1limited.h:49
line::polling::PollingMoments::r
std::vector< T > r
mean switchover time per queue
Definition
polling_qsys_1limited.h:52
line::polling::PollingMoments::b
std::vector< T > b
mean service time per queue
Definition
polling_qsys_1limited.h:50
line::polling::PollingMoments::size
std::size_t size() const
Definition
polling_qsys_1limited.h:55
include
line
api
polling
polling_qsys_klimited.h
Generated by
1.18.0