LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
pfqn_oi_open.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_OI_OPEN_H
6#define LINE_API_PFQN_PFQN_OI_OPEN_H
7
8/**
9 * @file
10 * @ingroup api_pfqn
11 * Exact steady-state means of an OPEN order-independent (OI) station fed by
12 * Poisson traffic.
13 *
14 * Templated port of matlab/src/api/pfqn/pfqn_oi_open.m. An OI queue is
15 * quasi-reversible (Berezner, Kriel and Krzesinski 1995, Thm 1), so in an open
16 * network of OI and BCMP stations each OI station has the isolated product-form
17 * marginal
18 *
19 * pi(n) = P0 * Phi(n) * prod_r lambda_r^{n_r},
20 * Phi(0) = 1, Phi(n) = (1/mu(n)) sum_{r: n_r>0} Phi(n - e_r),
21 *
22 * with lambda_r the class-r traffic offered to the station. P0 is an INFINITE
23 * sum, evaluated exactly by the saturation recursion of pfqn_oi_mixed whenever
24 * the rate saturates (the open station is the mixed table with no closed class,
25 * a one-point lattice), and by the 'oi.trunc' doubling-cutoff branch when it
26 * does not.
27 *
28 * References: Berezner, Kriel, Krzesinski (1995), Queueing Systems 19:345-359;
29 * Bonald, Comte, Mathieu (2017), POMACS 1(2), Art. 41.
30 *
31 * ARITHMETIC. Field arithmetic, as pfqn_oi_mixed. An UNSTABLE station reports
32 * Q = Usir = Inf for the classes with traffic, which exists only in floating
33 * point: under exact arithmetic that case raises instead.
34 */
35
36#include <cmath>
37#include <functional>
38#include <limits>
39#include <string>
40#include <vector>
41
43#include "line/num/number.h"
44#include "line/util/error.h"
45
46namespace line {
47namespace pfqn {
48
49/** Return value of pfqn_oi_open, mirroring [Q, Usir, P0, stable, tau, method]. */
50template <class T>
52 std::vector<T> Q; ///< (R) mean number of class-r jobs E[n_r] (Inf when unstable)
53 std::vector<T> Usir; ///< (R) mean number of class-r jobs in service (Inf when unstable)
54 T P0; ///< probability that the station is empty (0 when unstable)
55 bool stable = true; ///< false when some reachable macrostate has den(m) <= 0
56 std::vector<int> tau; ///< (R) cutoffs used (frozen T for 'oi.trunc')
57 std::string method = "oi"; ///< "oi" (exact) or "oi.trunc"
58};
59
60/**
61 * @brief Exact means of an open OI station.
62 *
63 * @param lambda (R) class traffic offered to the station (>= 0)
64 * @param mu permutation-invariant total service rate mu(n) on the count vector
65 * @param opt tol, taumax, maxstates of the cutoff search and 'oi.trunc'
66 */
67template <class T>
68OiOpenResult<T> pfqn_oi_open(const std::vector<T>& lambda,
69 const std::function<T(const std::vector<int>&)>& mu,
71 const std::size_t R = lambda.size();
72 const T zero = num_traits<T>::from_int(0);
74 lambda, std::vector<double>(R, std::numeric_limits<double>::infinity()), mu, opt);
76 out.stable = m.stable;
77 out.tau = m.tau;
78 out.method = m.method;
79 out.Q.assign(R, zero);
80 out.Usir.assign(R, zero);
81 out.P0 = zero;
82 if (!m.stable) {
83 if constexpr (!num_traits<T>::has_transcendental) {
84 throw NumericError(ErrorKind{"Instability"},
85 "pfqn_oi_open: the station is unstable (a saturated macrostate has a nonpositive "
86 "net rate) and its mean queue length is infinite, which exact arithmetic cannot "
87 "represent");
88 } else {
89 const T inf = num_traits<T>::from_double(std::numeric_limits<double>::infinity());
90 for (std::size_t r = 0; r < R; ++r)
91 if (lambda[r] > zero) {
92 out.Q[r] = inf;
93 out.Usir[r] = inf;
94 }
95 return out;
96 }
97 }
98 out.P0 = T(num_traits<T>::from_int(1) / m.W[0]);
99 for (std::size_t r = 0; r < R; ++r) {
100 out.Q[r] = T(m.H(0, r) / m.W[0]);
101 out.Usir[r] = T(m.S(0, r) / m.W[0]);
102 }
103 return out;
104}
105
106} // namespace pfqn
107} // namespace line
108
109#endif // LINE_API_PFQN_PFQN_OI_OPEN_H
NumericError(const std::string &what)
Definition error.h:112
The exception types the port throws.
OiMixedResult< T > pfqn_oi_mixed(const std::vector< T > &lambda, const std::vector< double > &N, const std::function< T(const std::vector< int > &)> &mu, const OiMixedOptions &opt=OiMixedOptions())
Closed-lattice station tables of an OI station with open classes summed out.
OiOpenResult< T > pfqn_oi_open(const std::vector< T > &lambda, const std::function< T(const std::vector< int > &)> &mu, const OiMixedOptions &opt=OiMixedOptions())
Exact means of an open OI station.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Number-type abstraction for the templated API port.
Closed-lattice station tables of an order-independent (OI) station visited by CLOSED and OPEN classes...
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
The tuning fields of pfqn_oi_mixed / pfqn_oi_open (OPTIONS in the reference).
Return value of pfqn_oi_mixed, mirroring [W, H, S, stable, tau, method].
std::vector< int > tau
(R) open cutoffs used (0 for closed and idle classes)
Matrix< T > S
(prod(Nc+1) x R) per-class in-service weights
std::vector< T > W
(prod(Nc+1)) column-major table over the closed lattice
std::string method
"oi" (exact) or "oi.trunc"
bool stable
false when some reachable macrostate has den(m) <= 0
Matrix< T > H
(prod(Nc+1) x R) per-class mean weights
Return value of pfqn_oi_open, mirroring [Q, Usir, P0, stable, tau, method].
std::vector< T > Usir
(R) mean number of class-r jobs in service (Inf when unstable)
std::vector< T > Q
(R) mean number of class-r jobs E[n_r] (Inf when unstable)
std::string method
"oi" (exact) or "oi.trunc"
bool stable
false when some reachable macrostate has den(m) <= 0
T P0
probability that the station is empty (0 when unstable)
std::vector< int > tau
(R) cutoffs used (frozen T for 'oi.trunc')