LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
solver_mva_qsys_prio_tardiness.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_SOLVERS_MVA_SOLVER_MVA_QSYS_PRIO_TARDINESS_H
6
#define LINE_SOLVERS_MVA_SOLVER_MVA_QSYS_PRIO_TARDINESS_H
7
8
/**
9
* @file
10
* Port of `solver_mva_qsys_prio_tardiness.m`: the exact class-deadline
11
* tardiness E[(R - D)^+] of the single priority queue `solver_mva_qsys_prio_analyzer`
12
* solved (Hafizoglu, Gel and Keskinocak, INFORMS J. Comput. 25(2), 2013).
13
*
14
* Applies when some class has a finite deadline and every active class has
15
* exponential service at one common rate. "mmc.prio" and "mg1.prio" are
16
* head-of-line, "mg1.prio.pr" preemptive resume. Both matrices are EMPTY
17
* otherwise, which is the reference's "solver does not compute it".
18
*
19
* ARITHMETIC: double.
20
*/
21
22
#include <algorithm>
23
#include <cmath>
24
#include <string>
25
#include <vector>
26
27
#include "
line/api/qsys/qsys_mmc_prio_tardiness.h
"
28
#include "
line/solvers/mva/mva_dispatch.h
"
29
30
namespace
line
{
31
namespace
mva
{
32
33
/** `Avg.Tard` (stations x classes, queue row filled) and `Avg.SysTard` (1 x classes). */
34
struct
QsysPrioTardiness
{
35
Matrix<double>
Tard
,
SysTard
;
36
bool
empty
()
const
{
return
SysTard
.rows() == 0; }
37
};
38
39
/**
40
* @param L the model the prio analyzer solved
41
* @param actualmethod the resolved method, optionally prefixed "default/"
42
*/
43
inline
QsysPrioTardiness
solver_mva_qsys_prio_tardiness
(
const
qn::NetworkStruct<double>
& L,
44
std::string actualmethod) {
45
QsysPrioTardiness
out;
46
const
std::string pre =
"default/"
;
47
if
(actualmethod.compare(0, pre.size(), pre) == 0) actualmethod = actualmethod.substr(pre.size());
48
std::string type;
49
if
(actualmethod ==
"mmc.prio"
|| actualmethod ==
"mg1.prio"
) type =
"np"
;
50
else
if
(actualmethod ==
"mg1.prio.pr"
) type =
"pr"
;
51
else
return
out;
52
if
(
mva_qsys_prio_variant
(L) != actualmethod)
return
out;
53
const
std::size_t K = L.
nclasses
;
54
bool
any =
false
;
55
for
(std::size_t r = 0; r < K; ++r)
56
if
(std::isfinite(L.
classes
[r].deadline)) any =
true
;
57
if
(!any)
return
out;
58
const
std::size_t src = detail::station_of_type(L, qn::NodeType::Source);
59
const
std::size_t q = detail::station_of_type(L, qn::NodeType::Queue);
60
if
(src == 0 || q == 0)
return
out;
61
std::vector<std::size_t> order(K);
62
for
(std::size_t r = 0; r < K; ++r) order[r] = r;
63
std::stable_sort(order.begin(), order.end(), [&](std::size_t a, std::size_t b) {
64
return L.classes[a].prio < L.classes[b].prio;
65
});
66
std::vector<double> la,
da
;
67
std::vector<std::size_t> cls;
68
double
mu0 = NAN;
69
for
(std::size_t j = 0; j < K; ++j) {
70
const
std::size_t r = order[j];
71
const
double
lam = L.
rates
(src - 1, r), mu = L.
rates
(q - 1, r);
72
if
(!(lam > 0) || !std::isfinite(mu))
continue
;
73
if
(std::isnan(mu0)) mu0 = mu;
74
if
(std::abs(L.
scv
(q - 1, r) - 1.0) > 1e-6 || std::abs(mu - mu0) > 1e-10 * mu0)
return
out;
75
la.push_back(lam);
76
da
.push_back(L.
classes
[r].deadline);
77
cls.push_back(r);
78
}
79
if
(la.empty())
return
out;
80
const
std::vector<double> t =
81
qsys::qsys_mmc_prio_tardiness
(la, mu0,
static_cast<
unsigned
>
(L.
stations
[q - 1].nservers),
da
, type).
Tard
;
82
out.
Tard
=
Matrix<double>
(L.
nstations
, K);
83
out.
SysTard
=
Matrix<double>
(1, K);
84
for
(std::size_t a = 0; a < cls.size(); ++a) {
85
out.
Tard
(q - 1, cls[a]) = t[a];
86
out.
SysTard
(0, cls[a]) = t[a];
87
}
88
return
out;
89
}
90
91
}
// namespace mva
92
}
// namespace line
93
94
#endif
// LINE_SOLVERS_MVA_SOLVER_MVA_QSYS_PRIO_TARDINESS_H
line::Matrix
Definition
matrix.h:56
line::qn::NetworkStruct
A network plus its refreshed NetworkStruct.
Definition
network_struct.h:1070
line::qn::NetworkStruct::nclasses
std::size_t nclasses
Definition
network_struct.h:1364
line::qn::NetworkStruct::classes
std::vector< JobClass > classes
Definition
network_struct.h:1086
line::qn::NetworkStruct::stations
std::vector< Station< T > > stations
stations[k-1] is the k-th station
Definition
network_struct.h:1083
line::qn::NetworkStruct::rates
Matrix< T > rates
(nstations x nclasses) service rates and SCVs, with a PARALLEL disabled flag instead of MATLAB's NaN ...
Definition
network_struct.h:1395
line::qn::NetworkStruct::nstations
std::size_t nstations
Definition
network_struct.h:1364
line::qn::NetworkStruct::scv
Matrix< T > scv
Definition
network_struct.h:1395
mva_dispatch.h
Port of @@SolverMVA/mvaDispatch.m: one inner solve, choosing the analyzer that fits the model.
line::da
Definition
da_cache_isolate.h:45
line::mva
Definition
fj_driver.h:44
line::mva::mva_qsys_prio_variant
std::string mva_qsys_prio_variant(const qn::NetworkStruct< T > &L)
Port of SolverMVA.qsysPrioVariant(sn): the exact priority closed form solver_mva_qsys_prio_analyzer a...
Definition
mva_dispatch.h:368
line::mva::solver_mva_qsys_prio_tardiness
QsysPrioTardiness solver_mva_qsys_prio_tardiness(const qn::NetworkStruct< double > &L, std::string actualmethod)
Definition
solver_mva_qsys_prio_tardiness.h:43
line::qsys::qsys_mmc_prio_tardiness
MmcPrioTardinessResult qsys_mmc_prio_tardiness(const std::vector< double > &lambda, double mu, unsigned c, const std::vector< double > &d, const std::string &type="np", const std::string &method="euler")
Stationary per-class expected tardiness of a priority M/M/c queue.
Definition
qsys_mmc_prio_tardiness.h:191
line
Conservation laws of a layered queueing network, enumerated from its structure.
Definition
aoi_dist2ph.h:52
qsys_mmc_prio_tardiness.h
Exact stationary expected tardiness in a multiclass priority M/M/c queue (Hafizoglu,...
line::mva::QsysPrioTardiness
Avg.Tard (stations x classes, queue row filled) and Avg.SysTard (1 x classes).
Definition
solver_mva_qsys_prio_tardiness.h:34
line::mva::QsysPrioTardiness::Tard
Matrix< double > Tard
Definition
solver_mva_qsys_prio_tardiness.h:35
line::mva::QsysPrioTardiness::empty
bool empty() const
Definition
solver_mva_qsys_prio_tardiness.h:36
line::mva::QsysPrioTardiness::SysTard
Matrix< double > SysTard
Definition
solver_mva_qsys_prio_tardiness.h:35
line::qsys::MmcPrioTardinessResult::Tard
std::vector< double > Tard
per-class E[(T_i - d_i)^+], class 1 first
Definition
qsys_mmc_prio_tardiness.h:176
include
line
solvers
mva
solver_mva_qsys_prio_tardiness.h
Generated by
1.18.0