LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
pfqn_ssd.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_SSD_H
6#define LINE_API_PFQN_PFQN_SSD_H
7
8/**
9 * @file
10 * @ingroup api_pfqn
11 * Server-Station Disaggregation bounds for a multiserver closed network
12 * (Dallery and Suri, SIGMETRICS 1986).
13 *
14 * Templated port of matlab/src/api/pfqn/pfqn_ssd.m. Single-class model: L is the
15 * per-station demand vector, N the population, Z the think time.
16 *
17 * Theorem 5 eq. (6) carries no think time of its own. Inserting a bare +Z into
18 * the Theorem 5 form is NOT a bound, because the BJB optimistic step needs
19 * sum_k Q_k(N-1) = N-1, which fails once Z X(N-1) jobs sit at the terminal.
20 * The queueing term is corrected instead, scaled by the terminal-workload
21 * factor of Lazowska et al. 1984, Table 5.2:
22 * (N-1) Y_l / (1 + Z/(N R_l)) on the lower bound and (N-1) Y_u / (1 + Z/R_u) on
23 * the upper. Both reduce to the Z=0 forms exactly, so this generalises rather
24 * than replaces eq. (6), and the Z>0 case is computed instead of refused.
25 *
26 * All operations stay in the field, so the bound is exact in rational
27 * arithmetic: a bound computed exactly is worth having, since a bound violated
28 * only by rounding is indistinguishable from a real violation.
29 */
30
31#include <algorithm>
32#include <vector>
33
34#include "line/num/number.h"
35#include "line/util/error.h"
36#include "line/util/matrix.h"
37
38namespace line {
39namespace pfqn {
40
41template <class T>
42struct SsdBounds {
43 T Xlo;
44 T Xhi;
45};
46
47/**
48 * @brief Server-Station Disaggregation bounds for a multiserver closed
49 * network (Dallery and Suri, SIGMETRICS 1986).
50 *
51 * @param L demands, @param N population, @param Z think time,
52 * @param nservers per-station server counts (empty for all ones)
53 */
54template <class T>
55SsdBounds<T> pfqn_ssd(const std::vector<T>& L, const T& N, const T& Z,
56 const std::vector<T>& nservers) {
57 const std::size_t K = L.size();
58 if (K == 0) throw InputError("pfqn_ssd: empty demand vector");
59 if (!nservers.empty() && nservers.size() != K)
60 throw InputError("pfqn_ssd: server-count vector has the wrong length");
61 const T one = num_traits<T>::from_int(1);
62
65 std::size_t b = 0;
66 for (std::size_t i = 0; i < K; ++i) {
67 const T c = nservers.empty() ? one : nservers[i];
68 if (c == num_traits<T>::from_int(0)) throw InputError("pfqn_ssd: zero server count");
69 Rl += L[i];
70 const T lc = L[i] / c;
71 Ru += lc;
72 if (lc > Yl) {
73 Yl = lc;
74 b = i;
75 }
76 }
77 const T Kt = num_traits<T>::from_int(static_cast<long>(K));
78 const T Yu = Ru / Kt;
79 const T cb = nservers.empty() ? one : nservers[b];
80
81 const T zero = num_traits<T>::from_int(0);
82 // Lazowska Table 5.2 terminal-workload scaling; at Z=0 both factors are 1.
83 // A zero total demand forces Yl = Yu = 0, so the term vanishes and the
84 // division that would be undefined is never reached.
85 const T ql = (Rl == zero) ? zero : (N - one) * Yl / (one + Z / (N * Rl));
86 const T qu = (Ru == zero) ? zero : (N - one) * Yu / (one + Z / Ru);
87
89 r.Xlo = N / (Rl + Z + ql); // Theorem 5 lower, think-time corrected
90 T hi = N / (Ru + Z + qu); // Theorem 5 upper, eq. (6), think-time corrected
91 const T cap = cb / L[b];
92 if (cap < hi) hi = cap;
93 const T pop = N / (Rl + Z);
94 if (pop < hi) hi = pop;
95 r.Xhi = hi;
96 return r;
97}
98
99template <class T>
100SsdBounds<T> pfqn_ssd(const std::vector<T>& L, const T& N, const T& Z) {
101 return pfqn_ssd(L, N, Z, std::vector<T>());
102}
103
104} // namespace pfqn
105} // namespace line
106
107#endif
InputError(const std::string &what)
Definition error.h:105
The exception types the port throws.
Dense matrix and non-owning view.
SsdBounds< T > pfqn_ssd(const std::vector< T > &L, const T &N, const T &Z, const std::vector< T > &nservers)
Server-Station Disaggregation bounds for a multiserver closed network (Dallery and Suri,...
Definition pfqn_ssd.h:55
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:52
Number-type abstraction for the templated API port.