LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
sn_schedule_nominal.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_SCHEDULE_NOMINAL_H
6#define LINE_API_SN_SN_SCHEDULE_NOMINAL_H
7
8/**
9 * @file
10 * @ingroup api_sn
11 * Port of `matlab/src/api/sn/sn_schedule_nominal.m`: unpack the MAPt or PHt slot
12 * of `sn.proc` at one (station, class) into the per-segment (D0, D1) pairs and
13 * their width-weighted time average.
14 *
15 * IT IS AN ACCESSOR HERE AND A DECODER THERE, and the difference is where the
16 * conversion happens. MATLAB stores the slot as `{breakpoints, A, B, cyclic}`
17 * with A and B holding (D0, D1) for a MAPt and (alpha, S) for a PHt, so every
18 * reader must know which family it is looking at and rebuild the MAP pair
19 * (S, (-S e) alpha) itself. This port converts a PHt ONCE, in
20 * `Distrib::pht`, so what is stored is always the MAP schedule and every reader
21 * sees one representation. The nominal pair is likewise computed once, in the
22 * constructor, and lives in `Distrib::D0` / `D1` where a time-blind consumer --
23 * the phase count, `sn.rates`, the fluid layout -- already looks for it.
24 *
25 * What is left for this function is the CONTRACT: return the same six outputs
26 * the reference returns, and refuse a (station, class) that carries no schedule
27 * rather than inventing a one-segment one. A caller that wants the nominal of an
28 * ordinary process reads `sn.service[i][r].D0` directly, which is what the
29 * reference's own `nomD0`/`nomD1` fallback does.
30 */
31
32#include <cstddef>
33#include <vector>
34
37#include "line/num/number.h"
38#include "line/util/error.h"
39#include "line/util/matrix.h"
40
41namespace line {
42namespace sn {
43
44/** What `sn_schedule_nominal` returns, in the reference's own output order. */
45template <class T>
47 Matrix<T> D0bar, D1bar; ///< the width-weighted time average
48 std::vector<T> breakpoints; ///< the boundary vector, nseg + 1 long
49 std::vector<Matrix<T> > segD0; ///< per-segment D0, already in MAP form
50 std::vector<Matrix<T> > segD1; ///< per-segment D1
51 bool cyclic = false;
52};
53
54/** True when (ist, r) carries a MAPt / PHt / NHPP schedule. Both 0-based. */
55template <class T>
56bool sn_has_schedule(const qn::NetworkStruct<T>& sn, std::size_t ist, std::size_t r) {
57 if (ist >= sn.service.size() || r >= sn.service[ist].size()) return false;
58 return sn.service[ist][r].has_schedule();
59}
60
61/** Port of `sn_schedule_nominal(sn, ist, r)`; `ist` and `r` are 0-based here. */
62template <class T>
64 std::size_t r) {
65 if (!sn_has_schedule(sn, ist, r))
66 throw InputError("sn_schedule_nominal: station " + std::to_string(ist + 1) + ", class " +
67 std::to_string(r + 1) +
68 " carries no MAPt/PHt schedule; read sn.service[i][r].D0 for an "
69 "ordinary process");
70 const lang::Distrib<T>& d = sn.service[ist][r];
72 out.D0bar = d.D0;
73 out.D1bar = d.D1;
74 out.breakpoints = d.sched_bp;
75 out.segD0 = d.sched_D0;
76 out.segD1 = d.sched_D1;
77 out.cyclic = d.sched_cyclic;
78 return out;
79}
80
81} // namespace sn
82} // namespace line
83
84#endif // LINE_API_SN_SN_SCHEDULE_NOMINAL_H
InputError(const std::string &what)
Definition error.h:39
A network plus its refreshed NetworkStruct.
The exception types the port throws.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
Dense matrix and non-owning view.
ScheduleNominal< T > sn_schedule_nominal(const qn::NetworkStruct< T > &sn, std::size_t ist, std::size_t r)
Port of sn_schedule_nominal(sn, ist, r); ist and r are 0-based here.
bool sn_has_schedule(const qn::NetworkStruct< T > &sn, std::size_t ist, std::size_t r)
True when (ist, r) carries a MAPt / PHt / NHPP schedule.
A queueing network and its refreshed NetworkStruct.
Number-type abstraction for the templated API port.
Matrix< T > D0
The (D0,D1) pair when the type carries one directly.
Definition lang_types.h:759
std::vector< T > sched_bp
sn.proc{i}{r} = {breakpoints, A, B, cyclic} of a MAPt / PHt / NHPP.
Definition lang_types.h:794
std::vector< Matrix< T > > sched_D1
Definition lang_types.h:795
std::vector< Matrix< T > > sched_D0
Definition lang_types.h:795
What sn_schedule_nominal returns, in the reference's own output order.
Matrix< T > D1bar
the width-weighted time average
std::vector< Matrix< T > > segD1
per-segment D1
std::vector< T > breakpoints
the boundary vector, nseg + 1 long
std::vector< Matrix< T > > segD0
per-segment D0, already in MAP form