5#ifndef LINE_SOLVERS_MVA_SOLVER_MVA_RETRIEVAL_H
6#define LINE_SOLVERS_MVA_SOLVER_MVA_RETRIEVAL_H
56 "solver_mva_retrieval_analyzer: the delayed-hit retrieval fixed point needs "
57 "transcendental arithmetic; rerun with --arith double or --arith real");
81 for (std::size_t i = 0; i < n; ++i) lamsum = T(lamsum + in.
lambda[i]);
82 std::vector<T> w(n, zero);
83 for (std::size_t i = 0; i < n; ++i) w[i] = lamsum > zero ? T(in.
lambda[i] / lamsum) : zero;
84 T hitAgg = zero, missAgg = zero, delayedAgg = zero;
85 for (std::size_t i = 0; i < n; ++i) {
87 for (std::size_t l = 0; l < fp.
phit.rows(); ++l) pih = T(pih + fp.
phit(l, i));
88 missAgg = T(missAgg + w[i] * fp.
pmiss[i]);
89 hitAgg = T(hitAgg + w[i] * pih);
90 delayedAgg = T(delayedAgg + w[i] * lat.
phi[i]);
98 cache_out->hitprob.assign(K, nan);
99 cache_out->missprob.assign(K, nan);
100 cache_out->delayedprob.assign(K, nan);
101 cache_out->latency.assign(K, nan);
102 if (jobin >= 1 && jobin <= K) {
103 cache_out->hitprob[jobin - 1] = hitAgg;
104 cache_out->missprob[jobin - 1] = missAgg;
105 cache_out->delayedprob[jobin - 1] = delayedAgg;
106 cache_out->latency[jobin - 1] = lat.
Z;
110 const std::size_t h = fp.
phit.rows();
111 cache_out->hitproblist =
Matrix<T>(K, h, nan);
112 if (jobin >= 1 && jobin <= K)
113 for (std::size_t l = 0; l < h; ++l) {
115 for (std::size_t i = 0; i < n; ++i) acc = T(acc + fp.
phit(l, i) * w[i]);
116 cache_out->hitproblist(jobin - 1, l) = acc;
119 cache_out->itemprob =
Matrix<T>(n, h + 1, zero);
120 for (std::size_t i = 0; i < n; ++i) {
121 cache_out->itemprob(i, 0) = fp.
pmiss[i];
122 for (std::size_t l = 0; l < h; ++l) cache_out->itemprob(i, l + 1) = fp.
phit(l, i);
129 L.
disabled[src_st - 1][jobin - 1] ? zero : L.
rates(src_st - 1, jobin - 1);
130 s.
Tp(src_st - 1, jobin - 1) = sourceRate;
133 if (L.
nodes[kv.first - 1].nodetype == qn::NodeType::Cache)
return kv.second;
134 throw InputError(
"solver_mva_retrieval_analyzer: no cache");
136 const std::size_t hc = (jobin - 1) < ch.
hitclass.size() ? ch.
hitclass[jobin - 1] : 0;
138 if (hc > 0) s.
X[hc - 1] = T(sourceRate * (hitAgg + delayedAgg));
139 if (
mc > 0) s.
X[
mc - 1] = T(sourceRate * missAgg);
142 std::vector<std::size_t> psIdx;
143 for (std::size_t si = 0; si < S; ++si)
145 for (std::size_t si = 0; si < S; ++si) {
147 std::size_t prow = 0;
149 for (std::size_t p = 0; p < psIdx.size(); ++p)
150 if (psIdx[p] == si) prow = 1 + p;
153 if (prow < fp.
pdh.rows())
154 for (std::size_t i = 0; i < n; ++i) phi_s = T(phi_s + fp.
pdh(prow, i));
157 for (std::size_t i = 0; i < n; ++i) {
159 std::vector<T> a(S, zero);
160 for (std::size_t x = 0; x < S; ++x) {
161 a[x] = in.
R[i](0, x + 1);
162 for (std::size_t y = 0; y < S; ++y)
164 in.
R[i](x + 1, y + 1));
168 for (std::size_t y = 0; y < S; ++y) vis = T(vis + a[y] * F(y, si));
169 tput_s = T(tput_s + sourceRate * w[i] * fp.
pmiss[i] * vis);
171 s.
Q(st - 1, jobin - 1) = phi_s;
172 s.
U(st - 1, jobin - 1) = phi_s;
173 s.
Tp(st - 1, jobin - 1) = tput_s;
174 if (tput_s > zero) s.
R(st - 1, jobin - 1) = T(phi_s / tput_s);
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
std::size_t sourceIdx
1-based station index of the Source, 0 = none
std::vector< std::vector< bool > > disabled
std::map< std::size_t, CacheParam< T > > nodeparam
Cache parameters by 1-based NODE index; only Cache nodes have an entry.
Matrix< T > rates
(nstations x nclasses) service rates and SCVs, with a PARALLEL disabled flag instead of MATLAB's NaN ...
std::vector< NodeDef > nodes
every node, in creation order
Dense linear algebra over the templated number type: products, identity, inverse, and powers.
The option and result types every MVA analyzer shares.
MvaSolution< T > solver_mva_retrieval_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt, MvaRetrievalCacheOutputs< T > *cache_out=nullptr)
RetrievalInputs< T > cache_retrieval_inputs(const qn::NetworkStruct< T > &sn, double lambda_override=-1.0)
Extract the delayed-hit retrieval-algorithm inputs from a NetworkStruct, a port of matlab/src/api/ret...
RetrievalFpiLatencyResult< T > retrieval_fpi_latency(const std::vector< int > &m, const std::vector< T > &lambda, const Matrix< T > &gamma, const std::vector< RetrievalStationPH< T > > &station, const std::vector< Matrix< T > > &R, const FpiOptions &options=FpiOptions())
FPI-based approximation of the delayed-hit count and the expected latency of a list-based cache with ...
RetrievalFpiResult< T > retrieval_fpi(const std::vector< int > &m, const std::vector< T > &lambda, const Matrix< T > &eta, const Matrix< T > &gamma, const FpiOptions &options=FpiOptions())
Fixed-point heuristic for a delayed-hit (list-based) cache.
Matrix< T > inverse(const Matrix< T > &A)
Inverse by LU with one factorization and n back substitutions.
Fixed-point heuristic for a delayed-hit (list-based) cache.
FPI-based approximation of the delayed-hit count and the expected latency of a list-based cache with ...
The options SolverMVA reads.
The cache half of the reference's return list: hitprob, missprob, delayedprob, latency,...
std::vector< T > missprob
Matrix< T > itemprob
(n x h+1), column 0 = miss
Matrix< T > hitproblist
(K x h)
std::vector< T > delayedprob
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
std::vector< std::size_t > missclass
std::vector< std::size_t > hitclass
Mirrors the [Z, d, phi, pi0] return list of the MATLAB function.
T Z
expected latency of the delayed-hit system
std::vector< T > phi
(n) delayed-hit ratio phi_i
Mirrors the [pmiss, phit, pdh] return list, plus the iteration diagnostics.
Matrix< T > phit
(h x n) hit ratios pi_{i,j}
Matrix< T > pdh
((r+1) x n) delayed-hit probabilities phi_{s,i}, s = 0..r
std::vector< T > pmiss
(n) miss ratios pi_{i,0}