5#ifndef LINE_API_CACHE_T_LRUM_MAP_H
6#define LINE_API_CACHE_T_LRUM_MAP_H
61std::vector<T> lrum_map_occupancy(
const std::vector<mam::Map<T>>& items,
const std::vector<T>& Tv) {
62 std::vector<T> occ(Tv.size(), num_traits<T>::from_int(0));
63 for (std::size_t k = 0; k < items.size(); ++k) {
64 const CacheLrumMapLevelStats<T> st =
66 for (std::size_t l = 0; l < Tv.size(); ++l) occ[l] += st.occ[l];
84 const T& tol,
unsigned maxswp = 200) {
86 "cache_t_lrum_map requires transcendental arithmetic");
87 const std::size_t n = items.size();
88 const std::size_t h = m.size();
89 if (n == 0)
throw InputError(
"cache_t_lrum_map: no items");
90 if (h == 0)
throw InputError(
"cache_t_lrum_map: no lists");
93 for (std::size_t l = 0; l < h; ++l) {
94 if (!(m[l] > zero))
throw InputError(
"cache_t_lrum_map: list capacities must be positive");
98 throw InputError(
"cache_t_lrum_map: the cache is not smaller than the item catalogue");
101 for (
unsigned sweep = 0; sweep < maxswp; ++sweep) {
102 const std::vector<T> Told = Tv;
103 for (std::size_t l = 0; l < h; ++l) {
104 std::vector<T> work = Tv;
107 auto resid = [&](
const T& x) {
109 return T(detail::lrum_map_occupancy(items, work)[l] - m[l]);
113 if (!(resid(lo) < zero))
114 throw NumericError(
"cache_t_lrum_map: list occupancy exceeds its capacity even at "
115 "a vanishing characteristic time");
121 for (std::size_t l = 0; l < h; ++l) {
122 const T den = Told[l] > tol ? Told[l] : tol;
123 const T d =
num_abs(T(Tv[l] - Told[l])) / den;
124 if (d > rel) rel = d;
126 if (rel < tol)
break;
Level statistics of one item's embedded (list, phase) chain in the LRU(m)-MAP TTL approximation.
NumericError(const std::string &what)
The exception types the port throws.
Markovian arrival process descriptors: stationary vectors, rate, moments, autocorrelation and the ind...
Dense matrix and non-owning view.
CacheLrumMapLevelStats< T > cache_lrum_map_levelstats(const Matrix< T > &D0, const Matrix< T > &D1, const std::vector< T > &Tv)
Level statistics of one item's embedded (list, phase) chain in the LRU(m)-MAP TTL approximation.
std::vector< T > cache_t_lrum_map(const std::vector< mam::Map< T > > &items, const std::vector< T > &m, const T &tol, unsigned maxswp=200)
Characteristic times of the LRU(m)-MAP TTL approximation.
RootResult< T > root_bisect(F f, const T &a, const T &b, const T &tol, unsigned maxiter=200)
Bisection on a bracket with a sign change.
void bracket_expand(F f, const T &a, T &b, unsigned maxdoubling=200)
Expand a bracket to the right until f changes sign, doubling the upper end.
Number-type abstraction for the templated API port.
Deterministic scalar root finding.
Outcome of a scalar solve.
T root
best estimate of the root
A MAP as the pair of matrices (D0, D1).