LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
qsys_mg1_setup.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_SETUP_H
6
#define LINE_API_QSYS_QSYS_MG1_SETUP_H
7
8
/**
9
* @file
10
* @ingroup api_qsys
11
* M/G/1 with setup times: the server switches off when empty and needs a setup
12
* time U before serving the job that finds it off.
13
*
14
* Port of matlab/src/api/qsys/qsys_mg1_setup.m. By the decomposition of
15
* Fuhrmann and Cooper, the waiting time is the M/G/1 waiting time plus the
16
* equilibrium excess of the setup period,
17
*
18
* Wq = lambda E[S^2] / (2 (1 - rho)) + (2 E[U] + lambda E[U^2]) / (2 (1 + lambda E[U])).
19
*
20
* ARITHMETIC: field. Only the squared coefficient of variation appears, so the
21
* computation is exact for T = Rational.
22
*/
23
24
#include <string>
25
26
#include "
line/api/qsys/qsys_res.h
"
27
#include "
line/lang/distribution.h
"
28
#include "
line/num/number.h
"
29
#include "
line/util/error.h
"
30
31
namespace
line
{
32
namespace
qsys
{
33
34
/** MATLAB's [W, Wq, U, Q, res] outputs. */
35
template
<
class
T>
36
struct
Mg1SetupResult
{
37
T
W
;
///< mean sojourn time
38
T
Wq
;
///< mean waiting time
39
T
U
;
///< utilization rho
40
T
Q
;
///< mean number in system lambda W
41
QsysResT<T>
res
;
///< meanWaitingTime ... probSetup, analyzer
42
};
43
44
/**
45
* @brief M/G/1 with setup times, setup given by its first two moments.
46
*
47
* @param lambda arrival rate
48
* @param mu service rate
49
* @param cs coefficient of variation of the service time
50
* @param EU mean setup time
51
* @param EU2 second moment of the setup time
52
*/
53
template
<
class
T>
54
Mg1SetupResult<T>
qsys_mg1_setup
(
const
T& lambda,
const
T& mu,
const
T& cs,
const
T& EU,
const
T& EU2) {
55
const
T zero =
num_traits<T>::from_int
(0), one =
num_traits<T>::from_int
(1);
56
const
T two =
num_traits<T>::from_int
(2);
57
if
(lambda <= zero || mu <= zero || cs < zero)
58
throw
InputError
(
ErrorKind
(
"Argument"
),
59
"qsys_mg1_setup: lambda and mu must be positive scalars and cs non-negative"
);
60
const
T EUsq = T(EU * EU);
61
const
T tol = T(
num_traits<T>::from_double
(1e-12) * (EUsq > one ? EUsq : one));
62
if
(EU < zero || EU2 < T(EUsq - tol))
63
throw
InputError
(
ErrorKind
(
"Argument"
),
64
"qsys_mg1_setup: setup moments must satisfy EU >= 0 and EU2 >= EU^2"
);
65
const
T rho = T(lambda / mu);
66
if
(rho >= one)
resdetail::throw_unstable
(
"qsys_mg1_setup"
,
"rho"
,
num_traits<T>::to_double
(rho));
67
const
T ES2 = T((one + cs * cs) / (mu * mu));
68
Mg1SetupResult<T>
r;
69
r.
Wq
= T(lambda * ES2 / (two * (one - rho)) + (two * EU + lambda * EU2) / (two * (one + lambda * EU)));
70
r.
W
= T(r.
Wq
+ one / mu);
71
r.
U
= rho;
72
r.
Q
= T(lambda * r.
W
);
73
r.
res
.
set
(
"meanWaitingTime"
, r.
Wq
);
74
r.
res
.
set
(
"meanSojournTime"
, r.
W
);
75
r.
res
.
set
(
"meanQueueLength"
, r.
Q
);
76
r.
res
.
set
(
"meanQueueLengthQ"
, T(lambda * r.
Wq
));
77
r.
res
.
set
(
"utilization"
, rho);
78
r.
res
.
set
(
"probIdle"
, T((one - rho) / (one + lambda * EU)));
79
r.
res
.
set
(
"probSetup"
, T((one - rho) * lambda * EU / (one + lambda * EU)));
80
r.
res
.
analyzer
=
"exact:M/G/1-setup"
;
81
return
r;
82
}
83
84
/**
85
* @brief M/G/1 with setup times, setup given as a Distribution (MATLAB passes
86
* it in place of EU and reads its mean and variance).
87
*/
88
template
<
class
T>
89
Mg1SetupResult<T>
qsys_mg1_setup
(
const
T& lambda,
const
T& mu,
const
T& cs,
const
lang::Distrib<T>
& U) {
90
const
T EU =
lang::dist_moment
(U, 1);
91
return
qsys_mg1_setup
(lambda, mu, cs, EU, T(
lang::dist_moment
(U, 2)));
92
}
93
94
}
// namespace qsys
95
}
// namespace line
96
97
#endif
// LINE_API_QSYS_QSYS_MG1_SETUP_H
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:105
distribution.h
What refreshProcessRepresentations and refreshLST compute FROM a distribution: the (D0,...
error.h
The exception types the port throws.
line::lang::dist_moment
T dist_moment(const Distrib< T > &d, unsigned k)
The k-th raw moment.
Definition
distribution.h:586
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_setup
Mg1SetupResult< T > qsys_mg1_setup(const T &lambda, const T &mu, const T &cs, const T &EU, const T &EU2)
M/G/1 with setup times, setup given by its first two moments.
Definition
qsys_mg1_setup.h:54
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::lang::Distrib
Definition
lang_types.h:870
line::num_traits
Definition
number.h:123
line::qsys::Mg1SetupResult
MATLAB's [W, Wq, U, Q, res] outputs.
Definition
qsys_mg1_setup.h:36
line::qsys::Mg1SetupResult::Wq
T Wq
mean waiting time
Definition
qsys_mg1_setup.h:38
line::qsys::Mg1SetupResult::W
T W
mean sojourn time
Definition
qsys_mg1_setup.h:37
line::qsys::Mg1SetupResult::res
QsysResT< T > res
meanWaitingTime ... probSetup, analyzer
Definition
qsys_mg1_setup.h:41
line::qsys::Mg1SetupResult::Q
T Q
mean number in system lambda W
Definition
qsys_mg1_setup.h:40
line::qsys::Mg1SetupResult::U
T U
utilization rho
Definition
qsys_mg1_setup.h:39
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_setup.h
Generated by
1.18.0