LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
qsys_mg1_breakdown.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_BREAKDOWN_H
6#define LINE_API_QSYS_QSYS_MG1_BREAKDOWN_H
7
8/**
9 * @file
10 * @ingroup api_qsys
11 * M/G/1 FCFS with server breakdowns: Queue.setBreakdown with no down service.
12 *
13 * Templated port of matlab/src/api/qsys/qsys_mg1_breakdown.m, cross-checked
14 * against jar/src/main/java/jline/api/qsys/Qsys_mg1_breakdown.java.
15 *
16 * An up server fails after an exponential time of rate alpha WHETHER BUSY OR
17 * IDLE; repair R is general; arrivals continue while down and an interrupted
18 * job resumes. With p = alpha/(lambda+alpha) and r = R*(lambda), the residual
19 * repair D met by a job arriving to an empty system has
20 * E[D] = p (E[R] - (1-r)/lambda) / (1 - p r)
21 * E[D^2] = p (E[R^2] - 2E[R]/lambda + 2(1-r)/lambda^2) / (1 - p r)
22 * and each job holds the server for C = S + repairs during S (Gaver 1962):
23 * E[C] = E[S](1 + alpha E[R]), E[C^2] = E[S^2](1 + alpha E[R])^2 + alpha E[S] E[R^2].
24 * The queue is an M/G/1 with exceptional first service C0 = D + C (Welch
25 * 1964; Avi-Itzhak and Naor 1963): with a = lambda E[C], a0 = lambda E[C0],
26 * a2 = lambda^2 E[C^2], a02 = lambda^2 E[C0^2],
27 * E[N] = ((2 a0 + a02)(1 - a) + a0 a2) / (2 (1 - a)(1 - a + a0)).
28 * W = E[N]/lambda, Wq = W - 1/mu, U = lambda/mu, Q = E[N]. Rational in the
29 * inputs (the repair LST enters as a number), so exact for T = Rational.
30 */
31
33#include "line/num/number.h"
34#include "line/util/error.h"
35
36namespace line {
37namespace qsys {
38
39/**
40 * @brief M/G/1 FCFS with exponential failures (busy or idle) and general repair.
41 *
42 * @param lambda Poisson arrival rate
43 * @param mu service rate, E[S] = 1/mu
44 * @param cs coefficient of variation of the service time
45 * @param alpha failure rate of an up server (0: the M/G/1)
46 * @param ER mean repair time
47 * @param ER2 second raw moment of the repair time
48 * @param RLST repair LST at the arrival rate, R*(lambda), in (0,1)
49 */
50template <class T>
51MeanValueResult<T> qsys_mg1_breakdown(const T& lambda, const T& mu, const T& cs, const T& alpha,
52 const T& ER, const T& ER2, const T& RLST) {
53 const T zero = num_traits<T>::from_int(0);
54 const T one = num_traits<T>::from_int(1);
55 const T two = num_traits<T>::from_int(2);
56 const T tol = num_traits<T>::from_rational(1, 1000000000000L);
57 if (!(lambda > zero) || !(mu > zero) || cs < zero)
58 throw InputError(ErrorKind("Argument"), "qsys_mg1_breakdown needs lambda > 0, 0 < mu < Inf and cs >= 0");
59 if (alpha < zero)
60 throw InputError(ErrorKind("Argument"), "qsys_mg1_breakdown needs a finite failure rate alpha >= 0");
61 if (!(ER > zero) || ER2 < ER * ER * (one - tol))
62 throw InputError(ErrorKind("Argument"),
63 "qsys_mg1_breakdown needs a repair time with 0 < E[R] < Inf and E[R]^2 <= E[R^2] < Inf");
64 if (!(RLST > zero) || !(RLST < one))
65 throw InputError(ErrorKind("Argument"),
66 "qsys_mg1_breakdown: the repair LST at lambda, R*(lambda), must lie in (0,1)");
67 const T ES = one / mu;
68 const T ES2 = (one + cs * cs) / (mu * mu);
69 const T avail = one + alpha * ER;
70 const T EC = ES * avail;
71 const T EC2 = ES2 * avail * avail + alpha * ES * ER2;
72 const T a = lambda * EC;
73 if (a >= one)
74 throw NumericError(ErrorKind("Instability"),
75 "qsys_mg1_breakdown: system is unstable, lambda E[S] (1 + alpha E[R]) >= 1");
76 const T p = alpha / (lambda + alpha);
77 const T ED = p * (ER - (one - RLST) / lambda) / (one - p * RLST);
78 const T ED2 = p * (ER2 - two * ER / lambda + two * (one - RLST) / (lambda * lambda)) / (one - p * RLST);
79 const T EC0 = ED + EC;
80 const T EC02 = ED2 + two * ED * EC + EC2;
81 const T a0 = lambda * EC0;
82 const T a2 = lambda * lambda * EC2;
83 const T a02 = lambda * lambda * EC02;
85 r.Q = ((two * a0 + a02) * (one - a) + a0 * a2) / (two * (one - a) * (one - a + a0));
86 r.W = r.Q / lambda;
87 r.Wq = r.W - ES;
88 r.U = lambda * ES;
89 return r;
90}
91
92} // namespace qsys
93} // namespace line
94
95#endif // LINE_API_QSYS_QSYS_MG1_BREAKDOWN_H
InputError(const std::string &what)
Definition error.h:105
NumericError(const std::string &what)
Definition error.h:112
The exception types the port throws.
MeanValueResult< T > qsys_mg1_breakdown(const T &lambda, const T &mu, const T &cs, const T &alpha, const T &ER, const T &ER2, const T &RLST)
M/G/1 FCFS with exponential failures (busy or idle) and general repair.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Number-type abstraction for the templated API port.
M^X/G/1: the FCFS batch-Poisson queue with general service.
ErrorKind(std::string n)
Definition error.h:39
The four outputs [W, Wq, U, Q] of qsys_mxg1, qsys_mg1_vacation and qsys_mg1_breakdown.
Definition qsys_mxg1.h:39
T W
mean response (sojourn) time of an arbitrary job
Definition qsys_mxg1.h:40
T Q
mean number of jobs in the system
Definition qsys_mxg1.h:43
T Wq
mean time in the system and not in service
Definition qsys_mxg1.h:41
T U
server utilization (fraction of time doing work)
Definition qsys_mxg1.h:42