LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
fj_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_FJ_BOUNDS_H
6#define LINE_API_FJ_BOUNDS_H
7
8/**
9 * @file
10 * @ingroup api_fj
11 * Upper and lower bounds on the mean response time of a K-way fork-join system
12 * of M/M/1 branches.
13 *
14 * Templated port of matlab/src/api/fj/fj_bounds.m, cross-checked against
15 * jar/src/main/java/jline/api/fj/FJ_bounds.java (identical).
16 *
17 * Rmax = H_K / (mu (1 - rho)) (Thomasian 2014, Eq. 1)
18 * Rmin = (1/mu) [ H_K + sum_{j=1..K} (1/j) rho/(j - rho) ] (Eq. 2)
19 *
20 * Both are rational functions of rho = lambda/mu, so the pair is exact in the
21 * field. That matters because the bounds are meant to bracket the true mean:
22 * a rounded Rmin can exceed a rounded Rmax when the two are close, which the
23 * exact instantiation never does.
24 */
25
28#include "line/num/number.h"
29#include "line/util/error.h"
30
31namespace line {
32namespace fj {
33
34/**
35 * @brief Upper and lower bounds on the mean response time of a K-way
36 * fork-join system of M/M/1 branches.
37 *
38 * @param K number of parallel branches, K >= 1
39 * @param lambda arrival rate
40 * @param mu per-branch service rate, mu > lambda for stability
41 * @return Rmax (pessimistic) and Rmin (optimistic) bounds
42 */
43template <class T>
44FJBoundsResult<T> fj_bounds(unsigned K, const T& lambda, const T& mu) {
45 detail::require_positive_K(K, "fj_bounds");
46 const T one = num_traits<T>::from_int(1);
47 const T rho = lambda / mu;
48 if (rho >= one) throw NumericError("fj_bounds: unstable system, rho = lambda/mu >= 1");
49
50 const T H_K = fj_harmonic<T>(K);
51 const T Rmax = H_K / (mu * (one - rho));
52
53 T S_K = num_traits<T>::from_int(0);
54 for (unsigned j = 1; j <= K; ++j) {
55 const T jj = num_traits<T>::from_int(static_cast<long>(j));
56 S_K += (one / jj) * (rho / (jj - rho));
57 }
58 const T Rmin = (one / mu) * (H_K + S_K);
59 return {Rmax, Rmin};
60}
61
62} // namespace fj
63} // namespace line
64
65#endif // LINE_API_FJ_BOUNDS_H
NumericError(const std::string &what)
Definition error.h:45
The exception types the port throws.
Harmonic number H_K = sum_{k=1..K} 1/k.
Shared return types and arithmetic helpers for the templated fork-join port.
FJBoundsResult< T > fj_bounds(unsigned K, const T &lambda, const T &mu)
Upper and lower bounds on the mean response time of a K-way fork-join system of M/M/1 branches.
Definition fj_bounds.h:44
T fj_harmonic(unsigned K)
Harmonic number H_K = sum_{k=1..K} 1/k.
Definition fj_harmonic.h:37
Number-type abstraction for the templated API port.
[Rmax, Rmin] of fj_bounds: pessimistic and optimistic response-time bounds.
Definition fj_types.h:48