LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
sn_renewal_lst.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_SN_SN_RENEWAL_LST_H
6#define LINE_API_SN_SN_RENEWAL_LST_H
7
8/**
9 * @file
10 * @ingroup api_sn
11 * Port of matlab/src/api/sn/sn_renewal_lst.m.
12 *
13 * The Laplace-Stieltjes transform of the inter-arrival law of class 1 at
14 * station `ist`, when that law is a renewal process; empty otherwise.
15 *
16 * A Markovian law (D0, D1) is renewal when D1 has rank at most one; then
17 * LA(s) = pie (sI - D0)^{-1} D1 e with pie = map_pie. A Markovian law whose D1
18 * has a higher rank (a correlated MAP) has no renewal transform and answers
19 * empty, as the reference returns there without looking further. A
20 * non-Markovian law answers its `sn.lst` handle, when it has one.
21 *
22 * ARITHMETIC: the transform is evaluated in double (it feeds the GI/M/c root
23 * search, which is double), whatever the struct's arithmetic.
24 */
25
26#include <complex>
27#include <cstddef>
28#include <functional>
29#include <vector>
30
35#include "line/num/number.h"
36#include "line/util/eig.h"
37#include "line/util/lu.h"
38#include "line/util/matrix.h"
39
40namespace line {
41namespace api {
42
43/** A real-argument Laplace-Stieltjes transform; empty when there is none. */
44using RenewalLst = std::function<double(double)>;
45
46/**
47 * @brief Renewal inter-arrival LST of class 1 at station `ist` (1-based).
48 * @return the transform s -> LA(s), or an empty function when there is none
49 */
50template <class T>
52 if (ist < 1 || ist > sn.service.size() || sn.service[ist - 1].empty()) return {};
53 const lang::Distrib<T>& d = sn.service[ist - 1][0];
54 if (lang::process_is_markovian(sn.procid(ist, 1))) {
55 if (d.disabled || d.is_prior()) return {};
56 Matrix<T> D0, D1;
57 if (d.has_map()) {
58 D0 = d.D0;
59 D1 = d.D1;
60 } else {
61 const mam::Map<T> m = lang::dist_to_map(d);
62 D0 = m.D0;
63 D1 = m.D1;
64 }
65 const std::size_t n = D0.rows();
66 if (n == 0 || D0.cols() != n || D1.rows() != n || D1.cols() != n) return {};
67 Matrix<double> D0d(n, n), D1d(n, n);
68 for (std::size_t i = 0; i < n; ++i)
69 for (std::size_t j = 0; j < n; ++j) {
70 D0d(i, j) = num_traits<T>::to_double(D0(i, j));
71 D1d(i, j) = num_traits<T>::to_double(D1(i, j));
72 }
73 if (matrix_rank(D1d) > 1) return {};
75 md.D0 = D0d;
76 md.D1 = D1d;
77 const std::vector<double> pie = mam::map_pie(md);
78 std::vector<double> e1(n, 0.0);
79 for (std::size_t i = 0; i < n; ++i)
80 for (std::size_t j = 0; j < n; ++j) e1[i] += D1d(i, j);
81 return [pie, D0d, e1, n](double s) {
82 Matrix<double> A(n, n);
83 for (std::size_t i = 0; i < n; ++i)
84 for (std::size_t j = 0; j < n; ++j) A(i, j) = (i == j ? s : 0.0) - D0d(i, j);
85 const std::vector<double> x = solve(A, e1);
86 double v = 0.0;
87 for (std::size_t i = 0; i < n; ++i) v += pie[i] * x[i];
88 return v;
89 };
90 }
91 const auto handles = sn.lst();
92 if (ist - 1 < handles.size() && !handles[ist - 1].empty() && handles[ist - 1][0]) {
93 const auto h = handles[ist - 1][0];
94 return [h](double s) { return h(std::complex<double>(s, 0.0)).real(); };
95 }
96 return {};
97}
98
99} // namespace api
100} // namespace line
101
102#endif // LINE_API_SN_SN_RENEWAL_LST_H
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
A network plus its refreshed NetworkStruct.
What refreshProcessRepresentations and refreshLST compute FROM a distribution: the (D0,...
Eigenvalues and singular values, backed by LAPACK.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
LU factorization with partial pivoting, templated on the number type.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
RenewalLst sn_renewal_lst(const qn::NetworkStruct< T > &sn, std::size_t ist)
Renewal inter-arrival LST of class 1 at station ist (1-based).
std::function< double(double)> RenewalLst
A real-argument Laplace-Stieltjes transform; empty when there is none.
mam::Map< T > dist_to_map(const Distrib< T > &d)
The (D0,D1) pair that reaches sn.proc.
bool process_is_markovian(ProcessType p)
ProcessType.isMarkovian: true when sn.proc carries an exact matrix representation of the law,...
Definition lang_types.h:713
std::vector< T > map_pie(const Map< T > &m)
Phase distribution seen by an arriving job, pie = pi D1 / (pi D1 e).
Definition map_moment.h:89
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
std::vector< T > solve(const Matrix< T > &A, const std::vector< T > &b)
Convenience: solve Ax = b, leaving A and b untouched.
Definition lu.h:158
std::size_t matrix_rank(const Matrix< double > &A)
Numerical rank at the standard max(m,n) eps sigma_1 threshold.
Definition eig.h:316
A queueing network and its refreshed NetworkStruct.
Number-type abstraction for the templated API port.
bool has_map() const
True when the type carries a (D0,D1) pair of its own.
Matrix< T > D0
The (D0,D1) pair when the type carries one directly.
Definition lang_types.h:921
bool is_prior() const
Definition lang_types.h:961
A MAP as the pair of matrices (D0, D1).
Definition map_moment.h:53
Matrix< T > D1
Definition map_moment.h:55
Matrix< T > D0
Definition map_moment.h:54