LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
qsys_mg1_lrpt.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_LRPT_H
6#define LINE_API_QSYS_QSYS_MG1_LRPT_H
7
8/**
9 * @file
10 * @ingroup api_qsys
11 * M/G/1 under LRPT (longest remaining processing time).
12 *
13 * Templated port of matlab/src/api/qsys/qsys_mg1_lrpt.m, cross-checked against
14 * jar/src/main/java/jline/api/qsys/Qsys_mg1_lrpt.java.
15 *
16 * LRPT gives the server to the job with the most work left, so the slowdown is
17 * the same for every job in the system (Wierman and Harchol-Balter,
18 * SIGMETRICS 2003, Sec. 3.2):
19 *
20 * E[T(x)] = x/(1-rho) + lambda E[X^2] / (2 (1-rho)^2)
21 *
22 * with rho the total load and E[X^2] the second moment of the mixture size.
23 * Only the first term depends on x, so for ANY size law the class mean is the
24 * closed form E[T_k] = E[S_k]/(1-rho) + lambda E[X^2]/(2 (1-rho)^2), which is
25 * never below FCFS. The former code integrated the exponential case to 20/mu_k
26 * only, and answered a non-exponential input with a priority surrogate that
27 * ignored cs and fell below FCFS.
28 *
29 * ARITHMETIC. Rational operations only; the gate is kept for API stability.
30 */
31
32#include <cstddef>
33#include <vector>
34
37#include "line/num/number.h"
38#include "line/util/error.h"
39
40namespace line {
41namespace qsys {
42
43/**
44 * @brief M/G/1 under LRPT (longest remaining processing time).
45 *
46 * @param lambda per-class arrival rates
47 * @param mu per-class service rates
48 * @param cs per-class coefficients of variation of the service time
49 */
50template <class T>
51Mg1DisciplineResult<T> qsys_mg1_lrpt(const std::vector<T>& lambda, const std::vector<T>& mu,
52 const std::vector<T>& cs) {
54 "qsys_mg1_lrpt requires transcendental arithmetic");
55 const T rho_total = detail::mg1_discipline_check("qsys_mg1_lrpt", lambda, mu, cs);
56 const std::size_t K = lambda.size();
57 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
58 const T two = num_traits<T>::from_int(2);
59
61 T lambda_total = zero;
62 for (const T& v : lambda) lambda_total += v;
63 T E_X2 = zero;
64 for (std::size_t i = 0; i < K; ++i)
65 E_X2 += (lambda[i] / lambda_total) * (one + cs[i] * cs[i]) / (mu[i] * mu[i]);
66 const T flat = lambda_total * E_X2 / (two * (one - rho_total) * (one - rho_total));
67 r.W.assign(K, zero);
68 for (std::size_t k = 0; k < K; ++k) r.W[k] = (one / mu[k]) / (one - rho_total) + flat;
69 r.rhohat = detail::mg1_discipline_rhohat(lambda, r.W);
70 return r;
71}
72
73} // namespace qsys
74} // namespace line
75
76#endif // LINE_API_QSYS_QSYS_MG1_LRPT_H
The exception types the port throws.
Mg1DisciplineResult< T > qsys_mg1_lrpt(const std::vector< T > &lambda, const std::vector< T > &mu, const std::vector< T > &cs)
M/G/1 under LRPT (longest remaining processing time).
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/G/1 under SETF (shortest elapsed time first), the non-preemptive counterpart of FB/LAS.
Shared return type and arithmetic helpers for the templated qsys port.
std::vector< T > W
per-class mean response time
T rhohat
Q/(1+Q) with Q = sum_k lambda_k W_k.