LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
sn_has_classdep_routing.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_HAS_CLASSDEP_ROUTING_H
6#define LINE_API_SN_SN_HAS_CLASSDEP_ROUTING_H
7
8/**
9 * @file
10 * @ingroup api_sn
11 * Port of matlab/src/api/sn/sn_has_classdep_routing.m.
12 *
13 * True when the routing depends on the class: either some edge switches class
14 * (an off-diagonal (r,s) block entry) or two classes leave the same pair (i,j)
15 * with different probabilities. SolverMVA reads it to decide whether a
16 * per-chain aggregate routing is faithful, so a false negative aggregates a
17 * class-dependent model and returns a chain answer for a class question.
18 *
19 * INDEX SPACE. The reference walks i and j over STATIONS while indexing `sn.rt`,
20 * which is over STATEFUL NODES. The two coincide unless the model has a
21 * stateful non-station node (a Router, a Cache), and this port reproduces the
22 * reference walk rather than correcting it: the predicate gates a dispatch
23 * branch, and answering it on a different index space would send models down a
24 * different path here than in every other codebase.
25 *
26 * ARITHMETIC: field. Comparisons only.
27 */
28
29#include <cmath>
30#include <cstddef>
31
33#include "line/num/number.h"
34
35namespace line {
36namespace api {
37
38template <class T>
40 const std::size_t K = sn.nclasses, M = sn.nstations;
41 if (K <= 1) return false;
42 const double tol = qn::GlobalConstants::FineTol;
43 const std::size_t dim = sn.rt.rows();
44 for (std::size_t i = 0; i < M; ++i)
45 for (std::size_t j = 0; j < M; ++j) {
46 bool have_shared = false;
47 double shared = 0.0;
48 for (std::size_t r = 0; r < K; ++r) {
49 for (std::size_t s = 0; s < K; ++s) {
50 if (r == s) continue;
51 const std::size_t a = i * K + r, b = j * K + s;
52 if (a >= dim || b >= dim) continue;
53 if (num_traits<T>::to_double(sn.rt(a, b)) > tol) return true;
54 }
55 const std::size_t a = i * K + r, b = j * K + r;
56 if (a >= dim || b >= dim) continue;
57 const double p = num_traits<T>::to_double(sn.rt(a, b));
58 if (!have_shared) {
59 shared = p;
60 have_shared = true;
61 } else if (std::fabs(p - shared) > tol) {
62 return true;
63 }
64 }
65 }
66 return false;
67}
68
69} // namespace api
70} // namespace line
71
72#endif // LINE_API_SN_SN_HAS_CLASSDEP_ROUTING_H
A network plus its refreshed NetworkStruct.
bool sn_has_classdep_routing(const qn::NetworkStruct< T > &sn)
A queueing network and its refreshed NetworkStruct.
Number-type abstraction for the templated API port.
static constexpr double FineTol
Definition lang_types.h:668