LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
qsys_mg1_vacation.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_VACATION_H
6#define LINE_API_QSYS_QSYS_MG1_VACATION_H
7
8/**
9 * @file
10 * @ingroup api_qsys
11 * M/G/1 and M^X/G/1 exhaustive service with server vacations.
12 *
13 * Templated port of matlab/src/api/qsys/qsys_mg1_vacation.m, cross-checked
14 * against jar/src/main/java/jline/api/qsys/Qsys_mg1_vacation.java.
15 *
16 * multiple vacations (Haverkort 1998, eq. 5.38, 5.41):
17 * Wq = E[V^2]/(2E[V]) + Wq(M^X/G/1)
18 * single vacation (Haverkort 1998, eq. 5.39):
19 * Wq = lambda E[V^2] / (2 (V*(lambda) + lambda E[V])) + Wq(M^X/G/1)
20 *
21 * with lambda the batch rate, V*(lambda) the vacation LST at lambda, and
22 * Wq(M^X/G/1) the arbitrary-job wait of qsys_mxg1. W = Wq + 1/mu,
23 * U = lambda E[X]/mu, Q = lambda E[X] W. Rational in the inputs (the LST
24 * enters as a number), so exact for T = Rational.
25 */
26
28#include "line/num/number.h"
29#include "line/util/error.h"
30
31namespace line {
32namespace qsys {
33
34/** Vacation policy: MATLAB's 'policy' option. */
36
37/** The MATLAB name-value options of qsys_mg1_vacation. */
38template <class T>
41 T lst = num_traits<T>::from_int(0); ///< V*(lambda); read only by the single policy
42 bool has_lst = false; ///< the single policy needs lst
43 T E_X = num_traits<T>::from_int(1); ///< mean batch size
44 T E_X2 = num_traits<T>::from_int(1); ///< second raw moment of the batch size
45};
46
47/**
48 * @brief Exhaustive-service M/G/1 (or M^X/G/1) with vacations.
49 *
50 * @param lambda (batch) arrival rate
51 * @param mu service rate of a job
52 * @param cs coefficient of variation of the service time
53 * @param EV mean vacation time (> 0)
54 * @param EV2 second raw moment of the vacation time
55 * @param opt policy, vacation LST and batch moments
56 */
57template <class T>
58MeanValueResult<T> qsys_mg1_vacation(const T& lambda, const T& mu, const T& cs, const T& EV,
59 const T& EV2,
61 const T zero = num_traits<T>::from_int(0);
62 const T one = num_traits<T>::from_int(1);
63 const T two = num_traits<T>::from_int(2);
64 const T tol = num_traits<T>::from_rational(1, 1000000000000L);
65 if (!(EV > zero) || EV2 < EV * EV * (one - tol))
66 throw InputError(ErrorKind("Argument"),
67 "qsys_mg1_vacation needs a vacation with 0 < E[V] < Inf and E[V]^2 <= E[V^2] < Inf");
68 const MeanValueResult<T> base = qsys_mxg1(lambda, mu, cs, opt.E_X, opt.E_X2);
69 T Wvac;
70 if (opt.policy == VacationPolicy::Multiple) {
71 Wvac = EV2 / (two * EV);
72 } else {
73 if (!opt.has_lst)
74 throw InputError(ErrorKind("Argument"),
75 "qsys_mg1_vacation: the single-vacation policy needs the vacation LST at the "
76 "arrival rate, V*(lambda) = E[exp(-lambda V)]");
77 if (opt.lst < zero || !(opt.lst < one))
78 throw InputError(ErrorKind("Argument"),
79 "qsys_mg1_vacation: the vacation LST at lambda must lie in [0,1) for a vacation "
80 "with E[V] > 0");
81 Wvac = lambda * EV2 / (two * (opt.lst + lambda * EV));
82 }
84 r.Wq = base.Wq + Wvac;
85 r.W = r.Wq + one / mu;
86 r.U = lambda * opt.E_X / mu;
87 r.Q = lambda * opt.E_X * r.W;
88 return r;
89}
90
91} // namespace qsys
92} // namespace line
93
94#endif // LINE_API_QSYS_QSYS_MG1_VACATION_H
InputError(const std::string &what)
Definition error.h:105
The exception types the port throws.
MeanValueResult< T > qsys_mxg1(const T &lambda_batch, const T &mu, const T &cs, const T &E_X, const T &E_X2)
M^X/G/1 from the first two raw moments of the batch size.
Definition qsys_mxg1.h:56
MeanValueResult< T > qsys_mg1_vacation(const T &lambda, const T &mu, const T &cs, const T &EV, const T &EV2, const Mg1VacationOptions< T > &opt=Mg1VacationOptions< T >())
Exhaustive-service M/G/1 (or M^X/G/1) with vacations.
VacationPolicy
Vacation policy: MATLAB's 'policy' option.
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
The MATLAB name-value options of qsys_mg1_vacation.
T lst
V*(lambda); read only by the single policy.
bool has_lst
the single policy needs lst
T E_X2
second raw moment of the batch size