LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
mtrace_split.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_TRACE_MTRACE_SPLIT_H
6
#define LINE_API_TRACE_MTRACE_SPLIT_H
7
8
/**
9
* @file
10
* @ingroup api_trace
11
* Splits a marked trace into its per-class traces: for each class, the
12
* inter-arrival times BETWEEN CONSECUTIVE EVENTS OF THAT CLASS, with the
13
* first interval measured from the origin.
14
*
15
* Templated port of matlab/lib/m3a/m3a/mtrace/mtrace_split.m, cross-checked
16
* against jar/src/main/java/jline/api/trace/Mtrace_split.java (identical:
17
* both prepend a zero epoch before differencing).
18
*
19
* The per-class traces partition the arrivals, and the sum of every class
20
* trace equals the epoch of that class's last event, so the sum over classes
21
* of the class sums is generally NOT the trace length.
22
*
23
* ARITHMETIC: cumulative sums and differences, exact in Rational.
24
*/
25
26
#include <cstddef>
27
#include <vector>
28
29
#include "
line/api/trace/trace_types.h
"
30
#include "
line/num/number.h
"
31
#include "
line/util/error.h
"
32
33
namespace
line
{
34
namespace
trace
{
35
36
/** Return value of mtrace_split. */
37
template
<
class
T>
38
struct
MtraceSplitResult
{
39
std::vector<int>
labels
;
///< the distinct labels, increasing
40
std::vector<std::vector<T>>
traces
;
///< per-class inter-arrival times
41
};
42
43
/**
44
* @brief Splits a marked trace into its per-class traces: for each class, the
45
* inter-arrival times BETWEEN CONSECUTIVE EVENTS OF THAT CLASS, with
46
* the first interval measured from the origin.
47
*
48
* @param Tv inter-arrival times of the marked process
49
* @param L class labels
50
*/
51
template
<
class
T>
52
MtraceSplitResult<T>
mtrace_split
(
const
std::vector<T>& Tv,
const
std::vector<int>& L) {
53
detail::require_marked(Tv, L,
"mtrace_split"
);
54
MtraceSplitResult<T>
out;
55
out.
labels
= detail::unique_labels(L);
56
const
std::vector<T> cs = detail::cumsum0(Tv);
// cs[k] = epoch of event k
57
out.
traces
.resize(out.
labels
.size());
58
for
(std::size_t c = 0; c < out.
labels
.size(); ++c) {
59
T prev =
num_traits<T>::from_int
(0);
60
for
(std::size_t i = 0; i < L.size(); ++i) {
61
if
(L[i] != out.
labels
[c])
continue
;
62
const
T epoch = cs[i + 1];
63
out.
traces
[c].push_back(epoch - prev);
64
prev = epoch;
65
}
66
}
67
return
out;
68
}
69
70
}
// namespace trace
71
}
// namespace line
72
73
#endif
// LINE_API_TRACE_MTRACE_SPLIT_H
error.h
The exception types the port throws.
line::trace
Definition
autocov.h:38
line::trace::mtrace_split
MtraceSplitResult< T > mtrace_split(const std::vector< T > &Tv, const std::vector< int > &L)
Splits a marked trace into its per-class traces: for each class, the inter-arrival times BETWEEN CONS...
Definition
mtrace_split.h:52
line
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
line::num_traits
Definition
number.h:111
line::trace::MtraceSplitResult
Return value of mtrace_split.
Definition
mtrace_split.h:38
line::trace::MtraceSplitResult::traces
std::vector< std::vector< T > > traces
per-class inter-arrival times
Definition
mtrace_split.h:40
line::trace::MtraceSplitResult::labels
std::vector< int > labels
the distinct labels, increasing
Definition
mtrace_split.h:39
trace_types.h
Shared declarations for the empirical trace statistics domain.
include
line
api
trace
mtrace_split.h
Generated by
1.18.0