LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
slotted_request.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_SOLVERS_SLOTTED_REQUEST_H
6
#define LINE_SOLVERS_SLOTTED_REQUEST_H
7
8
/**
9
* @file
10
* @ingroup line_solvers
11
* Port of `matlab/src/solvers/line_slotted_request.m`: the one reading of the
12
* discrete-time switch shared by SolverNC, SolverMAM and SolverLDES, so the
13
* same options mean the same thing to all three.
14
*
15
* MODE is "discrete" when `config.slotted` is true or `config.timescale` is
16
* "discrete", "continuous" when the timescale is "continuous", and "auto"
17
* otherwise. Asking for slotted together with a continuous timescale is an
18
* error. What "auto" means is the solver's business: MAM infers the time scale
19
* from the laws (`sn_is_discrete_time`), NC and LDES read it as continuous.
20
*
21
* SLOT LENGTH is `config.slotlength` (default 1), the lattice unit d in model
22
* time units. Every interarrival and service sample must be a positive multiple
23
* of d; a law keeps its meaning whatever d is.
24
*/
25
26
#include <algorithm>
27
#include <cctype>
28
#include <cmath>
29
#include <string>
30
31
#include "
line/util/error.h
"
32
33
namespace
line
{
34
namespace
solvers
{
35
36
/** The resolved time-scale request. */
37
struct
SlottedRequest
{
38
std::string
mode
=
"auto"
;
///< "auto", "discrete" or "continuous"
39
double
slot_length
= 1.0;
///< the lattice unit d in model time units
40
bool
discrete
()
const
{
return
mode
==
"discrete"
; }
41
};
42
43
/**
44
* Resolves `timescale` (empty reads as "auto"), `slotted` and `slotlength` as
45
* they come from `options.config`.
46
*/
47
inline
SlottedRequest
slotted_request
(std::string timescale,
bool
slotted,
double
slotlength) {
48
if
(timescale.empty()) timescale =
"auto"
;
49
std::transform(timescale.begin(), timescale.end(), timescale.begin(),
50
[](
unsigned
char
c) { return static_cast<char>(std::tolower(c)); });
51
if
(timescale !=
"auto"
&& timescale !=
"discrete"
&& timescale !=
"continuous"
)
52
throw
InputError
(
ErrorKind
{
"Option"
},
53
"options.config.timescale must be 'auto', 'discrete' or 'continuous'."
);
54
if
(!std::isfinite(slotlength) || slotlength <= 0)
55
throw
InputError
(
ErrorKind
{
"Option"
},
56
"options.config.slotlength must be a positive finite scalar."
);
57
if
(slotted && timescale ==
"continuous"
)
58
throw
InputError
(
ErrorKind
{
"Option"
},
59
"options.config.slotted=true asks for a discrete time scale but "
60
"options.config.timescale='continuous' asks for a continuous one."
);
61
SlottedRequest
out;
62
out.
mode
= slotted ? std::string(
"discrete"
) : timescale;
63
out.slot_length = slotlength;
64
return
out;
65
}
66
67
}
// namespace solvers
68
}
// namespace line
69
70
#endif
// LINE_SOLVERS_SLOTTED_REQUEST_H
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:105
error.h
The exception types the port throws.
line::solvers
Definition
cache_metrics.h:40
line::solvers::slotted_request
SlottedRequest slotted_request(std::string timescale, bool slotted, double slotlength)
Resolves timescale (empty reads as "auto"), slotted and slotlength as they come from options....
Definition
slotted_request.h:47
line
Conservation laws of a layered queueing network, enumerated from its structure.
Definition
aoi_dist2ph.h:52
line::ErrorKind
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition
error.h:37
line::solvers::SlottedRequest
The resolved time-scale request.
Definition
slotted_request.h:37
line::solvers::SlottedRequest::slot_length
double slot_length
the lattice unit d in model time units
Definition
slotted_request.h:39
line::solvers::SlottedRequest::mode
std::string mode
"auto", "discrete" or "continuous"
Definition
slotted_request.h:38
line::solvers::SlottedRequest::discrete
bool discrete() const
Definition
slotted_request.h:40
include
line
solvers
slotted_request.h
Generated by
1.18.0