LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
fj_rmax_evd.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_RMAX_EVD_H
6#define LINE_API_FJ_RMAX_EVD_H
7
8/**
9 * @file
10 * @ingroup api_fj
11 * Extreme-value approximation to the maximum of K branch response times, from
12 * their mean and standard deviation.
13 *
14 * Templated port of matlab/src/api/fj/fj_rmax_evd.m, cross-checked against
15 * FJ_rmax.fj_rmax_evd in jar/src/main/java/jline/api/fj/FJ_rmax.java
16 * (identical).
17 *
18 * Rmax = R + (sqrt(6) ln K / pi) sigma_R
19 *
20 * with the correction term divided by 1.27 in the calibrated variant of
21 * Thomasian et al. (2007).
22 *
23 * static_assert(num_traits<T>::has_transcendental) -- sqrt and log. Note that
24 * at K = 1 the correction vanishes and Rmax = R exactly, which is the only
25 * value of K at which the approximation is exact.
26 */
27
29#include "line/num/number.h"
30#include "line/util/error.h"
31
32namespace line {
33namespace fj {
34
35/**
36 * @brief Extreme-value approximation to the maximum of K branch response
37 * times, from their mean and standard deviation.
38 *
39 * @param K number of branches, K >= 1
40 * @param R mean branch response time, > 0
41 * @param sigma_R standard deviation of the branch response time, >= 0
42 * @param calibrated apply the 1/1.27 calibration of Thomasian et al. (2007)
43 */
44template <class T>
45T fj_rmax_evd(unsigned K, const T& R, const T& sigma_R, bool calibrated = false) {
47 "fj_rmax_evd requires transcendental arithmetic");
48 detail::require_positive_K(K, "fj_rmax_evd");
49 if (R <= num_traits<T>::from_int(0)) throw InputError("fj_rmax_evd: the mean response time R must be positive");
50 if (sigma_R < num_traits<T>::from_int(0)) throw InputError("fj_rmax_evd: sigma_R must be non-negative");
51
52 const T Kt = num_traits<T>::from_int(static_cast<long>(K));
53 T corr = detail::num_sqrt(T(num_traits<T>::from_int(6))) * detail::num_log(Kt) / detail::num_pi<T>();
54 if (calibrated) corr /= num_traits<T>::from_double(1.27);
55 return R + corr * sigma_R;
56}
57
58} // namespace fj
59} // namespace line
60
61#endif // LINE_API_FJ_RMAX_EVD_H
InputError(const std::string &what)
Definition error.h:39
The exception types the port throws.
Shared return types and arithmetic helpers for the templated fork-join port.
T fj_rmax_evd(unsigned K, const T &R, const T &sigma_R, bool calibrated=false)
Extreme-value approximation to the maximum of K branch response times, from their mean and standard d...
Definition fj_rmax_evd.h:45
Number-type abstraction for the templated API port.