LINE Solver (C++)
Templated C++ port of the LINE queueing solver
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) = gamma(i,l) xi(l) / (1 + S(i)) (item i in list l)
20 *
21 * ARITHMETIC: transcendental, inherited from cache_xi_fp's tolerance-stopped
22 * iteration.
23 *
24 * Each row sums to 1, and column 1+l sums over items to m(l), which is the
25 * equation cache_xi_fp solves. Until 2026-11-14 all four codebases wrote the
26 * AGGREGATE hit probability S/(1+S) into every list column (a scalar broadcast
27 * in MATLAB), so a row summed to 1 + (h-1) S/(1+S) whenever h > 1.
28 */
29
30#include <cstddef>
31#include <vector>
32
34#include "line/num/number.h"
35#include "line/util/error.h"
36#include "line/util/matrix.h"
37
38namespace line {
39namespace cache {
40
41/**
42 * @brief Cache hit and miss probabilities from the fixed-point multipliers.
43 *
44 * @param gamma (n x h) access factors
45 * @param m (h) list capacities
46 * @return (n x (h+1)); column 0 miss, column 1+l the probability of list l
47 */
48template <class T>
49Matrix<T> cache_prob_fpi(const Matrix<T>& gamma, const std::vector<int>& m) {
51 "cache_prob_fpi requires transcendental arithmetic");
52 const std::size_t n = gamma.rows();
53 const std::size_t h = gamma.cols();
54 const CacheXiFpResult<T> f = cache_xi_fp(gamma, m);
55
56 const T zero = num_traits<T>::from_int(0);
57 const T one = num_traits<T>::from_int(1);
58 Matrix<T> prob(n, h + 1, zero);
59 for (std::size_t i = 0; i < n; ++i) {
60 T s = zero;
61 for (std::size_t l = 0; l < h; ++l) s += gamma(i, l) * f.xi[l];
62 const T den = one + s;
63 prob(i, 0) = one / den;
64 for (std::size_t l = 0; l < h; ++l) prob(i, 1 + l) = gamma(i, l) * f.xi[l] / den;
65 }
66 return prob;
67}
68
69} // namespace cache
70} // namespace line
71
72#endif // LINE_API_CACHE_PROB_FPI_H
Lagrange multipliers of a multi-list cache by fixed-point iteration.
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
The exception types the port throws.
Dense matrix and non-owning view.
Matrix< T > cache_prob_fpi(const Matrix< T > &gamma, const std::vector< int > &m)
Cache hit and miss probabilities from the fixed-point multipliers.
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
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
Number-type abstraction for the templated API port.
Return value of cache_xi_fp, mirroring [xi,pi0,pij,it].
Definition cache_xi_fp.h:51
std::vector< T > xi
(h) Lagrange multipliers
Definition cache_xi_fp.h:52