LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
npfqn_traffic_rqt.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_NPFQN_NPFQN_TRAFFIC_RQT_H
6#define LINE_API_NPFQN_NPFQN_TRAFFIC_RQT_H
7
8/**
9 * @file
10 * @ingroup api_npfqn
11 * Effective arrival processes of a network under the Robust Queueing calculus.
12 *
13 * Templated port of matlab/src/api/npfqn/npfqn_traffic_rqt.m, cross-checked
14 * against jar/src/main/java/jline/api/npfqn/Npfqn_traffic_rqt.java.
15 *
16 * The network characterization composes three operators: passage through a
17 * queue with adversarial servers leaves the uncertainty set unchanged (robust
18 * Burke, Theorem 4), superposition merges sets by Theorem 5, and thinning by a
19 * fraction f scales the rate by f and the variability by f^(-1/alpha)
20 * (Theorem 6). The resulting equations are
21 *
22 * lambda_j = lambda0_j + sum_i lambda_i f_ij,
23 * Gamma_j = (1/lambda_j) [ 1{a0_j=ab_j} (lambda0_j Gamma0_j)^(p_j)
24 * + sum_i 1{ab_i=ab_j} (lambda_i Gamma_i)^(p_i) f_ij ]^(1/p_j),
25 *
26 * with p_j = ab_j/(ab_j-1) and ab_j the minimum tail coefficient among the
27 * streams feeding j: the heaviest tail upstream dominates. Both are solved
28 * exactly rather than iteratively. The rate equations are the usual traffic
29 * equations, and in the variables z_j = (lambda_j Gamma_j)^(p_j) the variability
30 * equations are linear as well, so each is one linear system; ab is obtained by
31 * propagating the minimum to a fixed point.
32 *
33 * ARITHMETIC. Real exponents make this transcendental.
34 *
35 * Reference: C. Bandi, D. Bertsimas, N. Youssef (2015). Robust Queueing Theory.
36 * Operations Research 63(3), 676-700, Theorems 4-7 and 10.
37 */
38
39#include <cstddef>
40#include <limits>
41#include <vector>
42
44#include "line/num/number.h"
45#include "line/util/linalg.h"
46#include "line/util/matrix.h"
47
48namespace line {
49namespace npfqn {
50
51template <class T>
52struct TrafficRqt {
53 std::vector<T> lambda; ///< effective arrival rate at each node
54 std::vector<T> Gamma; ///< effective variability parameter at each node
55 std::vector<T> alpha; ///< effective tail coefficient at each node
56};
57
58/**
59 * @brief Effective arrival processes of a network under the Robust Queueing
60 * calculus.
61 *
62 * @param lambda0 external arrival rate at each node, 0 where there is none
63 * @param Gamma0 variability parameter of each external arrival process, which
64 * for a renewal stream is the interarrival standard deviation
65 * @param alpha0 tail coefficient in (1,2] of each external arrival process
66 * @param F routing probabilities, F(i,j) = fraction of the jobs leaving
67 * node i that go to node j (row sums <= 1)
68 */
69template <class T>
70TrafficRqt<T> npfqn_traffic_rqt(const std::vector<T>& lambda0, const std::vector<T>& Gamma0,
71 const std::vector<T>& alpha0, const Matrix<T>& F) {
73 "npfqn_traffic_rqt requires transcendental arithmetic");
74 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
75 const T two = num_traits<T>::from_int(2);
76 const std::size_t J = lambda0.size();
77 TrafficRqt<T> out;
78 out.lambda.assign(J, zero);
79 out.Gamma.assign(J, zero);
80 out.alpha.assign(J, two);
81
82 // Traffic equations, lambda = (I - F')^{-1} lambda0.
83 Matrix<T> ImFt(J, J, zero);
84 for (std::size_t i = 0; i < J; ++i)
85 for (std::size_t j = 0; j < J; ++j)
86 ImFt(i, j) = T((i == j ? one : zero) - F(j, i));
87 const Matrix<T> Xi = inverse(ImFt);
88 for (std::size_t j = 0; j < J; ++j) {
89 T s = zero;
90 for (std::size_t i = 0; i < J; ++i) s = T(s + Xi(j, i) * lambda0[i]);
91 out.lambda[j] = s;
92 }
93
94 // Effective tail coefficient: the minimum propagated along the routing graph.
95 const double inf = std::numeric_limits<double>::infinity();
96 std::vector<double> alpha(J);
97 for (std::size_t j = 0; j < J; ++j)
98 alpha[j] = lambda0[j] > zero ? num_traits<T>::to_double(alpha0[j]) : inf;
99 for (std::size_t it = 0; it < J; ++it) {
100 bool changed = false;
101 for (std::size_t j = 0; j < J; ++j)
102 for (std::size_t i = 0; i < J; ++i)
103 if (F(i, j) > zero && out.lambda[i] > zero && alpha[i] < alpha[j]) {
104 alpha[j] = alpha[i];
105 changed = true;
106 }
107 if (!changed) break;
108 }
109 for (std::size_t j = 0; j < J; ++j) {
110 // an unreachable node keeps the light-tailed default
111 if (!(alpha[j] < inf)) alpha[j] = 2.0;
112 out.alpha[j] = num_traits<T>::from_double(alpha[j]);
113 }
114
115 // Variability equations, linear in z_j = (lambda_j Gamma_j)^(p_j).
116 std::vector<T> p(J, two);
117 for (std::size_t j = 0; j < J; ++j) p[j] = out.alpha[j] / (out.alpha[j] - one);
118 Matrix<T> z0(J, 1, zero);
119 for (std::size_t j = 0; j < J; ++j) {
120 const double d = num_traits<T>::to_double(alpha0[j]) - alpha[j];
121 if (lambda0[j] > zero && d < 1e-12 && d > -1e-12)
122 z0(j, 0) = qsys::detail::num_pow(T(lambda0[j] * Gamma0[j]), p[j]);
123 }
124 Matrix<T> ImAt(J, J, zero);
125 for (std::size_t i = 0; i < J; ++i)
126 for (std::size_t j = 0; j < J; ++j) {
127 T a = zero;
128 const double d = alpha[j] - alpha[i];
129 if (F(j, i) > zero && d < 1e-12 && d > -1e-12) a = F(j, i);
130 ImAt(i, j) = T((i == j ? one : zero) - a);
131 }
132 const Matrix<T> z = matmul(inverse(ImAt), z0);
133
134 for (std::size_t j = 0; j < J; ++j) {
135 T zj = z(j, 0);
136 if (zj < zero) zj = zero;
137 if (out.lambda[j] > zero)
138 out.Gamma[j] = qsys::detail::num_pow(zj, T(one / p[j])) / out.lambda[j];
139 }
140 return out;
141}
142
143} // namespace npfqn
144} // namespace line
145
146#endif // LINE_API_NPFQN_NPFQN_TRAFFIC_RQT_H
Dense linear algebra over the templated number type: products, identity, inverse, and powers.
Dense matrix and non-owning view.
TrafficRqt< T > npfqn_traffic_rqt(const std::vector< T > &lambda0, const std::vector< T > &Gamma0, const std::vector< T > &alpha0, const Matrix< T > &F)
Effective arrival processes of a network under the Robust Queueing calculus.
Matrix< T > inverse(const Matrix< T > &A)
Inverse by LU with one factorization and n back substitutions.
Definition linalg.h:72
Matrix< T > matmul(const Matrix< T > &A, const Matrix< T > &B)
Matrix product A B.
Definition linalg.h:36
Number-type abstraction for the templated API port.
Shared return type and arithmetic helpers for the templated qsys port.
std::vector< T > Gamma
effective variability parameter at each node
std::vector< T > lambda
effective arrival rate at each node
std::vector< T > alpha
effective tail coefficient at each node