LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_fld_cacheqn_tran.m
1function [tcache, hitprob_t, missprob_t, caches, arate, xocc] = solver_fld_cacheqn_tran(sn, options, x0cell)
2% SOLVER_FLD_CACHEQN_TRAN Transient refined-mean-field cache trajectory.
3%
4% Converges the per-class cache arrival rates with the same decomposition-
5% aggregation alternation as the steady solver (da_cacheqn), then integrates
6% the mean-field drift over OPTIONS.TIMESPAN to obtain the time-resolved
7% per-class hit/miss probabilities of each cache. This is the transient
8% counterpart of solver_fld_cacheqn_analyzer: the steady solver drives the
9% drift to its fixed point, whereas here the same drift is integrated over
10% the finite window from the supplied (or default) initial occupancy.
11%
12% SN: NetworkStruct with at least one Cache node.
13% OPTIONS: solver options; OPTIONS.TIMESPAN = [t0,t1] sets the window.
14% X0CELL: optional cell(1,ncaches); X0CELL{c} seeds cache c occupancy
15% (flat DDPP state vector, n_items*(h+1)); [] uses the default
16% all-items-outside-plus-first-m-in-list initial state.
17%
18% Returns the time grid TCACHE, the per-cache per-class hit/miss probability
19% trajectories HITPROB_T/MISSPROB_T (ncaches x nclasses x nt), and the cache
20% node indices CACHES (rows ordered as find(sn.nodetype==Cache)).
21%
22% Copyright (c) 2012-2026, Imperial College London
23% All rights reserved.
24
25K = sn.nclasses;
26if nargin < 3
27 x0cell = {};
28end
29tspan = options.timespan;
30if isinf(tspan(1))
31 tspan(1) = 0;
32end
33
34% Converge the cache arrival rates and capture the per-cache isolated inputs.
35[~, ~, ~, ~, ~, cacheinfo] = da_cacheqn(sn, @miss_isolated, @netsolve, options);
36caches = cacheinfo.node;
37ncaches = numel(caches);
38
39tcache = [];
40hitprob_t = [];
41missprob_t = [];
42arate = zeros(ncaches, K);
43xocc = cell(1, ncaches);
44for cIdx = 1:ncaches
45 gamma = cacheinfo.gamma{cIdx};
46 m = cacheinfo.m{cIdx};
47 lam = cacheinfo.lambda_cache{cIdx};
48 strat = cacheinfo.strat{cIdx};
49 if cIdx <= numel(x0cell)
50 x0 = x0cell{cIdx};
51 else
52 x0 = [];
53 end
54
55 % Isolated-cache transient occupancy via the drift-based mean field. RANDOM(m)
56 % and FIFO(m) share the steady state (Gast15 Thm 1) but NOT the transient, so
57 % FIFO uses its own position-resolved drift; strict FIFO(m) likewise.
58 % LRU/HLRU/CLIMB/QLRU have no drift-based transient.
59 if strat == ReplacementStrategy.RR
60 [~, ~, ~, ~, tc, ~, MU_t, xtraj] = cache_miss_rmf(gamma, m, lam, tspan, x0);
61 xocc{cIdx} = xtraj;
62 elseif strat == ReplacementStrategy.FIFO
63 [~, ~, ~, ~, tc, ~, MU_t, xtraj] = cache_miss_fifo_rmf(gamma, m, lam, tspan, x0);
64 xocc{cIdx} = xtraj;
65 elseif strat == ReplacementStrategy.SFIFO
66 [~, ~, ~, ~, tc, ~, MU_t, xtraj] = cache_miss_sfifo_rmf(gamma, m, lam, tspan, x0);
67 xocc{cIdx} = xtraj;
68 else
69 line_error(mfilename, sprintf(['Transient cache analysis is only ' ...
70 'available for RANDOM(m)/FIFO(m) and strict FIFO(m) replacement via ' ...
71 'a drift-based mean field; cache %d uses a strategy without one.'], cIdx));
72 end
73
74 if isempty(tcache)
75 nt = numel(tc);
76 tcache = tc(:)';
77 hitprob_t = zeros(ncaches, K, nt);
78 missprob_t = zeros(ncaches, K, nt);
79 end
80
81 % Per-user (per-class) arrival rate = sum over items of its isolated rate.
82 u = size(lam, 1);
83 for v = 1:u
84 rowrate = sum(lam(v, :, 1));
85 arate(cIdx, v) = rowrate;
86 if rowrate > 0
87 mp = MU_t(v, :) ./ rowrate;
88 mp = max(0, min(1, mp));
89 missprob_t(cIdx, v, :) = reshape(mp, 1, 1, []);
90 hitprob_t(cIdx, v, :) = reshape(1 - mp, 1, 1, []);
91 end
92 end
93end
94
95 function missrate = miss_isolated(gamma, m, lambda_cache, ch)
96 if ch.replacestrat == ReplacementStrategy.RR || ...
97 ch.replacestrat == ReplacementStrategy.FIFO
98 [~, missrate] = cache_miss_rmf(gamma, m, lambda_cache);
99 elseif ch.replacestrat == ReplacementStrategy.SFIFO
100 [~, missrate] = cache_miss_sfifo_rmf(gamma, m, lambda_cache);
101 else
102 % LRU/HLRU/CLIMB/QLRU have no drift-based fluid model.
103 line_error(mfilename, sprintf(['SolverFLD supports only ' ...
104 'RANDOM(m)/FIFO(m) and strict FIFO(m) cache replacement; ' ...
105 'strategy %d has no drift-based fluid model.'], ...
106 double(ch.replacestrat)));
107 end
108 end
109
110 function res = netsolve(snit)
111 res = struct();
112 fluid_options = options;
113 fluid_options.method = 'matrix';
114 fluid_options.init_sol = solver_fluid_initsol(snit, fluid_options);
115 [res.QN, res.UN, res.RN, res.TN, res.xvec_iter, res.QNt, res.UNt, res.TNt, ~, res.t] = solver_fluid_matrix(snit, fluid_options);
116 res.XN = zeros(1, K);
117 for k = 1:K
118 if snit.refstat(k) > 0
119 res.XN(k) = res.TN(snit.refstat(k), k);
120 end
121 end
122 end
123end