LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
amap2_fit_gamma.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_MAM_AMAP2_FIT_GAMMA_H
6
#define LINE_API_MAM_AMAP2_FIT_GAMMA_H
7
8
/**
9
* @file
10
* @ingroup api_mam
11
* AMAP(2) fit of three moments and the autocorrelation decay rate
12
* (matlab/lib/m3a/m3a/amap2/amap2_fit_gamma.m).
13
*
14
* A unit SCV short-circuits to a Poisson process, since the AMAP(2) canonical
15
* forms are degenerate there. Otherwise every exact solution is enumerated
16
* with amap2_fitall_gamma, normalized, and the first is returned.
17
*
18
* Not ported: the reference's approximate branch, which calls
19
* amap2_adjust_gamma to relax (M2, M3, GAMMA) into the feasible region. All
20
* four of its methods are driven by patternsearch / PSwarm / fmincon, so there
21
* is no closed form to port. When no exact solution exists this port takes the
22
* same final fallback as the in-tree MATLAB does when adjustment fails: a
23
* Poisson process matching the mean, flagged through Amap2FitGammaResult.
24
*
25
* Gated on transcendental arithmetic through amap2_fitall_gamma.
26
*/
27
28
#include <vector>
29
30
#include "
line/api/mam/amap2_fitall_gamma.h
"
31
#include "
line/api/mam/map_moment.h
"
32
#include "
line/api/mam/map_transform.h
"
33
#include "
line/num/number.h
"
34
35
namespace
line
{
36
namespace
mam
{
37
38
/** Result of amap2_fit_gamma. */
39
template
<
class
T>
40
struct
Amap2FitGammaResult
{
41
Map<T>
amap
;
///< the selected fit
42
std::vector<Map<T>>
amaps
;
///< every exact solution found
43
bool
poisson_fallback
;
///< true when no exact AMAP(2) exists (or SCV == 1)
44
};
45
46
/**
47
* Fit an AMAP(2) to (M1, M2, M3, GAMMA). cvtol is the tolerance on
48
* |M2 - 2 M1^2| below which the Poisson short-circuit fires (MATLAB 1e-6).
49
*/
50
template
<
class
T>
51
Amap2FitGammaResult<T>
amap2_fit_gamma
(
const
T& M1,
const
T& M2,
const
T& M3,
const
T& GAMMA,
52
const
T& cvtol) {
53
static_assert
(
num_traits<T>::has_transcendental
,
54
"amap2_fit_gamma requires transcendental arithmetic"
);
55
const
T two =
num_traits<T>::from_int
(2);
56
Amap2FitGammaResult<T>
r;
57
r.
poisson_fallback
=
false
;
58
59
if
(
num_abs
(T(M2 - two * M1 * M1)) < cvtol) {
60
r.
amap
=
map_exponential_mean
(M1);
61
r.
amaps
.push_back(r.
amap
);
62
r.
poisson_fallback
=
true
;
63
return
r;
64
}
65
66
std::vector<Map<T>> all =
amap2_fitall_gamma
(M1, M2, M3, GAMMA);
67
for
(std::size_t j = 0; j < all.size(); ++j) all[j] =
map_normalize
(all[j]);
68
r.
amaps
= all;
69
70
if
(r.
amaps
.empty()) {
71
r.
amap
=
map_exponential_mean
(M1);
72
r.
amaps
.push_back(r.
amap
);
73
r.
poisson_fallback
=
true
;
74
return
r;
75
}
76
r.
amap
= r.
amaps
.front();
77
return
r;
78
}
79
80
/** amap2_fit_gamma with the MATLAB default cvtol = 1e-6. */
81
template
<
class
T>
82
Amap2FitGammaResult<T>
amap2_fit_gamma
(
const
T& M1,
const
T& M2,
const
T& M3,
const
T& GAMMA) {
83
return
amap2_fit_gamma
(M1, M2, M3, GAMMA, T(
num_traits<T>::from_double
(1e-6)));
84
}
85
86
}
// namespace mam
87
}
// namespace line
88
89
#endif
// LINE_API_MAM_AMAP2_FIT_GAMMA_H
amap2_fitall_gamma.h
All AMAP(2) representations matching three moments and the autocorrelation decay rate (matlab/lib/m3a...
map_moment.h
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
map_transform.h
MAP constructors and structural transformations.
line::mam
Definition
amap2_adjust_gamma.h:78
line::mam::amap2_fit_gamma
Amap2FitGammaResult< T > amap2_fit_gamma(const T &M1, const T &M2, const T &M3, const T &GAMMA, const T &cvtol)
Fit an AMAP(2) to (M1, M2, M3, GAMMA).
Definition
amap2_fit_gamma.h:51
line::mam::map_exponential_mean
Map< T > map_exponential_mean(const T &mean)
Poisson process with the given mean inter-arrival time (map_exponential.m).
Definition
map_transform.h:118
line::mam::map_normalize
Map< T > map_normalize(const Map< T > &in)
Clamp negative off-diagonal entries of D0 and negative entries of D1 to zero, then rebuild the diagon...
Definition
map_transform.h:53
line::mam::amap2_fitall_gamma
std::vector< Map< T > > amap2_fitall_gamma(const T &M1, const T &M2, const T &M3, const T &GAMMA, const T °entol, const T &r12tol)
Every AMAP(2) matching (M1, M2, M3, GAMMA).
Definition
amap2_fitall_gamma.h:48
line
Definition
aoi_dist2ph.h:52
line::num_abs
T num_abs(const T &v)
Definition
number.h:172
number.h
Number-type abstraction for the templated API port.
line::mam::Amap2FitGammaResult
Result of amap2_fit_gamma.
Definition
amap2_fit_gamma.h:40
line::mam::Amap2FitGammaResult::poisson_fallback
bool poisson_fallback
true when no exact AMAP(2) exists (or SCV == 1)
Definition
amap2_fit_gamma.h:43
line::mam::Amap2FitGammaResult::amap
Map< T > amap
the selected fit
Definition
amap2_fit_gamma.h:41
line::mam::Amap2FitGammaResult::amaps
std::vector< Map< T > > amaps
every exact solution found
Definition
amap2_fit_gamma.h:42
line::mam::Map
A MAP as the pair of matrices (D0, D1).
Definition
map_moment.h:53
line::num_traits
Definition
number.h:111
include
line
api
mam
amap2_fit_gamma.h
Generated by
1.18.0