LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
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
48
#include "
line/api/spn/spn_metrics.h
"
49
#include "
line/api/spn/spn_pf.h
"
50
#include "
line/lang/qn/network_struct.h
"
51
#include "
line/solvers/nc/nc_types.h
"
52
#include "
line/util/matrix.h
"
53
54
namespace
line
{
55
namespace
nc
{
56
57
/** The product-form solve, with the certificate that produced it. */
58
template
<
class
T>
59
struct
NcSpnSolution
{
60
NcSolution<T>
sol
;
61
spn::SpnPfResult<T>
pf
;
62
spn::SpnMetrics<T>
metrics
;
63
};
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
*/
71
template
<
class
T>
72
NcSpnSolution<T>
solver_nc_spn_analyzer
(
const
qn::NetworkStruct<T>
&
sn
,
const
NcSolverOptions
&
opt
) {
73
const
T zero =
num_traits<T>::from_int
(0);
74
const
std::size_t M =
sn
.nstations, R =
sn
.nclasses;
75
76
spn::SpnPfOptions
pfopt;
77
if
(
opt
.tol > 0) pfopt.
tol
= std::max(
opt
.tol, 1e-12);
78
spn::SpnPfResult<T>
pf =
spn::spn_pf<T>
(
sn
, pfopt);
79
const
spn::SpnMetrics<T>
met =
80
spn::spn_metrics<T>
(pf.
spn
.mdds, pf.
g
, pf.
spn
.info);
81
82
NcSpnSolution<T>
out;
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
line::Matrix::Matrix
Matrix()
Definition
matrix.h:58
line::qn::NetworkStruct
A network plus its refreshed NetworkStruct.
Definition
network_struct.h:838
matrix.h
Dense matrix and non-owning view.
line::nc
Definition
nc_dispatch.h:57
line::nc::solver_nc_spn_analyzer
NcSpnSolution< T > solver_nc_spn_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Analyse a product-form stochastic Petri net.
Definition
solver_nc_spn.h:72
line::opt
Definition
bisection_solver.h:31
line::sn
Definition
sn_gd_balance.h:42
line::spn::spn_metrics
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
line::spn::spn_pf
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
line
Definition
aoi_dist2ph.h:52
nc_types.h
Controls and result shape shared by the normalizing-constant analyzers.
network_struct.h
A queueing network and its refreshed NetworkStruct.
spn_metrics.h
Stationary measures of a product-form stochastic Petri net from the MDD-rec masses.
spn_pf.h
Product form of a stochastic Petri net: decide whether one exists and derive the per-level factors g_...
line::nc::NcSolution
The [Q,U,R,T,C,X,lG] of the reference, plus the algorithm that ran.
Definition
nc_types.h:113
line::nc::NcSolverOptions
Controls, defaulting to SolverOptions('NC') in the reference.
Definition
nc_types.h:33
line::nc::NcSpnSolution
The product-form solve, with the certificate that produced it.
Definition
solver_nc_spn.h:59
line::nc::NcSpnSolution::pf
spn::SpnPfResult< T > pf
Definition
solver_nc_spn.h:61
line::nc::NcSpnSolution::metrics
spn::SpnMetrics< T > metrics
Definition
solver_nc_spn.h:62
line::nc::NcSpnSolution::sol
NcSolution< T > sol
Definition
solver_nc_spn.h:60
line::num_traits
Definition
number.h:111
line::spn::SpnMetrics
The stationary measures of Sec.
Definition
spn_metrics.h:53
line::spn::SpnMetrics::place_tput
std::vector< T > place_tput
Place throughput, tokens removed per unit time.
Definition
spn_metrics.h:61
line::spn::SpnMetrics::G
T G
The normalising constant G the measures are taken against.
Definition
spn_metrics.h:55
line::spn::SpnMetrics::tokens
std::vector< T > tokens
Mean tokens per place level.
Definition
spn_metrics.h:57
line::spn::SpnPfOptions
Options of the product-form derivation.
Definition
spn_pf.h:111
line::spn::SpnPfOptions::tol
double tol
Relative tolerance of the rate-law and complex-balance checks.
Definition
spn_pf.h:115
line::spn::SpnPfResult
The product form, and the certificate that it is one.
Definition
spn_pf.h:121
line::spn::SpnPfResult::g
std::vector< std::vector< T > > g
g[l][k] = g_l(k), ready for mdd_rec.
Definition
spn_pf.h:123
line::spn::SpnPfResult::spn
SpnResult< T > spn
Definition
spn_pf.h:136
include
line
solvers
nc
solver_nc_spn.h
Generated by
1.18.0