LINE Solver (C++)
Templated C++ port of the LINE queueing solver
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
29
30namespace line {
31namespace mva {
32
33/** `Avg.Tard` (stations x classes, queue row filled) and `Avg.SysTard` (1 x classes). */
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 */
44 std::string actualmethod) {
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
A network plus its refreshed NetworkStruct.
std::vector< JobClass > classes
std::vector< Station< T > > stations
stations[k-1] is the k-th station
Matrix< T > rates
(nstations x nclasses) service rates and SCVs, with a PARALLEL disabled flag instead of MATLAB's NaN ...
Port of @@SolverMVA/mvaDispatch.m: one inner solve, choosing the analyzer that fits the model.
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...
QsysPrioTardiness solver_mva_qsys_prio_tardiness(const qn::NetworkStruct< double > &L, std::string actualmethod)
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.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:52
Exact stationary expected tardiness in a multiclass priority M/M/c queue (Hafizoglu,...
Avg.Tard (stations x classes, queue row filled) and Avg.SysTard (1 x classes).
std::vector< double > Tard
per-class E[(T_i - d_i)^+], class 1 first