LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_mva_cache_analyzer.m
1function [QN,UN,RN,TN,CN,XN,lGN,runtime,iter,method] = solver_mva_cache_analyzer(sn, options)
2% [Q,U,R,T,C,X,LG,RUNTIME,ITER] = SOLVER_MVA_CACHE_ANALYZER(QN, OPTIONS)
3
4% Copyright (c) 2012-2026, Imperial College London
5% All rights reserved.
6
7T0=tic;
8QN = []; UN = [];
9RN = []; TN = [];
10CN = [];
11XN = zeros(1,sn.nclasses);
12lGN = NaN;
13iter = NaN;
14
15line_debug('MVA cache analyzer starting: method=%s, nclasses=%d', options.method, sn.nclasses);
16
17source_ist = sn.nodeToStation(sn.nodetype == NodeType.Source);
18sourceRate = sn.rates(source_ist,:);
19sourceRate(isnan(sourceRate)) = 0;
20TN(source_ist,:) = sourceRate;
21
22ch = sn.nodeparam{sn.nodetype == NodeType.Cache};
23
24m = ch.itemcap;
25n = ch.nitems;
26h = length(m);
27u = sn.nclasses;
28lambda = zeros(u,n,h);
29
30for v=1:u
31 for k=1:n
32 for l=1:(h+1)
33 if ~isnan(ch.pread{v})
34 lambda(v,k,l) = sourceRate(v) * ch.pread{v}(k);
35 end
36 end
37 end
38end
39
40Rcost = ch.accost;
41if isempty(Rcost)
42 % Default linear cache routing: items flow from list l to list l+1
43 Rcost = cell(u, n);
44 for v = 1:u
45 for k = 1:n
46 Rmat = diag(ones(1, h), 1);
47 Rmat(h+1, h+1) = 1;
48 Rcost{v, k} = Rmat;
49 end
50 end
51end
52
53gamma = cache_gamma_lp(lambda,Rcost);
54
55switch options.method
56 case 'exact'
57 line_debug('Using exact cache method');
58 switch sn.nodeparam{sn.nodetype == NodeType.Cache}.replacestrat
59 case {ReplacementStrategy.RR, ReplacementStrategy.FIFO}
60 line_debug('Replacement strategy: RR/FIFO, calling cache_mva');
61 [~,~,pij] = cache_mva(gamma, m);
62 pij = [abs(1-sum(pij,2)),pij];
63 otherwise
64 line_error(mfilename,'MVA does not support exact solution of the specified cache replacement policy.')
65 end
66 otherwise
67 line_debug('Default method: using approximate cache method\n');
68 line_debug('Using approximate cache method');
69 switch sn.nodeparam{sn.nodetype == NodeType.Cache}.replacestrat
70 case {ReplacementStrategy.RR, ReplacementStrategy.FIFO}
71 line_debug('Replacement strategy: RR/FIFO, calling cache_prob_fpi');
72 pij = cache_prob_fpi(gamma,m); % FPI method
73 case ReplacementStrategy.LRU
74 line_debug('Replacement strategy: LRU, calling cache_ttl_lrua');
75 %pij = cache_ttl_lrum(lambda, m); % linear topology only
76 pij = cache_ttl_lrua(lambda, Rcost, m); % allows trees and access costs
77 %case ReplacementStrategy.HLRU
78 % this is integrated but the cache_ttl_hlru script is not
79 % working correctly at present
80 %pij = cache_ttl_hlru(lambda, m); % without considering different graph of different items linear
81 otherwise
82 line_error(mfilename,'MVA does not support approximate solution of the specified cache replacement policy.')
83 end
84end
85missRate = zeros(1,u);
86for v=1:u
87 missRate(v) = lambda(v,:,1)*pij(:,1);
88end
89
90for r = 1:sn.nclasses
91 if length(ch.hitclass)>=r && ch.missclass(r)>0 && ch.hitclass(r)>0
92 XN(ch.missclass(r)) = XN(ch.missclass(r)) + missRate(r);
93 XN(ch.hitclass(r)) = XN(ch.hitclass(r)) + (sourceRate(r) - missRate(r));
94 end
95end
96
97% Set the actual method used
98if strcmp(options.method, 'exact')
99 method = 'exact';
100else
101 switch sn.nodeparam{sn.nodetype == NodeType.Cache}.replacestrat
102 case {ReplacementStrategy.RR, ReplacementStrategy.FIFO}
103 method = 'fpi';
104 case ReplacementStrategy.LRU
105 method = 'ttl';
106 otherwise
107 method = options.method;
108 end
109end
110
111runtime=toc(T0);
112end