LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
qsys_mg1_exceptional.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_QSYS_MG1_EXCEPTIONAL_H
6
#define LINE_API_QSYS_QSYS_MG1_EXCEPTIONAL_H
7
8
/**
9
* @file
10
* @ingroup api_qsys
11
* M/G/1 with exceptional first service: the job that starts a busy period has
12
* service law Bf, every other job law B (Welch, 1964).
13
*
14
* Port of matlab/src/api/qsys/qsys_mg1_exceptional.m. With x = P(empty) =
15
* (1 - lambda E[B]) / (1 + lambda E[Bf] - lambda E[B]), the fraction of time
16
* serving first jobs is rhof = lambda x E[Bf] and other jobs rho = lambda (1-x) E[B];
17
*
18
* Wq = (rhof E[Bf^2]/(2E[Bf]) + rho E[B^2]/(2E[B])) / (1 - lambda E[B]),
19
* W = Wq + x E[Bf] + (1 - x) E[B].
20
*
21
* ARITHMETIC: field; exact for T = Rational.
22
*/
23
24
#include "
line/api/qsys/qsys_res.h
"
25
#include "
line/num/number.h
"
26
#include "
line/util/error.h
"
27
28
namespace
line
{
29
namespace
qsys
{
30
31
/** MATLAB's [W, Wq, U, Q, res] outputs. */
32
template
<
class
T>
33
struct
Mg1ExceptionalResult
{
34
T
W
;
///< mean sojourn time
35
T
Wq
;
///< mean waiting time
36
T
U
;
///< utilization rhof + rho
37
T
Q
;
///< mean number in system
38
QsysResT<T>
res
;
///< meanWaitingTime ... rhoOther, analyzer
39
};
40
41
/**
42
* @brief M/G/1 with exceptional first service.
43
*
44
* @param lambda arrival rate
45
* @param mu service rate of ordinary jobs
46
* @param cs coefficient of variation of the ordinary service time
47
* @param muf service rate of the job opening a busy period
48
* @param csf coefficient of variation of the exceptional service time
49
*/
50
template
<
class
T>
51
Mg1ExceptionalResult<T>
qsys_mg1_exceptional
(
const
T& lambda,
const
T& mu,
const
T& cs,
const
T& muf,
52
const
T& csf) {
53
const
T zero =
num_traits<T>::from_int
(0), one =
num_traits<T>::from_int
(1);
54
const
T two =
num_traits<T>::from_int
(2);
55
if
(lambda <= zero || mu <= zero || muf <= zero || cs < zero || csf < zero)
56
throw
InputError
(
ErrorKind
(
"Argument"
),
57
"qsys_mg1_exceptional: lambda, mu, muf must be positive scalars and cs, csf non-negative"
);
58
const
T EB = T(one / mu), EB2 = T((one + cs * cs) / (mu * mu));
59
const
T EBf = T(one / muf), EBf2 = T((one + csf * csf) / (muf * muf));
60
if
(T(lambda * EB) >= one)
61
resdetail::throw_unstable
(
"qsys_mg1_exceptional"
,
"lambda E[B]"
,
num_traits<T>::to_double
(T(lambda * EB)));
62
const
T x = T((one - lambda * EB) / (one + lambda * EBf - lambda * EB));
63
const
T rhof = T(lambda * x * EBf);
64
const
T rho = T(lambda * (one - x) * EB);
65
Mg1ExceptionalResult<T>
r;
66
r.
Wq
= T((rhof * EBf2 / (two * EBf) + rho * EB2 / (two * EB)) / (one - lambda * EB));
67
r.
W
= T(r.
Wq
+ x * EBf + (one - x) * EB);
68
r.
U
= T(rhof + rho);
69
r.
Q
= T(lambda * r.
W
);
70
r.
res
.
set
(
"meanWaitingTime"
, r.
Wq
);
71
r.
res
.
set
(
"meanSojournTime"
, r.
W
);
72
r.
res
.
set
(
"meanQueueLength"
, r.
Q
);
73
r.
res
.
set
(
"meanQueueLengthQ"
, T(lambda * r.
Wq
));
74
r.
res
.
set
(
"utilization"
, r.
U
);
75
r.
res
.
set
(
"probEmpty"
, x);
76
r.
res
.
set
(
"rhoFirst"
, rhof);
77
r.
res
.
set
(
"rhoOther"
, rho);
78
r.
res
.
analyzer
=
"exact:M/G/1-exceptional"
;
79
return
r;
80
}
81
82
}
// namespace qsys
83
}
// namespace line
84
85
#endif
// LINE_API_QSYS_QSYS_MG1_EXCEPTIONAL_H
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:105
error.h
The exception types the port throws.
line::qsys::resdetail::throw_unstable
void throw_unstable(const char *fn, const char *what, double v)
A LINE:input:Unstable refusal "fn: unstable system: <what> = %g >= 1".
Definition
qsys_res.h:213
line::qsys
Definition
qsys_bmapm1.h:58
line::qsys::qsys_mg1_exceptional
Mg1ExceptionalResult< T > qsys_mg1_exceptional(const T &lambda, const T &mu, const T &cs, const T &muf, const T &csf)
M/G/1 with exceptional first service.
Definition
qsys_mg1_exceptional.h:51
line
Conservation laws of a layered queueing network, enumerated from its structure.
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
qsys_res.h
The res struct the exact queueing-system functions return, and the numeric helpers those functions sh...
line::ErrorKind::ErrorKind
ErrorKind(std::string n)
Definition
error.h:39
line::num_traits
Definition
number.h:123
line::qsys::Mg1ExceptionalResult
MATLAB's [W, Wq, U, Q, res] outputs.
Definition
qsys_mg1_exceptional.h:33
line::qsys::Mg1ExceptionalResult::res
QsysResT< T > res
meanWaitingTime ... rhoOther, analyzer
Definition
qsys_mg1_exceptional.h:38
line::qsys::Mg1ExceptionalResult::W
T W
mean sojourn time
Definition
qsys_mg1_exceptional.h:34
line::qsys::Mg1ExceptionalResult::U
T U
utilization rhof + rho
Definition
qsys_mg1_exceptional.h:36
line::qsys::Mg1ExceptionalResult::Q
T Q
mean number in system
Definition
qsys_mg1_exceptional.h:37
line::qsys::Mg1ExceptionalResult::Wq
T Wq
mean waiting time
Definition
qsys_mg1_exceptional.h:35
line::qsys::QsysResT
MATLAB's res struct: named measures in insertion order, plus res.analyzer.
Definition
qsys_res.h:57
line::qsys::QsysResT::analyzer
std::string analyzer
Definition
qsys_res.h:59
line::qsys::QsysResT::set
void set(const std::string &name, const T &v)
Sets (or overwrites) a scalar field.
Definition
qsys_res.h:62
include
line
api
qsys
qsys_mg1_exceptional.h
Generated by
1.18.0