LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
fj_respt_varki.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_RESPT_VARKI_H
6#define LINE_API_FJ_RESPT_VARKI_H
7
8/**
9 * @file
10 * @ingroup api_fj
11 * Varki approximation to the mean response time of a K-way fork-join system of
12 * M/M/1 branches.
13 *
14 * Templated port of matlab/src/api/fj/fj_respt_varki.m, cross-checked against
15 * FJ_respt.fj_respt_varki in jar/src/main/java/jline/api/fj/FJ_respt.java
16 * (identical).
17 *
18 * R_K = (1/mu) [ H_K + rho/(2(1-rho)) ( S1 + (1-2 rho) S2 ) ]
19 * S1 = sum_{i=1..K} 1/(i - rho), S2 = sum_{i=1..K} 1/(i (i - rho))
20 *
21 * Rational in rho, hence exact in the field. Note that the denominators i - rho
22 * are positive for every i >= 1 whenever rho < 1, so the only pole is at
23 * rho = 1.
24 */
25
28#include "line/num/number.h"
29#include "line/util/error.h"
30
31namespace line {
32namespace fj {
33
34/**
35 * @brief Varki approximation to the mean response time of a K-way fork-join
36 * 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
41 * @return approximate mean fork-join response time
42 */
43template <class T>
44T fj_respt_varki(unsigned K, const T& lambda, const T& mu) {
45 detail::require_positive_K(K, "fj_respt_varki");
46 const T one = num_traits<T>::from_int(1), two = num_traits<T>::from_int(2);
47 const T rho = lambda / mu;
48 if (rho >= one) throw NumericError("fj_respt_varki: unstable system, rho = lambda/mu >= 1");
49
50 const T H_K = fj_harmonic<T>(K);
52 for (unsigned i = 1; i <= K; ++i) {
53 const T ii = num_traits<T>::from_int(static_cast<long>(i));
54 S1 += one / (ii - rho);
55 S2 += one / (ii * (ii - rho));
56 }
57 return (one / mu) * (H_K + (rho / (two * (one - rho))) * (S1 + (one - two * rho) * S2));
58}
59
60} // namespace fj
61} // namespace line
62
63#endif // LINE_API_FJ_RESPT_VARKI_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.
T fj_respt_varki(unsigned K, const T &lambda, const T &mu)
Varki approximation to the mean response time of a K-way fork-join system of M/M/1 branches.
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.