LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
fj_gk_bound.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_GK_BOUND_H
6#define LINE_API_FJ_GK_BOUND_H
7
8/**
9 * @file
10 * @ingroup api_fj
11 * G(K) factors for the standardized-maximum approximation X_K^max ~ mu + sigma G(K).
12 *
13 * Templated port of matlab/src/api/fj/fj_gk_bound.m. The JAR carries the same
14 * four values in jline.api.fj.GKBoundResult, computed inside
15 * FJ_xmax.fj_xmax_approx (identical formulas).
16 *
17 * exponential: G(K) = H_K - 1
18 * uniform: G(K) = sqrt(3) (K-1)/(K+1)
19 * evd: G(K) = sqrt(6) ln(K) / pi
20 * upper bound: G(K) = (K-1)/sqrt(2K-1) (David 1970)
21 *
22 * static_assert(num_traits<T>::has_transcendental) -- three of the four
23 * involve sqrt or log, so the struct as a whole is only defined for the
24 * inexact number types. The exponential entry alone is rational and is
25 * reachable exactly through fj_harmonic.
26 */
27
30#include "line/num/number.h"
31#include "line/util/error.h"
32
33namespace line {
34namespace fj {
35
36/**
37 * @brief G(K) factors for the standardized-maximum approximation X_K^max ~ mu
38 * + sigma G(K).
39 *
40 * @param K number of branches, K >= 1
41 * @return all four G(K) factors, matching MATLAB's 'all' mode
42 */
43template <class T>
46 "fj_gk_bound requires transcendental arithmetic");
47 detail::require_positive_K(K, "fj_gk_bound");
48 const T one = num_traits<T>::from_int(1);
49 const T Kt = num_traits<T>::from_int(static_cast<long>(K));
51 r.K = K;
52 r.exponential = fj_harmonic<T>(K) - one;
53 r.uniform = detail::num_sqrt(T(num_traits<T>::from_int(3))) * (Kt - one) / (Kt + one);
54 r.evd = detail::num_sqrt(T(num_traits<T>::from_int(6))) * detail::num_log(Kt) / detail::num_pi<T>();
55 r.upper_bound = (Kt - one) / detail::num_sqrt(T(num_traits<T>::from_int(2) * Kt - one));
56 return r;
57}
58
59/** Single-family accessor, matching MATLAB's 'exp'/'uniform'/'evd'/'bound' modes. */
60template <class T>
61T fj_gk_bound(unsigned K, FJDistType type) {
63 switch (type) {
64 case FJDistType::Exp: return all.exponential;
65 case FJDistType::Uniform: return all.uniform;
66 case FJDistType::Evd: return all.evd;
67 case FJDistType::Bound: return all.upper_bound;
68 }
69 throw InputError("fj_gk_bound: unknown distribution type");
70}
71
72} // namespace fj
73} // namespace line
74
75#endif // LINE_API_FJ_GK_BOUND_H
InputError(const std::string &what)
Definition error.h:39
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.
FJGKBoundResult< T > fj_gk_bound(unsigned K)
G(K) factors for the standardized-maximum approximation X_K^max ~ mu.
Definition fj_gk_bound.h:44
FJDistType
Distribution families for which a G(K) standardized-maximum factor exists.
Definition fj_types.h:41
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.
All four G(K) factors of fj_gk_bound in its 'all' mode.
Definition fj_types.h:62