LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
qsys_types.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_QSYS_TYPES_H
6
#define LINE_API_QSYS_TYPES_H
7
8
/**
9
* @file
10
* @ingroup api_qsys
11
* Shared return type and arithmetic helpers for the templated qsys port.
12
*
13
* The MATLAB closed-form queueing-system functions in matlab/src/api/qsys/
14
* almost all return the pair [W,rhohat], mirrored in the JAR by Ret.qsys.
15
* This header carries that pair plus the handful of ADL wrappers the family
16
* needs; each ported function lives in its own header named after the MATLAB
17
* file, as required by the port convention.
18
*/
19
20
#include <cmath>
21
#include <string>
22
23
#include "
line/num/number.h
"
24
#include "
line/util/error.h
"
25
26
namespace
line
{
27
namespace
qsys
{
28
29
/**
30
* Return value of the qsys family, mirroring MATLAB's [W,rhohat] and the
31
* JAR's Ret.qsys.
32
*
33
* W mean response time (time in system, service included)
34
* rhohat modified utilization chosen so that the M/M/1 relations still hold
35
*/
36
template
<
class
T>
37
struct
QsysResult
{
38
T
W
;
39
T
rhohat
;
40
};
41
42
namespace
detail {
43
44
/** exp(v), resolved by ADL so double, cpp_bin_float and mpfr all work. */
45
template
<
class
T>
46
inline
T num_exp(
const
T& v) {
47
using
std::exp;
48
return
exp(v);
49
}
50
51
/** sqrt(v), resolved by ADL. */
52
template
<
class
T>
53
inline
T num_sqrt(
const
T& v) {
54
using
std::sqrt;
55
return
sqrt(v);
56
}
57
58
/** base^exponent for a real-valued exponent, resolved by ADL. */
59
template
<
class
T>
60
inline
T num_pow(
const
T& base,
const
T& exponent) {
61
using
std::pow;
62
return
pow(base, exponent);
63
}
64
65
template
<
class
T>
66
inline
T num_min(
const
T& a,
const
T& b) {
67
return
a < b ? a : b;
68
}
69
70
/**
71
* Guard against the exact pole at rho == 1.
72
*
73
* MATLAB divides by 1-rho and returns Inf there; in an exact field that
74
* division has no value at all, so the port reports it as an input error.
75
* Nothing else is checked: rho > 1 still returns MATLAB's negative W, since
76
* the MATLAB functions do not reject it either.
77
*/
78
template
<
class
E>
79
inline
void
require_no_pole(
const
E& one_minus_rho,
const
char
* fn) {
80
// E is deduced, not fixed to T, so a Boost expression template binds here
81
// without being materialized first.
82
if
(one_minus_rho == 0)
83
throw
InputError
(std::string(fn) +
": rho == 1, the mean waiting time is undefined"
);
84
}
85
86
/** rhohat = W*lambda/(1+W*lambda), the closing line of most qsys functions. */
87
template
<
class
T>
88
inline
T rhohat_from_W(
const
T& W,
const
T& lambda) {
89
const
T Wl = W * lambda;
90
return
Wl / (num_traits<T>::from_int(1) + Wl);
91
}
92
93
}
// namespace detail
94
95
}
// namespace qsys
96
}
// namespace line
97
98
#endif
// LINE_API_QSYS_TYPES_H
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
error.h
The exception types the port throws.
line::qsys
Definition
qsys_bmapm1.h:58
line
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
line::qsys::QsysResult
Return value of the qsys family, mirroring MATLAB's [W,rhohat] and the JAR's Ret.qsys.
Definition
qsys_types.h:37
line::qsys::QsysResult::W
T W
Definition
qsys_types.h:38
line::qsys::QsysResult::rhohat
T rhohat
Definition
qsys_types.h:39
include
line
api
qsys
qsys_types.h
Generated by
1.18.0