LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
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
35
#include "
line/lang/lang_types.h
"
36
#include "
line/lang/qn/network_struct.h
"
37
#include "
line/num/number.h
"
38
#include "
line/util/error.h
"
39
#include "
line/util/matrix.h
"
40
41
namespace
line
{
42
namespace
sn
{
43
44
/** What `sn_schedule_nominal` returns, in the reference's own output order. */
45
template
<
class
T>
46
struct
ScheduleNominal
{
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. */
55
template
<
class
T>
56
bool
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. */
62
template
<
class
T>
63
ScheduleNominal<T>
sn_schedule_nominal
(
const
qn::NetworkStruct<T>
&
sn
, std::size_t ist,
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];
71
ScheduleNominal<T>
out;
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
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
line::Matrix
Definition
matrix.h:56
line::qn::NetworkStruct
A network plus its refreshed NetworkStruct.
Definition
network_struct.h:838
error.h
The exception types the port throws.
lang_types.h
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
matrix.h
Dense matrix and non-owning view.
line::sn
Definition
sn_gd_balance.h:42
line::sn::sn_schedule_nominal
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.
Definition
sn_schedule_nominal.h:63
line::sn::sn_has_schedule
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.
Definition
sn_schedule_nominal.h:56
line
Definition
aoi_dist2ph.h:52
network_struct.h
A queueing network and its refreshed NetworkStruct.
number.h
Number-type abstraction for the templated API port.
line::lang::Distrib
Definition
lang_types.h:716
line::lang::Distrib::sched_cyclic
bool sched_cyclic
Definition
lang_types.h:796
line::lang::Distrib::D0
Matrix< T > D0
The (D0,D1) pair when the type carries one directly.
Definition
lang_types.h:759
line::lang::Distrib::sched_bp
std::vector< T > sched_bp
sn.proc{i}{r} = {breakpoints, A, B, cyclic} of a MAPt / PHt / NHPP.
Definition
lang_types.h:794
line::lang::Distrib::D1
Matrix< T > D1
Definition
lang_types.h:759
line::lang::Distrib::sched_D1
std::vector< Matrix< T > > sched_D1
Definition
lang_types.h:795
line::lang::Distrib::sched_D0
std::vector< Matrix< T > > sched_D0
Definition
lang_types.h:795
line::sn::ScheduleNominal
What sn_schedule_nominal returns, in the reference's own output order.
Definition
sn_schedule_nominal.h:46
line::sn::ScheduleNominal::D1bar
Matrix< T > D1bar
the width-weighted time average
Definition
sn_schedule_nominal.h:47
line::sn::ScheduleNominal::cyclic
bool cyclic
Definition
sn_schedule_nominal.h:51
line::sn::ScheduleNominal::segD1
std::vector< Matrix< T > > segD1
per-segment D1
Definition
sn_schedule_nominal.h:50
line::sn::ScheduleNominal::breakpoints
std::vector< T > breakpoints
the boundary vector, nseg + 1 long
Definition
sn_schedule_nominal.h:48
line::sn::ScheduleNominal::D0bar
Matrix< T > D0bar
Definition
sn_schedule_nominal.h:47
line::sn::ScheduleNominal::segD0
std::vector< Matrix< T > > segD0
per-segment D0, already in MAP form
Definition
sn_schedule_nominal.h:49
include
line
api
sn
sn_schedule_nominal.h
Generated by
1.18.0