LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solver_default_cdf.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#pragma once
6
7/**
8 * @file
9 * @ingroup line_solvers
10 * The base-class fallback for a response-time CDF.
11 *
12 * What a solver returns for `cdf_respt` when it has no distributional result of
13 * its own: an exponential curve with the station's mean response time. It is a
14 * placeholder with the right first moment, not an approximation with a claim on
15 * the shape, so a solver that can do better must override it rather than call
16 * this.
17 */
18
19#include <cmath>
20#include <vector>
21
23#include "line/num/number.h"
24
25namespace line {
26namespace solvers {
27
28/** One [F(t), t] curve of the base-class response-time CDF fallback. */
30 std::vector<double> t; ///< time points
31 std::vector<double> F; ///< CDF values, F[j] = P(R <= t[j])
32};
33
34/**
35 * The NetworkSolver base-class response-time CDF: an exponential law with the
36 * right mean per (station, class), tabulated on 100 quantile points.
37 *
38 * This is `@@NetworkSolver/getCdfRespT.m` verbatim -- "a trivial approximation
39 * that assumes exponential distributions everywhere with mean as RN(i,r)" --
40 * and it is what the reference serves for every solver without a
41 * distributional result of its own (MVA, QNS, BA, AG). It says nothing about
42 * the tail; the solvers with a real law (CTMC, NC, Fluid, MAM, JMT, LDES)
43 * never reach it, and SSA refuses instead of inheriting it.
44 *
45 * A Source station is left with empty curves, as the reference leaves its
46 * cells empty; a served cell whose mean is non-finite or non-positive gets the
47 * reference's degenerate [1, 0] point mass at zero.
48 */
49template <class T>
50std::vector<std::vector<DefaultCdfCurve>> solver_default_cdf_respt(
51 const qn::NetworkStruct<T>& sn, const Matrix<T>& RN) {
52 const std::size_t M = sn.nstations;
53 const std::size_t K = sn.nclasses;
54 std::vector<std::vector<DefaultCdfCurve>> RD(M, std::vector<DefaultCdfCurve>(K));
55 const std::size_t npts = 100;
56 for (std::size_t i = 0; i < M; ++i) {
57 if (sn.stations[i].nodetype == lang::NodeType::Source) continue;
58 for (std::size_t c = 0; c < K; ++c) {
59 const double rn = (i < static_cast<std::size_t>(RN.rows()) &&
60 c < static_cast<std::size_t>(RN.cols()))
61 ? num_traits<T>::to_double(RN(i, c))
62 : 0.0;
63 DefaultCdfCurve& cell = RD[i][c];
64 if (std::isfinite(rn) && rn > 0.0) {
65 cell.t.reserve(npts);
66 cell.F.reserve(npts);
67 for (std::size_t j = 0; j < npts; ++j) {
68 const double q =
69 0.001 + (0.999 - 0.001) * static_cast<double>(j) / (npts - 1);
70 cell.F.push_back(q);
71 cell.t.push_back(-std::log(1.0 - q) * rn);
72 }
73 } else {
74 cell.F.push_back(1.0);
75 cell.t.push_back(0.0);
76 }
77 }
78 }
79 return RD;
80}
81
82} // namespace solvers
83} // namespace line
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
A network plus its refreshed NetworkStruct.
std::vector< std::vector< DefaultCdfCurve > > solver_default_cdf_respt(const qn::NetworkStruct< T > &sn, const Matrix< T > &RN)
The NetworkSolver base-class response-time CDF: an exponential law with the right mean per (station,...
A queueing network and its refreshed NetworkStruct.
Number-type abstraction for the templated API port.
One [F(t), t] curve of the base-class response-time CDF fallback.
std::vector< double > t
time points
std::vector< double > F
CDF values, F[j] = P(R <= t[j]).