5#ifndef LINE_API_DA_DA_CACHEQN_H
6#define LINE_API_DA_DA_CACHEQN_H
53 std::vector<std::vector<std::vector<Matrix<T> > > >
Rcost;
54 std::vector<lang::ReplacementStrategy>
strat;
84 for (std::size_t ci = 0; ci < info.
gamma.size(); ++ci) {
85 if (info.
gamma[ci].rows() == 0)
continue;
86 const std::size_t ni = info.
gamma[ci].rows();
87 const std::size_t hi = info.
itemcap[ci].size();
89 std::vector<T> mT(hi);
90 for (std::size_t l = 0; l < hi; ++l)
98 std::numeric_limits<double>::quiet_NaN()));
136 const std::function<std::vector<T>(
const Matrix<T>&,
137 const std::vector<int>&,
142 const std::size_t I =
sn.nodes.size(), K =
sn.nclasses;
144 std::vector<std::size_t> caches;
145 for (std::size_t nd = 0; nd < I; ++nd)
146 if (
sn.nodes[nd].nodetype == qn::NodeType::Cache) caches.push_back(nd);
147 const std::size_t ncaches = caches.size();
151 std::vector<std::vector<bool> > conn(I, std::vector<bool>(I,
false));
152 for (std::size_t a = 0; a < I; ++a)
153 for (std::size_t b = 0; b < I; ++b) {
154 if (a == b)
continue;
155 for (std::size_t r = 0; r < K && !conn[a][b]; ++r)
156 for (std::size_t s = 0; s < K && !conn[a][b]; ++s)
157 if (
sn.rtnodes(a * K + r, b * K + s) > zero) conn[a][b] =
true;
163 outr.
info.gamma.resize(ncaches);
164 outr.
info.itemcap.resize(ncaches);
165 outr.
info.lambda_cache.resize(ncaches);
166 outr.
info.Rcost.resize(ncaches);
167 outr.
info.strat.resize(ncaches);
170 std::vector<T> lambda0(K, zero);
171 for (std::size_t ci = 0; ci < ncaches; ++ci) {
173 for (std::size_t r = 0; r < ch.
hitclass.size(); ++r)
176 sn.nodes[caches[ci]].nodetype = qn::NodeType::ClassSwitch;
188 auto sweep = [&](
const std::vector<T>& x,
189 std::size_t) -> std::pair<std::vector<T>, std::vector<T> > {
190 std::vector<T> lambda = x;
191 for (std::size_t ci = 0; ci < ncaches; ++ci) {
192 const std::size_t ind = caches[ci];
208 std::vector<T> missrate(K, zero);
211 for (std::size_t v = 0; v < mr.size() && v < K; ++v) missrate[v] = mr[v];
214 const std::size_t n = cm.
pij.rows(), h = cm.
pij.cols();
215 std::vector<T> pmiss(n, zero);
216 for (std::size_t k = 0; k < n; ++k) {
218 for (std::size_t l = 0; l < h; ++l) s = T(s + cm.
pij(k, l));
219 pmiss[k] = T(one - s);
221 for (std::size_t v = 0; v < iso.
lambda_cache.size() && v < K; ++v) {
223 for (std::size_t k = 0; k < n; ++k)
230 const std::size_t n = ch.
nitems;
232 for (std::size_t v = 0; v < u; ++v)
233 for (std::size_t k = 0; k < n; ++k) lam_un(v, k) = iso.
lambda_cache[v](k, 0);
236 for (std::size_t v = 0; v < mr.
MU.size() && v < K; ++v) missrate[v] = mr.
MU[v];
239 for (std::size_t r = 0; r < K; ++r) {
240 if (lambda[r] > zero) {
241 outr.
missprob(ci, r) = T(missrate[r] / lambda[r]);
255 for (std::size_t r = 0; r < ch.
hitclass.size(); ++r) {
258 for (std::size_t col = 0; col < I * K; ++col)
sn.rtnodes(ind * K + r, col) = zero;
259 for (std::size_t jnd = 0; jnd < I; ++jnd) {
260 if (!conn[ind][jnd])
continue;
261 sn.rtnodes(ind * K + r, jnd * K + hc) = outr.
hitprob(ci, r);
262 sn.rtnodes(ind * K + r, jnd * K +
mc) = outr.
missprob(ci, r);
272 for (std::size_t i = 0; i < I; ++i) {
273 if (
sn.nodes[i].nodetype == qn::NodeType::Cache ||
274 sn.nodes[i].nodetype == qn::NodeType::ClassSwitch)
276 std::size_t nsucc = 0;
277 for (std::size_t j = 0; j < I; ++j)
278 if (conn[i][j]) ++nsucc;
279 if (nsucc == 0)
continue;
281 for (std::size_t s = 0; s < K; ++s) {
283 for (std::size_t col = 0; col < I * K; ++col) rowsum = T(rowsum +
sn.rtnodes(i * K + s, col));
284 if (rowsum > zero)
continue;
285 for (std::size_t j = 0; j < I; ++j)
286 if (conn[i][j])
sn.rtnodes(i * K + s, j * K + s) = share;
289 sn.da_recompute_visits_from_rtnodes();
291 lastres = netfun(
sn);
295 for (std::size_t c = 0; c <
sn.nchains; ++c)
296 for (std::size_t a = 0; a < I; ++a)
297 for (std::size_t r = 0; r < K; ++r) nv(a, r) = T(nv(a, r) +
sn.nodevisits[c](a, r));
300 for (std::size_t ci = 0; ci < ncaches; ++ci) {
301 const std::size_t ind = caches[ci];
303 for (std::size_t r = 0; r < ch.
hitclass.size(); ++r) {
306 std::size_t c =
sn.nchains;
307 for (std::size_t cc = 0; cc <
sn.nchains; ++cc)
308 if (
sn.chains[cc][r]) { c = cc;
break; }
309 if (c ==
sn.nchains)
continue;
311 for (std::size_t k :
sn.inchain[c]) xsum = T(xsum + lastres.
X[k - 1]);
312 const std::size_t rstat =
sn.classes[r].refstat;
313 const std::size_t refnode =
sn.station_to_node[rstat - 1] - 1;
314 const std::size_t refcls =
315 (
sn.refclass[c] > 0) ?
sn.refclass[c] - 1 : r;
316 const T denom = nv(refnode, refcls);
317 if (denom > zero) lambda[r] = T(xsum * nv(ind, r) / denom);
320 return std::make_pair(lambda, x);
Cache miss rates from the fixed-point multipliers.
Exact mean value analysis of a multi-list cache.
Exact per-item hit and miss probabilities of a multi-list cache.
TTL (characteristic-time) approximation of an LRU cache whose lists form an arbitrary access graph.
A network plus its refreshed NetworkStruct.
Isolated-cache input construction for the decomposition methods.
Damped fixed-point iteration, the shared driver of the decomposition algorithms.
Dense matrix and non-owning view.
The option and result types every MVA analyzer shares.
CacheMvaResult< T > cache_mva(const Matrix< T > &gamma, const std::vector< int > &m)
Exact mean value analysis of a multi-list cache.
CacheMissResult< T > cache_miss_fpi(const Matrix< T > &gamma, const std::vector< int > &m, const Matrix< T > &lambda)
Cache miss rates from the fixed-point multipliers.
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,...
Matrix< T > cache_ttl_lrua(const Matrix< T > &lambda, const std::vector< Matrix< T > > &R, const std::vector< T > &m, const T &tol, unsigned maxswp=200)
TTL (characteristic-time) approximation of an LRU cache whose lists form an arbitrary access graph.
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 > &)> &missfun=nullptr)
Decomposition-aggregation driver for integrated cache-queueing models, a port of matlab/src/api/da/da...
std::vector< Matrix< T > > da_cacheqn_itemprob(const CacheqnInfo< T > &info)
Per-item occupancy of every cache from the CONVERGED access factors.
FpiResult< T > da_fpi(const std::function< std::pair< std::vector< T >, std::vector< T > >(const std::vector< T > &, std::size_t)> &iterfun, const std::vector< T > &x0, const FpiOptions &options=FpiOptions())
Damped fixed-point iteration, the shared driver of the decomposition algorithms.
CacheIsolateResult< T > da_cache_isolate(const CacheParam< T > &ch, const std::vector< T > &lambda)
Isolated-cache input construction for the decomposition methods.
A queueing network and its refreshed NetworkStruct.
Return value of cache_miss, mirroring [M,MU,MI,pi0].
std::vector< T > MU
(u) per-user miss rate; empty when no lambda given
Return value of cache_mva, mirroring [pi,pi0,pij,x,u,E].
Matrix< T > pij
(n x h) probability that item k sits in list l
Return value of da_cache_isolate, mirroring [gamma,lambda_cache,Rcost].
std::vector< Matrix< T > > lambda_cache
(u) matrices of size n x (h+1)
Matrix< T > gamma
(n x h) access factors
std::vector< std::vector< Matrix< T > > > Rcost
(u x n) of (h+1)x(h+1)
The fields of sn.nodeparam{cache} that da_cache_isolate reads.
std::vector< int > itemcap
(h) list capacities
std::vector< std::vector< Matrix< T > > > accost
(u) x (n) of (h+1)x(h+1), or empty
std::vector< std::vector< T > > pread
(u) x (n), empty row = NaN
The converged isolated-cache inputs, kept for per-item occupancy reporting.
std::vector< lang::ReplacementStrategy > strat
std::vector< std::vector< std::vector< Matrix< T > > > > Rcost
std::vector< Matrix< T > > gamma
per cache: (n x h)
std::vector< std::vector< int > > itemcap
per cache
std::vector< std::vector< Matrix< T > > > lambda_cache
per cache: (u) of n x (h+1)
Matrix< T > missprob
(ncaches x nclasses)
Matrix< T > hitprob
(ncaches x nclasses)
mva::MvaSolution< T > res
Options mirroring the fields MATLAB reads off the options struct.
static constexpr double FineTol
The options SolverMVA reads.
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
std::vector< std::vector< Matrix< T > > > accost
(u) x (n) of (h+1)x(h+1), or empty
std::vector< int > itemcap
std::vector< std::size_t > missclass
std::vector< std::size_t > hitclass
lang::ReplacementStrategy replacestrat
std::vector< std::vector< T > > pread
(u) x (n), empty row = NaN