LINE Solver (C++)
Templated C++ port of the LINE queueing solver
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
25#include "line/num/number.h"
26#include "line/util/error.h"
27
28namespace line {
29namespace qsys {
30
31/** MATLAB's [W, Wq, U, Q, res] outputs. */
32template <class T>
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 */
50template <class T>
51Mg1ExceptionalResult<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);
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
InputError(const std::string &what)
Definition error.h:105
The exception types the port throws.
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
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.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:52
Number-type abstraction for the templated API port.
The res struct the exact queueing-system functions return, and the numeric helpers those functions sh...
ErrorKind(std::string n)
Definition error.h:39
MATLAB's [W, Wq, U, Q, res] outputs.
QsysResT< T > res
meanWaitingTime ... rhoOther, analyzer
MATLAB's res struct: named measures in insertion order, plus res.analyzer.
Definition qsys_res.h:57
std::string analyzer
Definition qsys_res.h:59
void set(const std::string &name, const T &v)
Sets (or overwrites) a scalar field.
Definition qsys_res.h:62