LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_mva_cacheqn_analyzer.m
1function [Q,U,R,T,C,X,lG,hitprob,missprob,runtime,it] = solver_mva_cacheqn_analyzer(self, options)
2% [Q,U,R,T,C,X,LG,RUNTIME,ITER] = SOLVER_MVA_CACHEQN_ANALYZER(SELF, OPTIONS)
3
4% Copyright (c) 2012-2026, Imperial College London
5% All rights reserved.
6
7snorig = self.model.getStruct;
8sn = snorig;
9I = sn.nnodes;
10K = sn.nclasses;
11
12line_debug('MVA cacheqn analyzer starting: method=%s, nclasses=%d', options.method, K);
13
14statefulNodes = find(sn.isstateful)';
15statefulNodesClasses = [];
16for ind=statefulNodes %#ok<FXSET>
17 statefulNodesClasses(end+1:end+K)= ((ind-1)*K+1):(ind*K);
18end
19lambda = zeros(1,K);
20lambda_1 = zeros(1,K);
21caches = find(sn.nodetype == NodeType.Cache);
22
23hitprob = zeros(length(caches),K);
24missprob = zeros(length(caches),K);
25
26for it=1:options.iter_max
27 for ind=caches
28 ch = sn.nodeparam{ind};
29 hitClass = ch.hitclass;
30 missClass = ch.missclass;
31 inputClass = find(hitClass);
32 m = ch.itemcap;
33 n = ch.nitems;
34 if it == 1
35 % initial random value of arrival rates to the cache
36 lambda_1(inputClass) = rand(1,length(inputClass));
37 lambda = lambda_1;
38 sn.nodetype(ind) = NodeType.ClassSwitch;
39 end
40
41 % solution of isolated cache
42 h = length(m);
43 u = length(lambda);
44 lambda_cache = zeros(u,n,h);
45
46 for v=1:u
47 for k=1:n
48 for l=1:(h+1)
49 if ~isnan(ch.pread{v})
50 lambda_cache(v,k,l) = lambda(v) * ch.pread{v}(k);
51 end
52 end
53 end
54 end
55
56 Rcost = ch.accost;
57 if isempty(Rcost)
58 % Default linear cache routing: items flow from list l to list l+1
59 Rcost = cell(u, n);
60 for v = 1:u
61 for k = 1:n
62 Rmat = diag(ones(1, h), 1);
63 Rmat(h+1, h+1) = 1;
64 Rcost{v, k} = Rmat;
65 end
66 end
67 end
68 gamma = cache_gamma_lp(lambda_cache,Rcost);
69
70 switch options.method
71 case 'exact'
72 [~,~,pij] = cache_mva(gamma, m);
73 pij = [abs(1-sum(pij,2)),pij];
74 missrate(ind,:) = zeros(1,u);
75 for v=1:u
76 missrate(ind,v) = lambda_cache(v,:,1)*pij(:,1);
77 end
78 otherwise
79 line_debug('Default method: using FPI approximation for cache\n');
80 line_debug('Using FPI approximation, calling cache_miss_fpi');
81 [~,missrate(ind,:)] = cache_miss_fpi(gamma, m, lambda_cache);
82 end
83 missprob(ind,:) = missrate(ind,:) ./ lambda; % we set to NaN if no arrivals
84 hitprob(ind,:) = 1 - missprob(ind,:);
85 hitprob(isnan(hitprob)) = 0;
86 missprob(isnan(missprob)) = 0;
87
88 % bring back the isolated model results into the queueing model
89 for r=inputClass
90 sn.rtnodes((ind-1)*K+r,:) = 0;
91 for jnd=1:I
92 if sn.connmatrix(ind,jnd)
93 sn.rtnodes((ind-1)*K+r,(jnd-1)*K+hitClass(r)) = hitprob(ind,r);
94 sn.rtnodes((ind-1)*K+r,(jnd-1)*K+missClass(r)) = missprob(ind,r);
95 end
96 end
97 end
98 sn.rt = dtmc_stochcomp(sn.rtnodes,statefulNodesClasses);
99 end
100 [visits, nodevisits, sn] = sn_refresh_visits(sn, sn.chains, sn.rt, sn.rtnodes);
101 sn.visits = visits;
102 sn.nodevisits = nodevisits;
103
104 switch options.method
105 case {'aba.upper', 'aba.lower', 'bjb.upper', 'bjb.lower', 'pb.upper', 'pb.lower', 'gb.upper', 'gb.lower', 'sb.upper', 'sb.lower'}
106 [Q,U,R,T,C,X,lG,runtime] = solver_mva_bound_analyzer(sn, options);
107 otherwise
108 if ~isempty(sn.lldscaling) || ~isempty(sn.cdscaling)
109 [Q,U,R,T,C,X,lG,runtime] = solver_mvald_analyzer(sn, options);
110 else
111 [Q,U,R,T,C,X,lG,runtime] = solver_mva_analyzer(sn, options);
112 end
113
114 nodevisits = cellsum(nodevisits);
115 for ind=caches
116 for r=inputClass
117 c = find(sn.chains(:,r));
118 inchain = find(sn.chains(c,:));
119 if sn.refclass(c)>0
120 lambda(r) = sum(X(inchain)) * nodevisits(ind,r) / nodevisits(sn.stationToNode(sn.refstat(r)),sn.refclass(c));
121 else
122 lambda(r) = sum(X(inchain)) * nodevisits(ind,r) / nodevisits(sn.stationToNode(sn.refstat(r)),r);
123 end
124 end
125 end
126 if norm(lambda-lambda_1,1) < options.iter_tol
127 break
128 end
129 lambda_1 = lambda;
130end
131end