LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
fj_synch_delay.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_SYNCH_DELAY_H
6#define LINE_API_FJ_SYNCH_DELAY_H
7
8/**
9 * @file
10 * @ingroup api_fj
11 * Mean synchronization delay of a 2-way fork-join system of M/M/1 branches,
12 * i.e. the time the first-finishing branch waits at the join.
13 *
14 * Templated port of matlab/src/api/fj/fj_synch_delay.m, cross-checked against
15 * jar/src/main/java/jline/api/fj/FJ_synch_delay.java (identical).
16 *
17 * S_2 = (1/2)(1 - rho/4) R(rho)
18 *
19 * Rational in rho, hence exact in the field. It satisfies
20 * R_2 = R + S_2 exactly, which is the identity worth checking: both sides are
21 * exact rationals, so any discrepancy is a port error and not a rounding one.
22 */
23
26#include "line/num/number.h"
27#include "line/util/error.h"
28
29namespace line {
30namespace fj {
31
32/**
33 * @brief Mean synchronization delay of a 2-way fork-join system of M/M/1
34 * branches, i.e. the time the first-finishing branch waits at the join.
35 *
36 * @param lambda arrival rate
37 * @param mu per-branch service rate
38 * @return mean synchronization delay
39 */
40template <class T>
41T fj_synch_delay(const T& lambda, const T& mu) {
42 const T one = num_traits<T>::from_int(1);
43 const T rho = lambda / mu;
44 if (rho >= one) throw NumericError("fj_synch_delay: unstable system, rho = lambda/mu >= 1");
45 const T R_rho = qsys::qsys_mm1(lambda, mu).W;
46 return num_traits<T>::from_rational(1, 2) * (one - rho / num_traits<T>::from_int(4)) * R_rho;
47}
48
49} // namespace fj
50} // namespace line
51
52#endif // LINE_API_FJ_SYNCH_DELAY_H
NumericError(const std::string &what)
Definition error.h:45
The exception types the port throws.
Shared return types and arithmetic helpers for the templated fork-join port.
T fj_synch_delay(const T &lambda, const T &mu)
Mean synchronization delay of a 2-way fork-join system of M/M/1 branches, i.e.
QsysResult< T > qsys_mm1(const T &lambda, const T &mu)
Exact mean response time of the M/M/1 queue.
Definition qsys_mm1.h:35
Number-type abstraction for the templated API port.
Exact mean response time of the M/M/1 queue.