LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solver_nc_cacheqn_retrieval.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_SOLVERS_NC_SOLVER_NC_CACHEQN_RETRIEVAL_H
6#define LINE_SOLVERS_NC_SOLVER_NC_CACHEQN_RETRIEVAL_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * Port of `solver_nc_cacheqn_retrieval_analyzer.m`: a CLOSED integrated
12 * cache-queueing model whose Cache carries a delayed-hit retrieval system.
13 *
14 * THIS FILE IS GLUE. All the work is in `da_cacheqn_retrieval`, which alternates
15 * the isolated-cache solve with the network solve; this supplies only the
16 * NETWORK SOLVER and unpacks the result. The load-dependent path is not
17 * optional here: the driver installs a coupon-collector `lldscaling` on the
18 * fetch station, so the network solve must be the LOAD-DEPENDENT analyzer
19 * whenever scaling is present -- which, after the driver has run, it always is.
20 * `nc_dispatch` selects it on exactly that test.
21 *
22 * THE THREE-WAY SPLIT COLLAPSES ON THIS PATH, deliberately. The reference
23 * reports `hitprob` as P(item cached) and folds the delayed-hit fraction into
24 * `missprob`, returning `delayedprob = 0`. Only the OPEN analyzer
25 * (`solver_nc_retrieval.h`) separates true hits from delayed hits. That is why
26 * `hitproblist` and `latency` are NaN here and `itemprob` is empty: they are
27 * quantities this path does not compute, and reporting a number for them would
28 * be inventing one.
29 */
30
31#include <cmath>
32#include <cstddef>
33#include <limits>
34#include <vector>
35
40#include "line/util/error.h"
41
42namespace line {
43namespace nc {
44
45/** What the closed delayed-hit analyzer returns. */
46template <class T>
49 std::vector<T> hitprob; ///< (K) P(item cached)
50 std::vector<T> missprob; ///< (K) the delayed fraction is folded in here
51 std::vector<T> delayedprob; ///< (K) zero on this path, by the reference's convention
52 std::vector<T> latency; ///< (K) NaN: not computed on this path
53 Matrix<T> hitproblist; ///< (K x h) NaN: not computed on this path
54};
55
56/**
57 * Port of `solver_nc_cacheqn_retrieval_analyzer.m`.
58 *
59 * @param sn the refreshed struct; one Cache with a retrieval system, closed
60 * @param opt solver controls
61 */
62template <class T>
66 if constexpr (!num_traits<T>::has_transcendental) {
67 (void)sn;
68 (void)opt;
69 throw UnsupportedError(
70 "solver_nc_cacheqn_retrieval_analyzer: the closed delayed-hit decomposition alternates "
71 "two tolerance-stopped solves and needs transcendental arithmetic");
72 } else {
73 const T nanT = num_traits<T>::from_double(std::numeric_limits<double>::quiet_NaN());
74 const std::size_t K = sn.nclasses;
75 const NcSolverOptions netopt = opt;
76
77 std::function<mva::MvaSolution<T>(const qn::NetworkStruct<T>&)> netfun =
78 [netopt](const qn::NetworkStruct<T>& snit) -> mva::MvaSolution<T> {
79 return nc_dispatch(snit, netopt).sol;
80 };
81
82 mva::MvaOptions mopt;
83 mopt.method = opt.method;
84 mopt.tol = opt.tol;
85 mopt.iter_tol = opt.iter_tol;
86 mopt.iter_max = opt.iter_max;
87
89 da::da_cacheqn_retrieval<T>(sn, netfun, mopt);
90
91 out.sol.sol = r.res;
92 out.sol.sol.iter = static_cast<int>(r.iter);
93 // The reference reports 'fpi' here: the isolated-cache miss is
94 // cache_miss_fpi on this path in BOTH solvers, so the name records the
95 // algorithm that decided the split rather than the network method.
96 out.sol.sol.method = "fpi";
97 out.sol.actualmethod = "fpi";
98 out.hitprob = r.hitprob;
99 out.missprob = r.missprob;
100 out.delayedprob = r.delayedprob;
101 out.latency.assign(K, nanT);
102 std::size_t h = 0;
103 for (const auto& kv : sn.nodeparam)
104 if (kv.second.itemcap.size() > h) h = kv.second.itemcap.size();
105 out.hitproblist = Matrix<T>(K, h, nanT);
106 return out;
107 }
108}
109
110} // namespace nc
111} // namespace line
112
113#endif // LINE_SOLVERS_NC_SOLVER_NC_CACHEQN_RETRIEVAL_H
UnsupportedError(const std::string &what)
Definition error.h:51
A network plus its refreshed NetworkStruct.
Decomposition-aggregation driver for a CLOSED integrated cache-queueing model whose Cache carries a d...
The exception types the port throws.
CacheqnRetrievalResult< T > da_cacheqn_retrieval(qn::NetworkStruct< T > sn, const std::function< mva::MvaSolution< T >(const qn::NetworkStruct< T > &)> &netfun, const mva::MvaOptions &opt)
Port of da_cacheqn_retrieval.
NcCacheqnRetrievalSolution< T > solver_nc_cacheqn_retrieval_analyzer(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of solver_nc_cacheqn_retrieval_analyzer.m.
NcSolution< T > nc_dispatch(const qn::NetworkStruct< T > &sn, const NcSolverOptions &opt)
Port of @@SolverNC/ncDispatch.m: the inner solve of the fork-join fixed point, which is the load-depe...
Port of solver_nc_analyzer.m, solver_ncld_analyzer.m and @@SolverNC/ncDispatch.m: one inner solve,...
Controls and result shape shared by the normalizing-constant analyzers.
A queueing network and its refreshed NetworkStruct.
What the delayed-hit decomposition returns.
std::vector< T > hitprob
(K) P(item cached), read class only
std::vector< T > delayedprob
(K) zero on this path; see the header
The options SolverMVA reads.
Definition mva_types.h:31
std::string method
Definition mva_types.h:32
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
Definition mva_types.h:96
What the closed delayed-hit analyzer returns.
std::vector< T > delayedprob
(K) zero on this path, by the reference's convention
std::vector< T > missprob
(K) the delayed fraction is folded in here
std::vector< T > hitprob
(K) P(item cached)
std::vector< T > latency
(K) NaN: not computed on this path
Matrix< T > hitproblist
(K x h) NaN: not computed on this path
The [Q,U,R,T,C,X,lG] of the reference, plus the algorithm that ran.
Definition nc_types.h:113
Controls, defaulting to SolverOptions('NC') in the reference.
Definition nc_types.h:33