LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
cache_ttl_hlru.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_HLRU_H
6
#define LINE_API_CACHE_TTL_HLRU_H
7
8
/**
9
* @file
10
* @ingroup api_cache
11
* TTL (characteristic-time) approximation of an h-LRU / LRU(m) cache.
12
*
13
* Templated port of matlab/src/api/cache/cache_ttl_hlru.m, cross-checked
14
* against jar/src/main/java/jline/api/cache/Cache_ttl_hlru.java.
15
*
16
* The policy is h LRU lists of capacities m(1..h): a miss inserts the item at
17
* the head of list 1 and a hit in list l exchanges it with the tail of list
18
* l+1. Under the characteristic-time approximation the level of an item with
19
* request rate lam is a birth-death chain with up-probability 1 - e(l) and
20
* down-probability e(l), e(l) = exp(-lam T(l)), so
21
*
22
* pi(l) proportional to prod_{s<=l} (1 - e(s))/e(s),
23
*
24
* with the times T solved from the capacity constraints by cache_t_hlru. For
25
* h = 1 this is exactly the Che approximation of LRU, so an M/LRU/1 cache can
26
* be checked against the closed form 1 - exp(-lam T) directly.
27
*
28
* ARITHMETIC: transcendental, as cache_t_hlru.
29
*
30
* The MATLAB reference takes lambda as the (u x n x h+1) array built by
31
* solver_mva_cache_analyzer and sums slice min(2,h+1) over the user classes;
32
* that slice carries the same per-item rate as every other one. The port takes
33
* that slice directly as a (u x n) matrix, which is the same reduction without
34
* the three-dimensional container.
35
*/
36
37
#include <cstddef>
38
#include <vector>
39
40
#include "
line/api/cache/cache_t_hlru.h
"
41
#include "
line/num/number.h
"
42
#include "
line/util/error.h
"
43
#include "
line/util/matrix.h
"
44
45
namespace
line
{
46
namespace
cache
{
47
48
/**
49
* @brief TTL (characteristic-time) approximation of an h-LRU / LRU(m) cache.
50
*
51
* @param lambda (u x n) per-user per-item request rates
52
* @param m (h) list capacities
53
* @return (n x (h+1)); column 0 is "not cached", column 1+l is "in list l"
54
*/
55
template
<
class
T>
56
Matrix<T>
cache_ttl_hlru
(
const
Matrix<T>
& lambda,
const
std::vector<int>& m) {
57
static_assert
(
num_traits<T>::has_transcendental
,
58
"cache_ttl_hlru requires transcendental arithmetic"
);
59
if
(lambda.
empty
())
throw
InputError
(
"cache_ttl_hlru: empty request-rate matrix"
);
60
const
std::size_t n = lambda.
cols
();
61
std::vector<T> lam(n,
num_traits<T>::from_int
(0));
62
for
(std::size_t v = 0; v < lambda.
rows
(); ++v)
63
for
(std::size_t k = 0; k < n; ++k) lam[k] += lambda(v, k);
64
65
const
std::vector<T> Tv = detail::hlru_solve_times(lam, m);
66
return
detail::hlru_levelprobs(lam, Tv);
67
}
68
69
}
// namespace cache
70
}
// namespace line
71
72
#endif
// LINE_API_CACHE_TTL_HLRU_H
cache_t_hlru.h
Characteristic times of the h-LRU / LRU(m) TTL approximation.
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
line::Matrix
Definition
matrix.h:56
line::Matrix::cols
std::size_t cols() const
Definition
matrix.h:90
line::Matrix::rows
std::size_t rows() const
Definition
matrix.h:89
line::Matrix::empty
bool empty() const
Definition
matrix.h:92
error.h
The exception types the port throws.
matrix.h
Dense matrix and non-owning view.
line::cache
Definition
cache_cost.h:42
line::cache::cache_ttl_hlru
Matrix< T > cache_ttl_hlru(const Matrix< T > &lambda, const std::vector< int > &m)
TTL (characteristic-time) approximation of an h-LRU / LRU(m) cache.
Definition
cache_ttl_hlru.h:56
line
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
line::num_traits
Definition
number.h:111
include
line
api
cache
cache_ttl_hlru.h
Generated by
1.18.0