LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
qsys_ddckk.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_DDCKK_H
6#define LINE_API_QSYS_QSYS_DDCKK_H
7
8/**
9 * @file
10 * @ingroup api_qsys
11 * Exact analysis of the finite-source D/D/c/K/K machine-repair model.
12 *
13 * Port of matlab/src/api/qsys/qsys_ddckk.m. K sources each operate for a
14 * deterministic time EO and then request a deterministic service ES from one
15 * of c servers. After a transient the cycle settles into a periodic regime in
16 * which the per-server utilization is
17 *
18 * a = min(1, K / (c (1 + EO/ES))), X = c a / ES,
19 *
20 * and the response time follows from the cycle law ET = K/X - EO, with no
21 * waiting while the servers are not saturated.
22 *
23 * ARITHMETIC: field. Only min, products and quotients appear, so the
24 * computation is exact for T = Rational.
25 */
26
27#include <string>
28
30#include "line/num/number.h"
31#include "line/util/error.h"
32
33namespace line {
34namespace qsys {
35
36/**
37 * @brief Exact D/D/c/K/K finite-source queue.
38 *
39 * @param EO deterministic operating (think) time, EO >= 0
40 * @param ES deterministic service time, ES > 0
41 * @param c number of servers
42 * @param K number of sources, K >= c
43 * @return MATLAB's result struct: meanQueueLength, meanQueueLengthQ,
44 * meanWaitingTime, meanSojournTime, throughput, utilization,
45 * meanOperating, and analyzer
46 */
47template <class T>
48QsysResT<T> qsys_ddckk(const T& EO, const T& ES, unsigned c, unsigned K) {
49 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
50 if (EO < zero) throw Error("qsys_ddckk: EO must be a non-negative real scalar");
51 if (ES <= zero) throw Error("qsys_ddckk: ES must be a positive real scalar");
52 if (c < 1) throw Error("qsys_ddckk: c must be a positive integer");
53 if (K < c) throw Error("qsys_ddckk: K must be an integer >= c");
54 const T cT = num_traits<T>::from_int(static_cast<long>(c));
55 const T KT = num_traits<T>::from_int(static_cast<long>(K));
56 const T z = T(EO / ES);
57 T a = T(KT / (cT * (one + z)));
58 if (a > one) a = one;
59 const T X = T(cT * a / ES);
60 T ET = T(KT / X - EO);
61 T EW = T(ET - ES);
62 if (EW < zero) EW = zero;
63 ET = T(EW + ES);
65 r.set("meanQueueLength", T(X * ET));
66 r.set("meanQueueLengthQ", T(X * EW));
67 r.set("meanWaitingTime", EW);
68 r.set("meanSojournTime", ET);
69 r.set("throughput", X);
70 r.set("utilization", a);
71 r.set("meanOperating", T(X * EO));
72 r.analyzer = "exact:D/D/" + std::to_string(c) + "/" + std::to_string(K) + "/" + std::to_string(K);
73 return r;
74}
75
76} // namespace qsys
77} // namespace line
78
79#endif // LINE_API_QSYS_QSYS_DDCKK_H
Error(const std::string &what)
Definition error.h:75
The exception types the port throws.
QsysResT< T > qsys_ddckk(const T &EO, const T &ES, unsigned c, unsigned K)
Exact D/D/c/K/K finite-source queue.
Definition qsys_ddckk.h:48
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:52
Number-type abstraction for the templated API port.
The res struct the exact queueing-system functions return, and the numeric helpers those functions sh...
MATLAB's res struct: named measures in insertion order, plus res.analyzer.
Definition qsys_res.h:57
std::string analyzer
Definition qsys_res.h:59
void set(const std::string &name, const T &v)
Sets (or overwrites) a scalar field.
Definition qsys_res.h:62