LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
cache_prob_fpi.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_PROB_FPI_H
6
#define LINE_API_CACHE_PROB_FPI_H
7
8
/**
9
* @file
10
* @ingroup api_cache
11
* Cache hit and miss probabilities from the fixed-point multipliers.
12
*
13
* Templated port of matlab/src/api/cache/cache_prob_fpi.m, cross-checked
14
* against jar/src/main/java/jline/api/cache/Cache_prob_fpi.java.
15
*
16
* With S(i) = sum_l gamma(i,l) xi(l) from cache_xi_fp,
17
*
18
* prob(i,1) = 1 / (1 + S(i)) (miss)
19
* prob(i,1+l) = S(i) / (1 + S(i)) (hit, as written by the references)
20
*
21
* ARITHMETIC: transcendental, inherited from cache_xi_fp's tolerance-stopped
22
* iteration.
23
*
24
* REFERENCE DEFECT (both codebases): the hit entry is the AGGREGATE hit
25
* probability S/(1+S), written identically into all h list columns, instead of
26
* the per-list gamma(i,l) xi(l)/(1+S(i)). MATLAB's
27
* `prob(i,2:(1+h)) = gamma(i,:)*xi(:) ./ (1+gamma(i,:)*xi(:))` is a scalar
28
* broadcast over the row, and the JAR reproduces it with an explicit loop that
29
* stores the same `mul.get(0)` in every column. The consequence is that the
30
* row sums to 1 + (h-1) S/(1+S), not to 1, whenever h > 1; only h == 1 is
31
* correct. This port is faithful to the references -- correcting it here would
32
* silently diverge from MATLAB and the JAR -- and the conservation test in the
33
* suite is asserted only for h == 1 for exactly this reason.
34
*/
35
36
#include <cstddef>
37
#include <vector>
38
39
#include "
line/api/cache/cache_xi_fp.h
"
40
#include "
line/num/number.h
"
41
#include "
line/util/error.h
"
42
#include "
line/util/matrix.h
"
43
44
namespace
line
{
45
namespace
cache
{
46
47
/**
48
* @brief Cache hit and miss probabilities from the fixed-point multipliers.
49
*
50
* @param gamma (n x h) access factors
51
* @param m (h) list capacities
52
* @return (n x (h+1)); column 0 miss, columns 1..h hit (see the defect note)
53
*/
54
template
<
class
T>
55
Matrix<T>
cache_prob_fpi
(
const
Matrix<T>
& gamma,
const
std::vector<int>& m) {
56
static_assert
(
num_traits<T>::has_transcendental
,
57
"cache_prob_fpi requires transcendental arithmetic"
);
58
const
std::size_t n = gamma.
rows
();
59
const
std::size_t h = gamma.
cols
();
60
const
CacheXiFpResult<T>
f =
cache_xi_fp
(gamma, m);
61
62
const
T zero =
num_traits<T>::from_int
(0);
63
const
T one =
num_traits<T>::from_int
(1);
64
Matrix<T>
prob(n, h + 1, zero);
65
for
(std::size_t i = 0; i < n; ++i) {
66
T s = zero;
67
for
(std::size_t l = 0; l < h; ++l) s += gamma(i, l) * f.
xi
[l];
68
const
T den = one + s;
69
prob(i, 0) = one / den;
70
for
(std::size_t l = 0; l < h; ++l) prob(i, 1 + l) = s / den;
71
}
72
return
prob;
73
}
74
75
}
// namespace cache
76
}
// namespace line
77
78
#endif
// LINE_API_CACHE_PROB_FPI_H
cache_xi_fp.h
Lagrange multipliers of a multi-list cache by fixed-point iteration.
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
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_prob_fpi
Matrix< T > cache_prob_fpi(const Matrix< T > &gamma, const std::vector< int > &m)
Cache hit and miss probabilities from the fixed-point multipliers.
Definition
cache_prob_fpi.h:55
line::cache::cache_xi_fp
CacheXiFpResult< T > cache_xi_fp(const Matrix< T > &gamma, const std::vector< int > &m)
Lagrange multipliers of a multi-list cache by fixed-point iteration.
Definition
cache_xi_fp.h:65
line
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
line::cache::CacheXiFpResult
Return value of cache_xi_fp, mirroring [xi,pi0,pij,it].
Definition
cache_xi_fp.h:51
line::cache::CacheXiFpResult::xi
std::vector< T > xi
(h) Lagrange multipliers
Definition
cache_xi_fp.h:52
line::num_traits
Definition
number.h:111
include
line
api
cache
cache_prob_fpi.h
Generated by
1.18.0