LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
pfqn_expand.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_PFQN_EXPAND_H
6#define LINE_API_PFQN_EXPAND_H
7
8/**
9 * @file
10 * @ingroup api_pfqn
11 * Expand per-station metrics from a reduced model back to the original
12 * station set.
13 *
14 * Templated port of matlab/src/api/pfqn/pfqn_expand.m. The inverse of
15 * pfqn_unique: row i of each output is row mapping(i) of the corresponding
16 * input, so every station of a replicated group receives the metrics computed
17 * once for its representative.
18 *
19 * Arithmetic: EXACT-CAPABLE. The routine copies values and performs no
20 * arithmetic at all, so it is exact in every arithmetic by construction and
21 * carries no transcendental gate.
22 */
23
24#include <cstddef>
25#include <vector>
26
27#include "line/num/number.h"
28#include "line/util/error.h"
29#include "line/util/matrix.h"
30
31namespace line {
32namespace pfqn {
33
34/** Return value of pfqn_expand, mirroring [QN_full,UN_full,CN_full]. */
35template <class T>
37 Matrix<T> QN; ///< (M x R) queue lengths at the original stations
38 Matrix<T> UN; ///< (M x R) utilizations
39 Matrix<T> CN; ///< (M x R) residence times
40};
41
42/**
43 * @brief Expand per-station metrics from a reduced model back to the original
44 * station set.
45 *
46 * @param QN (M' x R) reduced queue lengths
47 * @param UN (M' x R) reduced utilizations
48 * @param CN (M' x R) reduced residence times
49 * @param mapping (M) 0-based unique-station index per original station
50 */
51template <class T>
53 const std::vector<std::size_t>& mapping) {
54 const std::size_t R = QN.cols();
55 const std::size_t M = mapping.size();
56 if (UN.rows() != QN.rows() || CN.rows() != QN.rows() || UN.cols() != R || CN.cols() != R)
57 throw InputError("pfqn_expand: the three metric matrices have different shapes");
58
60 res.QN = Matrix<T>(M, R);
61 res.UN = Matrix<T>(M, R);
62 res.CN = Matrix<T>(M, R);
63 for (std::size_t i = 0; i < M; ++i) {
64 const std::size_t u = mapping[i];
65 if (u >= QN.rows()) throw InputError("pfqn_expand: mapping index out of range");
66 for (std::size_t j = 0; j < R; ++j) {
67 res.QN(i, j) = QN(u, j);
68 res.UN(i, j) = UN(u, j);
69 res.CN(i, j) = CN(u, j);
70 }
71 }
72 return res;
73}
74
75} // namespace pfqn
76} // namespace line
77
78#endif // LINE_API_PFQN_EXPAND_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.
Dense matrix and non-owning view.
ExpandResult< T > pfqn_expand(const Matrix< T > &QN, const Matrix< T > &UN, const Matrix< T > &CN, const std::vector< std::size_t > &mapping)
Expand per-station metrics from a reduced model back to the original station set.
Definition pfqn_expand.h:52
Number-type abstraction for the templated API port.
Return value of pfqn_expand, mirroring [QN_full,UN_full,CN_full].
Definition pfqn_expand.h:36
Matrix< T > CN
(M x R) residence times
Definition pfqn_expand.h:39
Matrix< T > QN
(M x R) queue lengths at the original stations
Definition pfqn_expand.h:37
Matrix< T > UN
(M x R) utilizations
Definition pfqn_expand.h:38