LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
pfqn_kriz_bounds.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_PFQN_PFQN_KRIZ_BOUNDS_H
6
#define LINE_API_PFQN_PFQN_KRIZ_BOUNDS_H
7
8
/**
9
* @file
10
* @ingroup api_pfqn
11
* Kriz (1984) closed-form throughput bounds for single-class closed networks
12
* of single-server stations and delay servers.
13
*
14
* Templated port of matlab/src/api/pfqn/pfqn_kriz_bounds.m (native Python
15
* twin: python/line_solver/api/pfqn/throughput_bounds.py). J. Kriz,
16
* "Throughput Bounds for Closed Queueing Networks", Perform. Eval. 4 (1984)
17
* 1-10. With loadings t_m (= L), T = sum t_m, r = Z + T, t' = max t_m and
18
* t'' = T/w (w stations):
19
*
20
* bottleneck (6) X <= min(N/r, 1/t')
21
* Thm 5.1 (26a) X >= 2N/(b1+sqrt(b1^2-4 a1 N)),
22
* a1 = ((N-1)/N) Z t', b1 = r + (N-1) t'
23
* Thm 5.1 (26b) X <= min(2N/(b2+sqrt(b2^2-4 a2 N)), 1/t'),
24
* a2 = Z t'', b2 = r + (N-1) t''
25
* Thm 4.2 (21) X <= N/(Z + (N-1-Z y(N-1) + B(N)) t'),
26
* y(N-1) = min((N-1)/r, 1/t') as in Sec. 6
27
* Thm 5.2 (28) X <= 2N/(b+sqrt(b^2-4 a N)), a = Z t', b = Z + (N-1+B(N)) t'
28
* B(N) = w1 + w2 (t2/t')^N (eq. 22), w1 stations at t', w2 at the second
29
* largest loading t2.
30
*
31
* For level i >= 1 the Theorem-3.2 balanced hierarchy (eq. 16) is added:
32
* Y_0 = 0, Y_i(N) = N/(r + (N-1-Z Y_{i-1}(N-1)) t') below and
33
* Ybar_0 = min(N/r,1/t'), Ybar_i(N) = min(N/(r + (N-1-Z Ybar_{i-1}(N-1)) t''),
34
* 1/t') above; levels above N are capped at N. Xlo is the larger of the valid
35
* lower bounds and Xhi the smallest valid upper bound.
36
*
37
* ARITHMETIC. The square-root bounds need sqrt, so the routine is gated on
38
* num_traits<T>::has_transcendental, as pfqn_sib is.
39
*/
40
41
#include <algorithm>
42
#include <cmath>
43
#include <cstddef>
44
#include <vector>
45
46
#include "
line/num/number.h
"
47
#include "
line/util/error.h
"
48
49
namespace
line
{
50
namespace
pfqn
{
51
52
/** Every individual bound of pfqn_kriz_bounds, MATLAB's info struct. */
53
template
<
class
T>
54
struct
KrizBoundsInfo
{
55
T
Ys_lo
,
Ys_hi
,
Ye
,
Yes
,
Xab
;
56
T
Ylo_i
,
Yhi_i
;
///< the Theorem-3.2 pair; meaningful only when has_level
57
bool
has_level
=
false
;
///< false where MATLAB reports NaN (level 0)
58
int
level
= 0;
///< the level used, min(level, N)
59
T
B
;
///< B(N) of eq. (22)
60
};
61
62
/** Return value of pfqn_kriz_bounds, mirroring [Xlo, Xhi, info]. */
63
template
<
class
T>
64
struct
KrizBounds
{
65
T
Xlo
;
66
T
Xhi
;
67
KrizBoundsInfo<T>
info
;
68
};
69
70
/**
71
* @brief Kriz (1984) throughput bounds.
72
*
73
* @param L (M) loadings of the single-server stations; zeros are dropped
74
* @param N population, at least 1
75
* @param Z total loading of the delay servers
76
* @param level Theorem-3.2 hierarchy level (0: closed forms only)
77
*/
78
template
<
class
T>
79
KrizBounds<T>
pfqn_kriz_bounds
(
const
std::vector<T>& Lin,
int
N,
const
T& Z,
int
level = 0) {
80
static_assert
(
num_traits<T>::has_transcendental
,
81
"pfqn_kriz_bounds requires transcendental arithmetic (the square-root bounds)"
);
82
using
std::sqrt;
83
const
T zero =
num_traits<T>::from_int
(0), one =
num_traits<T>::from_int
(1);
84
std::vector<T> L;
85
for
(
const
T& x :
Lin
)
86
if
(x > zero) L.push_back(x);
87
if
(L.empty())
88
throw
InputError
(
ErrorKind
{
"Invalid"
},
89
"pfqn_kriz_bounds needs at least one station with positive loading."
);
90
if
(N < 1)
throw
InputError
(
ErrorKind
{
"Invalid"
},
"pfqn_kriz_bounds needs N >= 1."
);
91
level = std::max(0, level);
92
const
T NT =
num_traits<T>::from_int
(N), N1 =
num_traits<T>::from_int
(N - 1);
93
const
T w =
num_traits<T>::from_int
(
static_cast<
long
>
(L.size()));
94
T Ts = zero, tp = L[0];
95
for
(
const
T& x : L) {
96
Ts += x;
97
if
(x > tp) tp = x;
98
}
99
const
T r = T(Z + Ts);
100
const
T tpp = T(Ts / w);
101
const
T eps12 =
num_traits<T>::from_double
(1e-12);
102
long
w1 = 0;
103
std::vector<T> rest;
104
for
(
const
T& x : L) {
105
const
T d = x > tp ? T(x - tp) : T(tp - x);
106
if
(d <= T(eps12 * tp))
107
++w1;
108
else
109
rest.push_back(x);
110
}
111
T B =
num_traits<T>::from_int
(w1);
112
if
(!rest.empty()) {
113
T t2 = rest[0];
114
for
(
const
T& x : rest)
115
if
(x > t2) t2 = x;
116
long
w2 = 0;
117
for
(
const
T& x : rest) {
118
const
T d = x > t2 ? T(x - t2) : T(t2 - x);
119
if
(d <= T(eps12 * t2)) ++w2;
120
}
121
B = T(B +
num_traits<T>::from_int
(w2) *
num_pow_int
(T(t2 / tp),
static_cast<
unsigned
>
(N)));
122
}
123
const
auto
tmin = [](
const
T& a,
const
T& b) -> T {
return
a < b ? a : b; };
124
const
auto
tmax0 = [&zero](
const
T& a) -> T {
return
a > zero ? a : zero; };
125
const
T inv_tp = T(one / tp);
126
const
T four =
num_traits<T>::from_int
(4), two =
num_traits<T>::from_int
(2);
127
128
KrizBounds<T>
out;
129
KrizBoundsInfo<T>
& info = out.
info
;
130
info.
B
= B;
131
info.
Xab
= tmin(T(NT / r), inv_tp);
// eq. (6)
132
const
T a1 = T(T(N1 / NT) * Z * tp);
133
const
T b1 = T(r + N1 * tp);
134
info.
Ys_lo
= T(two * NT / T(b1 + sqrt(tmax0(T(b1 * b1 - four * a1 * NT)))));
// eq. (26a)
135
const
T a2 = T(Z * tpp);
136
const
T b2 = T(r + N1 * tpp);
137
info.
Ys_hi
= tmin(T(two * NT / T(b2 + sqrt(tmax0(T(b2 * b2 - four * a2 * NT))))), inv_tp);
// eq. (26b)
138
const
T y = tmin(T(N1 / r), inv_tp);
139
info.
Ye
= T(NT / T(Z + T(N1 - Z * y + B) * tp));
// eq. (21)
140
const
T a = T(Z * tp);
141
const
T b = T(Z + T(N1 + B) * tp);
142
info.
Yes
= T(two * NT / T(b + sqrt(tmax0(T(b * b - four * a * NT)))));
// eq. (28)
143
144
info.
Ylo_i
= zero;
145
info.
Yhi_i
= zero;
146
const
int
lev = std::min(level, N);
147
info.
level
= lev;
148
if
(lev >= 1) {
149
// Theorem 3.2: level lev at N, from level 0 at N-lev upwards.
150
info.
has_level
=
true
;
151
const
int
n0 = N - lev;
152
T Ylo = zero;
153
T Yhi = n0 > 0 ? tmin(T(
num_traits<T>::from_int
(n0) / r), inv_tp) : zero;
154
for
(
int
j = 1; j <= lev; ++j) {
155
const
int
n = n0 + j;
156
const
T nT =
num_traits<T>::from_int
(n), nm1 =
num_traits<T>::from_int
(n - 1);
157
Ylo = T(nT / T(r + T(nm1 - Z * Ylo) * tp));
158
Yhi = tmin(T(nT / T(r + T(nm1 - Z * Yhi) * tpp)), inv_tp);
159
}
160
info.
Ylo_i
= Ylo;
161
info.
Yhi_i
= Yhi;
162
}
163
164
out.
Xlo
= info.
Ys_lo
;
165
if
(info.
has_level
&& info.
Ylo_i
> out.
Xlo
) out.
Xlo
= info.
Ylo_i
;
166
out.
Xhi
= tmin(tmin(info.
Xab
, info.
Ys_hi
), tmin(info.
Ye
, info.
Yes
));
167
if
(info.
has_level
) out.
Xhi
= tmin(out.
Xhi
, info.
Yhi_i
);
168
return
out;
169
}
170
171
}
// namespace pfqn
172
}
// namespace line
173
174
#endif
// LINE_API_PFQN_PFQN_KRIZ_BOUNDS_H
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:105
error.h
The exception types the port throws.
line::pfqn
Definition
cd_peak_scaling.h:43
line::pfqn::pfqn_kriz_bounds
KrizBounds< T > pfqn_kriz_bounds(const std::vector< T > &Lin, int N, const T &Z, int level=0)
Kriz (1984) throughput bounds.
Definition
pfqn_kriz_bounds.h:79
line::pfqn::LinearizerMxMethod::Lin
@ Lin
Definition
pfqn_linearizermx.h:87
line
Conservation laws of a layered queueing network, enumerated from its structure.
Definition
aoi_dist2ph.h:51
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:204
number.h
Number-type abstraction for the templated API port.
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::pfqn::KrizBoundsInfo
Every individual bound of pfqn_kriz_bounds, MATLAB's info struct.
Definition
pfqn_kriz_bounds.h:54
line::pfqn::KrizBoundsInfo::has_level
bool has_level
false where MATLAB reports NaN (level 0)
Definition
pfqn_kriz_bounds.h:57
line::pfqn::KrizBoundsInfo::Ye
T Ye
Definition
pfqn_kriz_bounds.h:55
line::pfqn::KrizBoundsInfo::Yhi_i
T Yhi_i
the Theorem-3.2 pair; meaningful only when has_level
Definition
pfqn_kriz_bounds.h:56
line::pfqn::KrizBoundsInfo::Ys_lo
T Ys_lo
Definition
pfqn_kriz_bounds.h:55
line::pfqn::KrizBoundsInfo::Ylo_i
T Ylo_i
Definition
pfqn_kriz_bounds.h:56
line::pfqn::KrizBoundsInfo::Xab
T Xab
Definition
pfqn_kriz_bounds.h:55
line::pfqn::KrizBoundsInfo::level
int level
the level used, min(level, N)
Definition
pfqn_kriz_bounds.h:58
line::pfqn::KrizBoundsInfo::Yes
T Yes
Definition
pfqn_kriz_bounds.h:55
line::pfqn::KrizBoundsInfo::B
T B
B(N) of eq. (22).
Definition
pfqn_kriz_bounds.h:59
line::pfqn::KrizBoundsInfo::Ys_hi
T Ys_hi
Definition
pfqn_kriz_bounds.h:55
line::pfqn::KrizBounds
Return value of pfqn_kriz_bounds, mirroring [Xlo, Xhi, info].
Definition
pfqn_kriz_bounds.h:64
line::pfqn::KrizBounds::Xhi
T Xhi
Definition
pfqn_kriz_bounds.h:66
line::pfqn::KrizBounds::Xlo
T Xlo
Definition
pfqn_kriz_bounds.h:65
line::pfqn::KrizBounds::info
KrizBoundsInfo< T > info
Definition
pfqn_kriz_bounds.h:67
include
line
api
pfqn
pfqn_kriz_bounds.h
Generated by
1.18.0