LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
map_mark.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_MAP_MARK_H
6#define LINE_API_MAM_MAP_MARK_H
7
8/**
9 * @file
10 * @ingroup api_mam
11 * Mark the arrivals of a MAP with class probabilities
12 * (matlab/lib/kpctoolbox/map/map_mark.m).
13 *
14 * The unmarked inter-arrival process is unchanged: Dc = prob(c) * D1, so the
15 * class of an arrival is drawn independently of the phase. This is the
16 * phase-independent special case of mmap_mark in mmap_lambda.h, which takes a
17 * per-phase weight matrix instead.
18 *
19 * MATLAB warns and renormalizes when the probabilities do not sum to one;
20 * this port renormalizes silently but rejects a non-positive total, since a
21 * zero total has no meaningful normalization. Pure field arithmetic, exact at
22 * Rational: no transcendental gate.
23 */
24
25#include <vector>
26
29#include "line/num/number.h"
30#include "line/util/error.h"
31#include "line/util/matrix.h"
32
33namespace line {
34namespace mam {
35
36/** MMAP with the same inter-arrival process and arrivals marked by prob. */
37template <class T>
38Mmap<T> map_mark(const Map<T>& m, const std::vector<T>& prob) {
39 const T zero = num_traits<T>::from_int(0);
40 if (prob.empty()) throw InputError("map_mark: empty marking probabilities");
41 T s = zero;
42 for (const T& p : prob) {
43 if (p < zero) throw InputError("map_mark: negative marking probability");
44 s += p;
45 }
46 if (s == zero) throw InputError("map_mark: marking probabilities sum to zero");
47 Mmap<T> out;
48 out.D0 = m.D0;
49 out.D1 = m.D1;
50 for (std::size_t c = 0; c < prob.size(); ++c) {
51 Matrix<T> Dc(m.D1.rows(), m.D1.cols());
52 const T w = prob[c] / s;
53 for (std::size_t i = 0; i < Dc.rows(); ++i)
54 for (std::size_t j = 0; j < Dc.cols(); ++j) Dc(i, j) = w * m.D1(i, j);
55 out.Dc.push_back(Dc);
56 }
57 return mmap_normalize(out);
58}
59
60} // namespace mam
61} // namespace line
62
63#endif // LINE_API_MAM_MAP_MARK_H
InputError(const std::string &what)
Definition error.h:39
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
The exception types the port throws.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
Marked MAP (MMAP) algebra: per-class rates, class probabilities, superposition, normalization and sca...
Mmap< T > mmap_normalize(const Mmap< T > &in)
Clamp negative off-diagonal and per-class entries to zero and rebuild D1 and the diagonal of D0 from ...
Mmap< T > map_mark(const Map< T > &m, const std::vector< T > &prob)
MMAP with the same inter-arrival process and arrivals marked by prob.
Definition map_mark.h:38
Number-type abstraction for the templated API port.
A MAP as the pair of matrices (D0, D1).
Definition map_moment.h:53
Matrix< T > D1
Definition map_moment.h:55
Matrix< T > D0
Definition map_moment.h:54
An MMAP: the underlying MAP plus the per-class arrival matrices.
Definition mmap_lambda.h:45
Matrix< T > D0
Definition mmap_lambda.h:46
Matrix< T > D1
Definition mmap_lambda.h:47
std::vector< Matrix< T > > Dc
per-class matrices, sum_c Dc = D1
Definition mmap_lambda.h:48