LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
cache_rrm_meanfield.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_CACHE_RRM_MEANFIELD_H
6
#define LINE_API_CACHE_CACHE_RRM_MEANFIELD_H
7
8
/**
9
* @file
10
* @ingroup api_cache
11
* Steady state of the RANDOM(m) multi-list mean field.
12
*
13
* Port of matlab/src/api/cache/cache_rrm_meanfield.m, which is a SCRIPT rather
14
* than a function: it fixes n = 7 items, m = [1 1 3], a fixed popularity
15
* vector and a fixed initial condition, integrates the drift of
16
* cache_rrm_meanfield_ode.m with ode23s over [0,10000] and prints the terminal
17
* occupancy, the miss rate lambda*x(:,1) and the miss ratio. This header is
18
* that computation with the data as arguments.
19
*
20
* The right-hand side was already ported (cache_rrm_meanfield_ode.h) and noted
21
* there that the steady state needed a stiff integrator that the port did not
22
* have. It now does: line/util/ode.h. The Jacobian is not written out here --
23
* the drift is bilinear, so a numeric central-difference Jacobian is accurate
24
* to about eps^(2/3) and the integrator forms it itself; that is the deliberate
25
* choice, since unlike cache_miss_rmf nothing downstream needs an exact
26
* Jacobian and an analytic one would be a second expression of the same
27
* formula to keep in step with the first.
28
*
29
* The initial condition is the reference's: every item outside the cache,
30
* x(k,0) = 1. Integrating from there to t = 1e4 is exactly what
31
* cache_rrm_meanfield.m does.
32
*
33
* ARITHMETIC. Gated: the answer is the limit of a tolerance-driven
34
* integration.
35
*/
36
37
#include <cstddef>
38
#include <vector>
39
40
#include "
line/api/cache/cache_rrm_meanfield_ode.h
"
41
#include "
line/num/number.h
"
42
#include "
line/util/error.h
"
43
#include "
line/util/ode.h
"
44
45
namespace
line
{
46
namespace
cache
{
47
48
/** Return value of cache_rrm_meanfield. */
49
template
<
class
T>
50
struct
CacheRrmMeanfieldResult
{
51
std::vector<T>
x
;
///< (n*(h+1)) terminal occupancy, x[k + s*n] = x(item k, level s)
52
T
missrate
;
///< lambda . x(:,0)
53
T
missratio
;
///< missrate / sum(lambda)
54
};
55
56
/**
57
* @brief Steady state of the RANDOM(m) multi-list mean field.
58
*
59
* @param lambda (n) per-item request rates
60
* @param m (h) list capacities
61
* @param tmax integration horizon (the reference uses 1e4)
62
*/
63
template
<
class
T>
64
CacheRrmMeanfieldResult<T>
cache_rrm_meanfield
(
const
std::vector<T>& lambda,
65
const
std::vector<int>& m,
const
T& tmax) {
66
static_assert
(
num_traits<T>::has_transcendental
,
67
"cache_rrm_meanfield requires transcendental arithmetic: the steady state is "
68
"the limit of a tolerance-driven integration of the mean-field drift"
);
69
const
std::size_t n = lambda.size();
70
const
std::size_t h = m.size();
71
if
(n == 0)
throw
InputError
(
"cache_rrm_meanfield: no items"
);
72
if
(h == 0)
throw
InputError
(
"cache_rrm_meanfield: no cache lists"
);
73
74
const
T zero =
num_traits<T>::from_int
(0);
75
std::vector<T> x0(n * (h + 1), zero);
76
for
(std::size_t k = 0; k < n; ++k) x0[k] = num_traits<T>::from_int(1);
77
78
const
auto
f = [&](
const
T& t,
const
std::vector<T>& x) {
79
(void)t;
80
return
cache_rrm_meanfield_ode
(x, lambda, m);
81
};
82
OdeOptions<T>
opt
;
83
opt
.rtol =
num_traits<T>::from_double
(1e-8);
84
opt
.atol =
num_traits<T>::from_double
(1e-10);
85
opt
.store_trajectory =
false
;
86
87
CacheRrmMeanfieldResult<T>
res;
88
res.
x
=
ode_rosenbrock4
(f, T(
num_traits<T>::from_int
(0)), tmax, x0,
opt
).final_state();
89
res.
missrate
= zero;
90
T tot = zero;
91
for
(std::size_t k = 0; k < n; ++k) {
92
res.
missrate
+= lambda[k] * res.
x
[k];
93
tot += lambda[k];
94
}
95
res.
missratio
= res.
missrate
/ tot;
96
return
res;
97
}
98
99
/** cache_rrm_meanfield with the reference horizon tmax = 1e4. */
100
template
<
class
T>
101
CacheRrmMeanfieldResult<T>
cache_rrm_meanfield
(
const
std::vector<T>& lambda,
102
const
std::vector<int>& m) {
103
return
cache_rrm_meanfield
(lambda, m, T(
num_traits<T>::from_int
(10000)));
104
}
105
106
}
// namespace cache
107
}
// namespace line
108
109
#endif
// LINE_API_CACHE_CACHE_RRM_MEANFIELD_H
cache_rrm_meanfield_ode.h
Mean-field drift of the RANDOM(m) multi-list cache.
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
error.h
The exception types the port throws.
line::cache
Definition
cache_cost.h:42
line::cache::cache_rrm_meanfield_ode
std::vector< T > cache_rrm_meanfield_ode(const std::vector< T > &x, const std::vector< T > &lambda, const std::vector< int > &m)
Mean-field drift of the RANDOM(m) multi-list cache.
Definition
cache_rrm_meanfield_ode.h:58
line::cache::cache_rrm_meanfield
CacheRrmMeanfieldResult< T > cache_rrm_meanfield(const std::vector< T > &lambda, const std::vector< int > &m, const T &tmax)
Steady state of the RANDOM(m) multi-list mean field.
Definition
cache_rrm_meanfield.h:64
line::opt
Definition
bisection_solver.h:31
line
Definition
aoi_dist2ph.h:52
line::ode_rosenbrock4
OdeSolution< T > ode_rosenbrock4(const F &f, const J &jac, const T &t0, const T &t1, const std::vector< T > &y0, const OdeOptions< T > &opt)
Integrate y' = f(t,y) from t0 to t1 with an analytic Jacobian.
Definition
ode.h:304
number.h
Number-type abstraction for the templated API port.
ode.h
Adaptive stiff ODE integrator: a four-stage Rosenbrock method of order four with an embedded order-th...
line::OdeOptions
Integration controls.
Definition
ode.h:118
line::cache::CacheRrmMeanfieldResult
Return value of cache_rrm_meanfield.
Definition
cache_rrm_meanfield.h:50
line::cache::CacheRrmMeanfieldResult::x
std::vector< T > x
(n*(h+1)) terminal occupancy, x[k + s*n] = x(item k, level s)
Definition
cache_rrm_meanfield.h:51
line::cache::CacheRrmMeanfieldResult::missratio
T missratio
missrate / sum(lambda)
Definition
cache_rrm_meanfield.h:53
line::cache::CacheRrmMeanfieldResult::missrate
T missrate
lambda . x(:,0)
Definition
cache_rrm_meanfield.h:52
line::num_traits
Definition
number.h:111
include
line
api
cache
cache_rrm_meanfield.h
Generated by
1.18.0