LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
map2_fit_idc.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_MAP2_FIT_IDC_H
6
#define LINE_API_MAM_MAP2_FIT_IDC_H
7
8
/**
9
* @file
10
* @ingroup api_mam
11
* Fit a MAP(2) to three moments and an asymptotic index of dispersion.
12
*
13
* Templated port of matlab/src/api/mam/map2_fit_idc.m, mirrored by the JAR and
14
* native Python.
15
*
16
* A MAP(2) has a geometrically decaying autocorrelation, so its index of
17
* dispersion obeys
18
*
19
* I = SCV + (SCV - 1) g2 / (1 - g2),
20
*
21
* as reported in Section 5.2.2 of Casale, Mi, Cherkasova and Smirni, IEEE Trans.
22
* Soft. Eng. 37(5), 2011. Inverting it in closed form gives
23
* g2 = (I - SCV)/(I - 1), and that decay rate is handed to `map2_fit`, the
24
* explicit inverse characterization of Heindl, Horvath and Gross. A third moment
25
* outside the feasible region is replaced by its lower limit (3/2) e2^2 / e1,
26
* the largest heavy-tail decay a MAP(2) admits.
27
*
28
* THE EXPONENTIAL FALLBACK IS NOT MERELY A FEASIBILITY GUARD, and must not be
29
* relaxed. When SCV <= 1 or I < SCV the reference returns an exponential,
30
* because a flow-equivalent server whose service is exponential and load
31
* dependent is EXACT for a product-form subnetwork by Norton's theorem, whereas
32
* any MAP(2) fitted to the marginal inter-departure statistics is not: the
33
* departure stream of a subnetwork is not independent of the rest of the model.
34
* Fitting the sub-exponential SCV of a non-bursty aggregate was measured to cost
35
* up to 2.2% of throughput on a three-station exponential network that the
36
* exponential fallback reproduces exactly.
37
*
38
* ARITHMETIC: transcendental, inherited from map2_fit.
39
*/
40
41
#include "
line/api/mam/map2_fit.h
"
42
#include "
line/api/mam/map_transform.h
"
43
#include "
line/lang/lang_types.h
"
44
#include "
line/num/number.h
"
45
#include "
line/util/matrix.h
"
46
47
namespace
line
{
48
namespace
mam
{
49
50
/** The fitted process and which of the reference's five outcomes produced it. */
51
template
<
class
T>
52
struct
Map2FitIdcResult
{
53
Map<T>
map
;
54
/**
55
* 0 all four descriptors matched, 1 exponential because the burstiness is
56
* not representable, 2 third moment clamped to its lower limit, 3 third
57
* moment selected automatically, 4 the fit failed and an exponential is
58
* returned.
59
*/
60
int
status
= 0;
61
};
62
63
/**
64
* @brief Fit a MAP(2) to three moments and an asymptotic index of dispersion.
65
*
66
* @param e1 mean inter-arrival time
67
* @param e2 second moment of the inter-arrival times
68
* @param e3 third moment of the inter-arrival times
69
* @param I asymptotic index of dispersion
70
*/
71
template
<
class
T>
72
Map2FitIdcResult<T>
map2_fit_idc
(
const
T& e1,
const
T& e2,
const
T& e3,
const
T& I) {
73
static_assert
(
num_traits<T>::has_transcendental
,
74
"map2_fit_idc inherits map2_fit's arithmetic"
);
75
const
T one =
num_traits<T>::from_int
(1);
76
const
T tol =
num_traits<T>::from_double
(
lang::GlobalConstants::FineTol
);
77
const
T scv = T((e2 - e1 * e1) / (e1 * e1));
78
79
Map2FitIdcResult<T>
out;
80
if
(!(scv > one + tol) || I < scv) {
81
out.
map
=
map_exponential_mean
(e1);
82
out.
status
= 1;
83
return
out;
84
}
85
86
const
T g2 = T((I - scv) / (I - one));
87
Map2FitResult<T>
r =
map2_fit
(e1, e2, e3, g2);
88
if
(r.
err
== 0 && r.
has_map
) {
89
out.
map
= r.
map
;
90
out.
status
= 0;
91
return
out;
92
}
93
94
const
T e3min = T(
num_traits<T>::from_rational
(3, 2) +
num_traits<T>::from_double
(1e-6)) *
95
T(e2 * e2 / e1);
96
if
(e3 < e3min) {
97
r =
map2_fit
(e1, e2, e3min, g2);
98
if
(r.
err
== 0 && r.
has_map
) {
99
out.
map
= r.
map
;
100
out.
status
= 2;
101
return
out;
102
}
103
}
104
105
// -1 is map2_fit's sentinel for "choose the third moment yourself".
106
r =
map2_fit
(e1, e2,
num_traits<T>::from_int
(-1), g2);
107
if
(r.
err
== 0 && r.
has_map
) {
108
out.
map
= r.
map
;
109
out.
status
= 3;
110
return
out;
111
}
112
113
out.
map
=
map_exponential_mean
(e1);
114
out.
status
= 4;
115
return
out;
116
}
117
118
}
// namespace mam
119
}
// namespace line
120
121
#endif
// LINE_API_MAM_MAP2_FIT_IDC_H
lang_types.h
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
map2_fit.h
Explicit inverse characterization of a second-order acyclic MAP (matlab/lib/kpctoolbox/map/map2_fit....
map_transform.h
MAP constructors and structural transformations.
matrix.h
Dense matrix and non-owning view.
line::mam
Definition
amap2_adjust_gamma.h:78
line::mam::map2_fit
Map2FitResult< T > map2_fit(const T &e1, const T &e2, const T &e3_in, const T &g2)
Fit an AMAP(2) to (e1, e2, e3, g2); see the header comment for e3 sentinels.
Definition
map2_fit.h:117
line::mam::map2_fit_idc
Map2FitIdcResult< T > map2_fit_idc(const T &e1, const T &e2, const T &e3, const T &I)
Fit a MAP(2) to three moments and an asymptotic index of dispersion.
Definition
map2_fit_idc.h:72
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
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
line::lang::GlobalConstants::FineTol
static constexpr double FineTol
Definition
lang_types.h:668
line::mam::Map2FitIdcResult
The fitted process and which of the reference's five outcomes produced it.
Definition
map2_fit_idc.h:52
line::mam::Map2FitIdcResult::map
Map< T > map
Definition
map2_fit_idc.h:53
line::mam::Map2FitIdcResult::status
int status
0 all four descriptors matched, 1 exponential because the burstiness is not representable,...
Definition
map2_fit_idc.h:60
line::mam::Map2FitResult
Result of map2_fit: the MAP plus the reference's ERR code.
Definition
map2_fit.h:54
line::mam::Map2FitResult::has_map
bool has_map
false when the characteristics are infeasible
Definition
map2_fit.h:56
line::mam::Map2FitResult::map
Map< T > map
valid only when has_map is true
Definition
map2_fit.h:55
line::mam::Map2FitResult::err
int err
0 ok, -1 fitted but structurally infeasible, else MATLAB ERR
Definition
map2_fit.h:57
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
map2_fit_idc.h
Generated by
1.18.0