LINE Solver (C++)
Templated C++ port of the LINE queueing solver
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
30#include "line/num/number.h"
31#include "line/util/error.h"
32
33namespace line {
34namespace trace {
35
36/** Return value of mtrace_split. */
37template <class T>
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 */
51template <class T>
52MtraceSplitResult<T> mtrace_split(const std::vector<T>& Tv, const std::vector<int>& L) {
53 detail::require_marked(Tv, L, "mtrace_split");
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
The exception types the port throws.
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...
Number-type abstraction for the templated API port.
Return value of mtrace_split.
std::vector< std::vector< T > > traces
per-class inter-arrival times
std::vector< int > labels
the distinct labels, increasing
Shared declarations for the empirical trace statistics domain.