LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solver_nc_spn.h
Go to the documentation of this file.
1#ifndef LINE_SOLVERS_NC_SOLVER_NC_SPN_H
2#define LINE_SOLVERS_NC_SOLVER_NC_SPN_H
3
4/**
5 * @file solver_nc_spn.h
6 * @ingroup line_solvers
7 * @brief Stationary analysis of a PRODUCT-FORM stochastic Petri net by MDD-rec.
8 *
9 * The normalising constant is obtained from one memoised walk of the decision
10 * diagram holding the reachable set, and every reported measure is a masked walk
11 * of the same diagram.
12 *
13 * This is the `rec` method of SolverNC, and the first analytical route LINE
14 * offers for a Petri net -- CTMC solves the explicit generator, SSA and LDES
15 * simulate, FLD fluidises. Three functions do the work and each is the subject
16 * of its own reference:
17 *
18 * `spn_pf` decides the product form and derives the per-place factors
19 * g_l (Coleman-Henderson-Taylor complex balance)
20 * `mdd_rec` G = sum_S prod_l g_l(s_l) in O(sum_l nodes_l * |S_l|) rather
21 * than O(|S|) (Balsamo-Marin-Stojic)
22 * `spn_metrics` mean tokens, place and mode utilisation, and throughputs, all
23 * from masked walks of the same diagram
24 *
25 * WHAT THIS REACHES THAT THE EXPLICIT GENERATOR DOES NOT. The diagram stores the
26 * reachable set, never the generator, so the cost is set by the number of
27 * diagram nodes and not by |S|. It also does not need the marking to be a
28 * conserved job population: a mode may consume two tokens and produce one, or
29 * consume one and produce two, which is the fork-join and batch case that the
30 * MDD-rec paper exists to serve.
31 *
32 * UN FOLLOWS LINE, NOT THE PAPER. A Place is an INF station, and LINE reports
33 * U = Q at an infinite server, which is what SolverCTMC returns for the same
34 * net. The paper's place utilisation u(P_j) = 1 - P(m_j = 0) is a different
35 * quantity and rides on the returned metrics block instead.
36 *
37 * ARITHMETIC. `spn_pf` needs a transcendental field and says so; everything
38 * downstream of it -- `mdd_rec`, `spn_metrics` -- is rational.
39 *
40 * @see spn_pf, mdd_rec, spn_metrics, spn_mdd
41 */
42
43#include <cmath>
44#include <cstddef>
45#include <string>
46#include <vector>
47
49#include "line/api/spn/spn_pf.h"
52#include "line/util/matrix.h"
53
54namespace line {
55namespace nc {
56
57/** The product-form solve, with the certificate that produced it. */
58template <class T>
64
65/**
66 * Analyse a product-form stochastic Petri net.
67 *
68 * @param sn the struct of a net holding Places and Transitions
69 * @param opt solver controls; `tol` sets the product-form checks' tolerance
70 */
71template <class T>
73 const T zero = num_traits<T>::from_int(0);
74 const std::size_t M = sn.nstations, R = sn.nclasses;
75
77 if (opt.tol > 0) pfopt.tol = std::max(opt.tol, 1e-12);
79 const spn::SpnMetrics<T> met =
80 spn::spn_metrics<T>(pf.spn.mdds, pf.g, pf.spn.info);
81
83 out.pf = pf;
84 out.metrics = met;
85 out.sol.actualmethod = "rec";
86 out.sol.sol.method = "rec";
87 out.sol.sol.iter = 1;
88 out.sol.sol.Q = Matrix<T>(M, R, zero);
89 out.sol.sol.U = Matrix<T>(M, R, zero);
90 out.sol.sol.R = Matrix<T>(M, R, zero);
91 out.sol.sol.Tp = Matrix<T>(M, R, zero);
92 out.sol.sol.X.assign(R, zero);
93 out.sol.sol.C.assign(R, zero);
94
95 for (std::size_t pp = 0; pp < pf.spn.info.places.size(); ++pp) {
96 const std::size_t ist = sn.nodes[pf.spn.info.places[pp] - 1].station;
97 if (ist < 1) continue;
98 out.sol.sol.Q(ist - 1, 0) = met.tokens[pp];
99 // INF station: LINE charges one server per resident token, so U = Q. The
100 // paper's 1 - P(m = 0) is met.place_util, on the returned metrics block.
101 out.sol.sol.U(ist - 1, 0) = met.tokens[pp];
102 out.sol.sol.Tp(ist - 1, 0) = met.place_tput[pp];
103 if (met.place_tput[pp] > zero)
104 out.sol.sol.R(ist - 1, 0) = T(met.tokens[pp] / met.place_tput[pp]);
105 }
106
107 // System throughput at the reference station, and the response time Little's
108 // law then fixes. A net whose class population is not conserved has no
109 // meaningful N/X, so C stays zero there rather than reporting a ratio
110 // against a moving population.
111 const std::size_t ref = sn.classes.empty() ? 0 : sn.classes[0].refstat;
112 if (ref >= 1 && ref <= M) out.sol.sol.X[0] = out.sol.sol.Tp(ref - 1, 0);
113 T Nk = zero;
114 for (std::size_t i = 0; i < M; ++i) Nk += out.sol.sol.Q(i, 0);
115 if (out.sol.sol.X[0] > zero && Nk > zero) out.sol.sol.C[0] = T(Nk / out.sol.sol.X[0]);
116
117 out.sol.sol.lG = std::log(num_traits<T>::to_double(met.G));
118 return out;
119}
120
121} // namespace nc
122} // namespace line
123
124#endif // LINE_SOLVERS_NC_SOLVER_NC_SPN_H
A network plus its refreshed NetworkStruct.
Dense matrix and non-owning view.
NcSpnSolution< T > solver_nc_spn_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Analyse a product-form stochastic Petri net.
SpnMetrics< T > spn_metrics(const mdd::MddStruct &mdds, const std::vector< std::vector< T > > &g, const SpnInfo< T > &info)
Every measure of Sec.
Definition spn_metrics.h:78
SpnPfResult< T > spn_pf(const qn::NetworkStruct< T > &sn, const SpnPfOptions &options=SpnPfOptions())
Derive the product form of a stochastic Petri net.
Definition spn_pf.h:209
Controls and result shape shared by the normalizing-constant analyzers.
A queueing network and its refreshed NetworkStruct.
Stationary measures of a product-form stochastic Petri net from the MDD-rec masses.
Product form of a stochastic Petri net: decide whether one exists and derive the per-level factors g_...
The [Q,U,R,T,C,X,lG] of the reference, plus the algorithm that ran.
Definition nc_types.h:113
Controls, defaulting to SolverOptions('NC') in the reference.
Definition nc_types.h:33
The product-form solve, with the certificate that produced it.
spn::SpnPfResult< T > pf
spn::SpnMetrics< T > metrics
The stationary measures of Sec.
Definition spn_metrics.h:53
std::vector< T > place_tput
Place throughput, tokens removed per unit time.
Definition spn_metrics.h:61
T G
The normalising constant G the measures are taken against.
Definition spn_metrics.h:55
std::vector< T > tokens
Mean tokens per place level.
Definition spn_metrics.h:57
Options of the product-form derivation.
Definition spn_pf.h:111
double tol
Relative tolerance of the rate-law and complex-balance checks.
Definition spn_pf.h:115
The product form, and the certificate that it is one.
Definition spn_pf.h:121
std::vector< std::vector< T > > g
g[l][k] = g_l(k), ready for mdd_rec.
Definition spn_pf.h:123
SpnResult< T > spn
Definition spn_pf.h:136