LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
fj_xmax_2.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_XMAX_2_H
6#define LINE_API_FJ_XMAX_2_H
7
8/**
9 * @file
10 * @ingroup api_fj
11 * Expected maximum of two independent, possibly unequal-rate exponentials.
12 *
13 * Templated port of matlab/src/api/fj/fj_xmax_2.m, cross-checked against
14 * FJ_xmax.fj_xmax_2 in jar/src/main/java/jline/api/fj/FJ_xmax.java
15 * (identical).
16 *
17 * Y_2^max = 1/lambda1 + 1/lambda2 - 1/(lambda1 + lambda2)
18 *
19 * Rational, hence exact in the field. At lambda1 = lambda2 = mu it collapses
20 * to (3/2)/mu = H_2/mu, which is fj_xmax_exp at K = 2.
21 */
22
24#include "line/num/number.h"
25#include "line/util/error.h"
26
27namespace line {
28namespace fj {
29
30/**
31 * @brief Expected maximum of two independent, possibly unequal-rate
32 * exponentials.
33 *
34 * @param lambda1 rate of the first branch, > 0
35 * @param lambda2 rate of the second branch, > 0
36 * @return expected maximum of the two exponentials
37 */
38template <class T>
39T fj_xmax_2(const T& lambda1, const T& lambda2) {
40 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
41 if (lambda1 <= zero || lambda2 <= zero) throw InputError("fj_xmax_2: the rates must be positive");
42 return one / lambda1 + one / lambda2 - one / (lambda1 + lambda2);
43}
44
45/** Equal-rate overload, matching MATLAB's single-argument call. */
46template <class T>
47T fj_xmax_2(const T& lambda) {
48 return fj_xmax_2(lambda, lambda);
49}
50
51} // namespace fj
52} // namespace line
53
54#endif // LINE_API_FJ_XMAX_2_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_xmax_2(const T &lambda1, const T &lambda2)
Expected maximum of two independent, possibly unequal-rate exponentials.
Definition fj_xmax_2.h:39
Number-type abstraction for the templated API port.