LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
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
35
#include "
line/api/qsys/qsys_mg1_setf.h
"
36
#include "
line/api/qsys/qsys_types.h
"
37
#include "
line/num/number.h
"
38
#include "
line/util/error.h
"
39
40
namespace
line
{
41
namespace
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
*/
50
template
<
class
T>
51
Mg1DisciplineResult<T>
qsys_mg1_lrpt
(
const
std::vector<T>& lambda,
const
std::vector<T>& mu,
52
const
std::vector<T>& cs) {
53
static_assert
(
num_traits<T>::has_transcendental
,
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
60
Mg1DisciplineResult<T>
r;
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
error.h
The exception types the port throws.
line::qsys
Definition
qsys_bmapm1.h:58
line::qsys::qsys_mg1_lrpt
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).
Definition
qsys_mg1_lrpt.h:51
line
Conservation laws of a layered queueing network, enumerated from its structure.
Definition
aoi_dist2ph.h:51
number.h
Number-type abstraction for the templated API port.
qsys_mg1_setf.h
M/G/1 under SETF (shortest elapsed time first), the non-preemptive counterpart of FB/LAS.
qsys_types.h
Shared return type and arithmetic helpers for the templated qsys port.
line::num_traits
Definition
number.h:123
line::qsys::Mg1DisciplineResult
Definition
qsys_mg1_setf.h:46
line::qsys::Mg1DisciplineResult::W
std::vector< T > W
per-class mean response time
Definition
qsys_mg1_setf.h:47
line::qsys::Mg1DisciplineResult::rhohat
T rhohat
Q/(1+Q) with Q = sum_k lambda_k W_k.
Definition
qsys_mg1_setf.h:48
include
line
api
qsys
qsys_mg1_lrpt.h
Generated by
1.18.0