LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
fj_cox_fit.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_COX_FIT_H
6
#define LINE_API_FJ_COX_FIT_H
7
8
/**
9
* @file
10
* @ingroup api_fj
11
* Two-stage Coxian fit of a mean and a squared coefficient of variation.
12
*
13
* Templated port of matlab/src/api/fj/fj_cox_fit.m.
14
*
15
* Marie's balanced-stage condition 1/mu1 = q/mu2 closes the system of two
16
* moment equations in three unknowns and gives
17
*
18
* mu1 = 2 mu, q = 1/(2 c2), mu2 = 2 mu q = mu/c2,
19
*
20
* which needs q <= 1, hence c2 >= 0.5. The Erlang stage count representing the
21
* same target is bracketed by ceil(1/c2) <= k <= floor(1/c2) + 1.
22
*/
23
24
#include <cmath>
25
26
#include "
line/api/fj/fj_types.h
"
27
#include "
line/num/number.h
"
28
#include "
line/util/error.h
"
29
30
namespace
line
{
31
namespace
fj
{
32
33
/** [mu1, mu2, q, kmin, kmax] of fj_cox_fit. */
34
template
<
class
T>
35
struct
FJCoxFitResult
{
36
T
mu1
;
37
T
mu2
;
38
T
q
;
39
unsigned
kmin
;
40
unsigned
kmax
;
41
};
42
43
/**
44
* @brief Two-stage Coxian fit of a mean and a squared coefficient of
45
* variation.
46
*
47
* @param m1 target mean, m1 > 0
48
* @param c2 target squared coefficient of variation, c2 >= 0.5
49
* @return the two stage rates, the branching probability and the Erlang bracket
50
*/
51
template
<
class
T>
52
FJCoxFitResult<T>
fj_cox_fit
(
const
T& m1,
const
T& c2) {
53
const
T zero =
num_traits<T>::from_int
(0), one =
num_traits<T>::from_int
(1),
54
two =
num_traits<T>::from_int
(2);
55
if
(!(m1 > zero))
throw
InputError
(
"fj_cox_fit: the target mean must be positive"
);
56
if
(c2 < one / two)
57
throw
InputError
(
"fj_cox_fit: the balanced-stage Coxian fit needs c2 >= 0.5"
);
58
59
const
T mu = one / m1;
60
FJCoxFitResult<T>
out;
61
// Both stages contribute half of the mean
62
out.
mu1
= two * mu;
63
out.
q
= one / (two * c2);
64
out.
mu2
= mu / c2;
65
66
const
double
inv = 1.0 /
num_traits<T>::to_double
(c2);
67
long
lo =
static_cast<
long
>
(std::ceil(inv - 1e-12));
68
long
hi =
static_cast<
long
>
(std::floor(inv + 1e-12)) + 1;
69
if
(lo < 1) lo = 1;
70
if
(hi < lo) hi = lo;
71
out.
kmin
=
static_cast<
unsigned
>
(lo);
72
out.
kmax
=
static_cast<
unsigned
>
(hi);
73
return
out;
74
}
75
76
}
// namespace fj
77
}
// namespace line
78
79
#endif
// LINE_API_FJ_COX_FIT_H
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
error.h
The exception types the port throws.
fj_types.h
Shared return types and arithmetic helpers for the templated fork-join port.
line::fj
Definition
fj_amva.h:34
line::fj::fj_cox_fit
FJCoxFitResult< T > fj_cox_fit(const T &m1, const T &c2)
Two-stage Coxian fit of a mean and a squared coefficient of variation.
Definition
fj_cox_fit.h:52
line
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
line::fj::FJCoxFitResult
[mu1, mu2, q, kmin, kmax] of fj_cox_fit.
Definition
fj_cox_fit.h:35
line::fj::FJCoxFitResult::kmax
unsigned kmax
Definition
fj_cox_fit.h:40
line::fj::FJCoxFitResult::mu1
T mu1
Definition
fj_cox_fit.h:36
line::fj::FJCoxFitResult::mu2
T mu2
Definition
fj_cox_fit.h:37
line::fj::FJCoxFitResult::q
T q
Definition
fj_cox_fit.h:38
line::fj::FJCoxFitResult::kmin
unsigned kmin
Definition
fj_cox_fit.h:39
line::num_traits
Definition
number.h:111
include
line
api
fj
fj_cox_fit.h
Generated by
1.18.0