LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
cache_ttl_lrum_map.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_API_CACHE_TTL_LRUM_MAP_H
6#define LINE_API_CACHE_TTL_LRUM_MAP_H
7
8/**
9 * @file
10 * @ingroup api_cache
11 * TTL approximation of an LRU(m) cache whose items are requested by Markovian
12 * arrival processes.
13 *
14 * Templated port of matlab/src/api/cache/cache_ttl_lrum_map.m, cross-checked
15 * against jar/src/main/java/jline/api/cache/Cache_ttl_lrum_map.java. Solves the
16 * characteristic times with cache_t_lrum_map and then reports, per item, the
17 * request-weighted hit probabilities of each list and the time-stationary
18 * level occupancies (Gast and Van Houdt, Performance Evaluation 2017).
19 *
20 * This is the model to use when the items have genuinely distinct or
21 * correlated request processes; when items are i.i.d. marks of a common stream
22 * the request sequence is IRM and the Poisson-based approximations
23 * (cache_ttl_lrua, cache_ttl_hlru) already apply.
24 *
25 * ARITHMETIC: transcendental, through cache_lrum_map_levelstats.
26 *
27 * The miss column follows MATLAB exactly, pij(k,0) = max(0, 1 - sum_l
28 * hitfrac(k,l)): the hit fractions come from a fixed point and can overshoot
29 * one by a rounding-scale amount, and the clamp is part of the reference
30 * definition rather than a workaround added here.
31 */
32
33#include <cstddef>
34#include <vector>
35
39#include "line/num/number.h"
40#include "line/util/error.h"
41#include "line/util/matrix.h"
42
43namespace line {
44namespace cache {
45
46/** Request-weighted and time-stationary level probabilities. */
47template <class T>
49 Matrix<T> pij; ///< (n x h+1) column 0 = miss probability, column 1+l = hit in list l
50 Matrix<T> pijtime; ///< (n x h+1) time-stationary level occupancy probabilities
51 std::vector<T> t; ///< (h) characteristic times used
52};
53
54/**
55 * @brief TTL approximation of an LRU(m) cache whose items are requested by
56 * Markovian arrival processes.
57 *
58 * @param items (n) per-item request MAPs
59 * @param m (h) list capacities
60 * @param tol relative tolerance passed to cache_t_lrum_map
61 */
62template <class T>
64 const std::vector<T>& m, const T& tol) {
66 "cache_ttl_lrum_map requires transcendental arithmetic");
67 const std::size_t n = items.size();
68 const std::size_t h = m.size();
69 const T zero = num_traits<T>::from_int(0);
70 const T one = num_traits<T>::from_int(1);
71
73 out.t = cache_t_lrum_map(items, m, tol);
74 out.pij = Matrix<T>(n, h + 1, zero);
75 out.pijtime = Matrix<T>(n, h + 1, zero);
76
77 for (std::size_t k = 0; k < n; ++k) {
79 cache_lrum_map_levelstats(items[k].D0, items[k].D1, out.t);
80 for (std::size_t l = 0; l <= h; ++l) out.pijtime(k, l) = st.prob[l];
81 T hits = zero;
82 for (std::size_t l = 0; l < h; ++l) {
83 out.pij(k, 1 + l) = st.hitfrac[l];
84 hits += st.hitfrac[l];
85 }
86 const T miss = one - hits;
87 out.pij(k, 0) = miss > zero ? miss : zero;
88 }
89 return out;
90}
91
92} // namespace cache
93} // namespace line
94
95#endif // LINE_API_CACHE_TTL_LRUM_MAP_H
Level statistics of one item's embedded (list, phase) chain in the LRU(m)-MAP TTL approximation.
Characteristic times of the LRU(m)-MAP TTL approximation.
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.
CacheTtlLrumMapResult< T > cache_ttl_lrum_map(const std::vector< mam::Map< T > > &items, const std::vector< T > &m, const T &tol)
TTL approximation of an LRU(m) cache whose items are requested by Markovian arrival processes.
Number-type abstraction for the templated API port.
Per-item level statistics, MATLAB's [prob, occ, hitfrac].
std::vector< T > hitfrac
(h) fraction of the item's requests hitting in list l
std::vector< T > prob
(h+1) time-stationary probability of level 0..h
Request-weighted and time-stationary level probabilities.
std::vector< T > t
(h) characteristic times used
Matrix< T > pijtime
(n x h+1) time-stationary level occupancy probabilities
Matrix< T > pij
(n x h+1) column 0 = miss probability, column 1+l = hit in list l
A MAP as the pair of matrices (D0, D1).
Definition map_moment.h:53