LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
sn_get_refstat_chain.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_SN_SN_GET_REFSTAT_CHAIN_H
6#define LINE_API_SN_SN_GET_REFSTAT_CHAIN_H
7
8/**
9 * @file
10 * @ingroup api_sn
11 * The visit-normalization anchor station of each chain.
12 *
13 * Port of matlab/src/api/sn/sn_get_refstat_chain.m.
14 *
15 * TWO NOTIONS THAT USED TO BE ONE. Classes within a chain may each declare
16 * their own reference station, `classes[k].refstat`: the station at which that
17 * CLASS's throughput X(k) = T(refstat(k),k) and cycle time C(k) = N(k)/X(k) are
18 * observed. Chain-level quantities, by contrast, need a single station to gauge
19 * the chain visit ratios against, because Vchain is defined only up to a scale
20 * factor. This function fixes that gauge, so that every consumer of Vchain,
21 * Lchain, Xchain and Cchain agrees on where the chain is being measured.
22 *
23 * The anchor is the reference class's station when the chain declares a
24 * reference class (`refclass[c] > 0`), and otherwise the station of the chain's
25 * first class. Per-station metrics (Q, U, R, T) are invariant to this choice;
26 * the chain system throughput Xchain and cycle time Cchain are reported at it.
27 *
28 * INDEXING: every index here is 1-based, as the struct stores them -- class
29 * indices in `inchain`, the class in `refclass` (0 = none) and the stations in
30 * `refstat` and in the result. An empty chain yields 0, as the reference does.
31 *
32 * The header is included by network_struct.h itself (the visit refresh
33 * normalizes at the anchor), so it only forward-declares the struct.
34 */
35
36#include <cstddef>
37#include <vector>
38
39namespace line {
40namespace qn {
41template <class T>
42class NetworkStruct;
43} // namespace qn
44
45namespace api {
46
47/**
48 * @brief Anchor station of each chain, from plain per-class/per-chain vectors.
49 *
50 * @param refstat (K) 1-based reference station of each class
51 * @param refclass (C) 1-based reference class of each chain, 0 = none; may be
52 * shorter than `inchain` (missing entries read as none)
53 * @param inchain (C) 1-based class indices of each chain
54 * @return (C) 1-based anchor station of each chain, 0 for an empty chain
55 */
56inline std::vector<std::size_t> sn_get_refstat_chain(const std::vector<std::size_t>& refstat,
57 const std::vector<std::size_t>& refclass,
58 const std::vector<std::vector<std::size_t> >& inchain) {
59 const std::size_t C = inchain.size();
60 std::vector<std::size_t> out(C, 0);
61 for (std::size_t c = 0; c < C; ++c) {
62 if (inchain[c].empty()) continue;
63 const std::size_t k = (c < refclass.size() && refclass[c] > 0) ? refclass[c] : inchain[c][0];
64 out[c] = (k >= 1 && k <= refstat.size()) ? refstat[k - 1] : 0;
65 }
66 return out;
67}
68
69/**
70 * @brief Anchor station of each chain, port of `sn_get_refstat_chain(sn, inchain)`.
71 *
72 * @param sn the network structure (its `classes[k].refstat` and `refclass` are read)
73 * @param inchain (C) 1-based class indices per chain; the struct's own when omitted
74 * @return (C) 1-based anchor station of each chain, 0 for an empty chain
75 */
76template <class T>
77std::vector<std::size_t> sn_get_refstat_chain(const qn::NetworkStruct<T>& sn,
78 const std::vector<std::vector<std::size_t> >& inchain) {
79 std::vector<std::size_t> refstat(sn.classes.size(), 0);
80 for (std::size_t k = 0; k < sn.classes.size(); ++k) refstat[k] = sn.classes[k].refstat;
81 return sn_get_refstat_chain(refstat, sn.refclass, inchain);
82}
83
84/** @overload, over the struct's own `inchain`. */
85template <class T>
86std::vector<std::size_t> sn_get_refstat_chain(const qn::NetworkStruct<T>& sn) {
87 return sn_get_refstat_chain(sn, sn.inchain);
88}
89
90} // namespace api
91} // namespace line
92
93#endif // LINE_API_SN_SN_GET_REFSTAT_CHAIN_H
A network plus its refreshed NetworkStruct.
std::vector< std::size_t > sn_get_refstat_chain(const std::vector< std::size_t > &refstat, const std::vector< std::size_t > &refclass, const std::vector< std::vector< std::size_t > > &inchain)
Anchor station of each chain, from plain per-class/per-chain vectors.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51