5#ifndef LINE_SOLVERS_NC_SOLVER_NC_CACHEQN_H
6#define LINE_SOLVERS_NC_SOLVER_NC_CACHEQN_H
82 "solver_nc_cacheqn_analyzer: the integrated caching-queueing decomposition alternates "
83 "two tolerance-stopped solves and needs transcendental arithmetic");
91 for (
const auto& kv :
sn.nodeparam) {
94 for (
int c : ch.
itemcap) capsum += c;
95 if (
static_cast<long>(ch.
nitems) < capsum + 2)
97 "solver_nc_cacheqn_analyzer: NC requires the number of items to exceed the "
98 "cache capacity at least by 2; this cache holds " +
99 std::to_string(ch.
nitems) +
" items with total capacity " +
100 std::to_string(capsum));
103 const bool exact = (
opt.method ==
"exact");
112 for (
const auto& kv :
sn.nodeparam) {
117 "solver_nc_cacheqn_analyzer: NC does not support the exact solution of "
118 "this cache replacement policy -- only RR and FIFO are exchangeable, and "
119 "a recency-based policy (LRU, h-LRU, q-LRU, CLIMB) would silently receive "
120 "the exchangeable answer. Use the default (approximate) method or "
125 std::string sizedMethod;
136 std::function<std::vector<T>(
const Matrix<T>&,
const std::vector<int>&,
138 const std::vector<int>&)>
139 missfun = [exact, netopt, &sizedMethod](
const Matrix<T>& gamma,
const std::vector<int>& m,
140 const std::vector<Matrix<T> >& lambda_cache,
142 const std::vector<int>& parent) -> std::vector<T> {
143 const std::size_t u = lambda_cache.size();
145 if (u == 0)
return missrate;
146 const std::size_t n = lambda_cache[0].rows();
147 if (!ch.itemsize.empty()) {
156 for (std::size_t v = 0; v < u; ++v) {
158 for (std::size_t k = 0; k < n && k < pij.
rows(); ++k)
159 acc = T(acc + lambda_cache[v](k, 0) * pij(k, 0));
164 for (std::size_t v = 0; v < u; ++v)
165 for (std::size_t k = 0; k < n; ++k) lam_un(v, k) = lambda_cache[v](k, 0);
167 for (std::size_t v = 0; v < mr.MU.size() && v < u; ++v) missrate[v] = mr.MU[v];
181 out.
sol.actualmethod = !sizedMethod.empty() ? sizedMethod : (exact ?
"exact" :
"spm");
182 out.
sol.sol.method = out.
sol.actualmethod;
188 out.
listcost.assign(r.
info.gamma.size(), std::vector<T>());
189 for (std::size_t ci = 0; ci < r.
info.gamma.size() && ci < out.
itemprob.size(); ++ci) {
190 const std::vector<int>& sigma = r.
info.itemsize[ci];
192 if (!sigma.empty() && ip.
rows() == sigma.size() && ip.
cols() == r.
info.itemcap[ci].size() + 1)
194 r.
info.costcap[ci], ip);
209 bool hasCache =
false;
211 if (nd.
nodetype == qn::NodeType::Cache) hasCache =
true;
Mean per-list storage cost of a cache with item sizes, and the screen for promotion paths that storag...
Saddle-point approximation of the cache miss rates.
Exact per-item hit and miss probabilities of a multi-list cache.
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
Decomposition-aggregation driver for integrated cache-queueing models, a port of matlab/src/api/da/da...
The exception types the port throws.
std::vector< T > cache_cost(const Matrix< T > &gamma, const std::vector< int > &m, const std::vector< int > &sigma, const std::vector< int > &k, const Matrix< T > &pij)
Mean per-list storage cost of a cache with item sizes, and the screen for promotion paths that storag...
Matrix< T > cache_prob_erec(const Matrix< T > &gamma, const std::vector< int > &m, const std::vector< int > &sigma, const std::vector< int > &k)
Per-item hit and miss probabilities under per-list storage cost caps, pi_ij = m_j gamma(i,...
CacheMissSpmResult< T > cache_miss_spm(const Matrix< T > &gamma, const std::vector< int > &m, const Matrix< T > &lambda)
Saddle-point approximation of the cache miss rates.
std::vector< Matrix< T > > da_cacheqn_itemprob(const CacheqnInfo< T > &info)
Per-item occupancy of every cache from the CONVERGED access factors.
CacheqnResult< T > da_cacheqn(qn::NetworkStruct< T > sn, bool exact, const mva::MvaOptions &opt, const std::function< mva::MvaSolution< T >(const qn::NetworkStruct< T > &)> &netfun, const std::function< std::vector< T >(const Matrix< T > &, const std::vector< int > &, const std::vector< Matrix< T > > &, const qn::CacheParam< T > &, const std::vector< int > &)> &missfun=nullptr)
Decomposition-aggregation driver for integrated cache-queueing models, a port of matlab/src/api/da/da...
@ FIFO
first in, first out
bool nc_is_cacheqn(const qn::NetworkStruct< T > &sn)
True when the model has a Cache node and is not the Source-Cache-Sink shape.
NcCacheMiss< T > nc_cache_missrate(const Matrix< T > &gamma, const std::vector< int > &parent, const std::vector< int > &m, std::size_t n, const std::vector< Matrix< T > > &lambda, const qn::CacheParam< T > &ch, const NcSolverOptions &opt)
Miss rates of an isolated cache under opt.method, honouring the per-item storage costs and per-list c...
NcCacheqnSolution< T > solver_nc_cacheqn_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_cacheqn_analyzer.m.
NcSolution< T > nc_dispatch(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of @@SolverNC/ncDispatch.m: the inner solve of the fork-join fixed point, which is the load-depe...
Conservation laws of a layered queueing network, enumerated from its structure.
Port of solver_nc_analyzer.m, solver_ncld_analyzer.m and @@SolverNC/ncDispatch.m: one inner solve,...
Controls and result shape shared by the normalizing-constant analyzers.
A queueing network and its refreshed NetworkStruct.
Port of solver_nc_cache_analyzer.m: the NON-REENTRANT cache, a model that is exactly a Source,...
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Return value of cache_miss_spm, mirroring [M,MU,MI,pi0,lE].
Matrix< T > missprob
(ncaches x nclasses)
Matrix< T > hitprob
(ncaches x nclasses)
mva::MvaSolution< T > res
The options SolverMVA reads.
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
Miss rates of one isolated cache and what produced them; see nc_cache_missrate.
std::vector< T > missRate
(u) miss rate of each user class
What the integrated analyzer returns: the metrics plus the converged split.
Matrix< T > hitprob
(ncaches x nclasses) converged hit probability
Matrix< T > missprob
(ncaches x nclasses)
qn::NetworkStruct< T > refreshed
The struct whose cache self-switch carries the CONVERGED split rather than the offered one,...
std::vector< std::vector< T > > listcost
per cache, (h) mean storage cost per list; EMPTY without item sizes
std::vector< Matrix< T > > itemprob
per cache, (n x h+1); EMPTY = not computed
The [Q,U,R,T,C,X,lG] of the reference, plus the algorithm that ran.
Controls, defaulting to SolverOptions('NC') in the reference.
The parameters of a Cache node, MATLAB's sn.nodeparam{ind} for a Cache.
std::vector< int > itemcap
lang::ReplacementStrategy replacestrat