LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_nc_cacheqn_analyzer.m
1function [QN,UN,RN,TN,CN,XN,lG,hitprob,missprob,runtime,it,method] = solver_nc_cacheqn_analyzer(self, options)
2% [Q,U,R,T,C,X,LG,RUNTIME,ITER] = SOLVER_NC_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('NC 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 if n<sum(m)+2
36 line_error(mfilename,'NC requires the number of items to exceed the cache capacity at least by 2.');
37 end
38 % initial random value of arrival rates to the cache
39 lambda_1(inputClass) = rand(1,length(inputClass));
40 lambda = lambda_1;
41 sn.nodetype(ind) = NodeType.ClassSwitch;
42 end
43
44 % solution of isolated cache
45 h = length(m);
46 u = length(lambda);
47 lambda_cache = zeros(u,n,h);
48
49 for v=1:u
50 for k=1:n
51 for l=1:(h+1)
52 if ~isnan(ch.pread{v})
53 lambda_cache(v,k,l) = lambda(v) * ch.pread{v}(k);
54 end
55 end
56 end
57 end
58
59 Rcost = ch.accost;
60 gamma = cache_gamma_lp(lambda_cache,Rcost);
61 switch options.method
62 case 'exact'
63 [pij] = cache_prob_erec(gamma, m);
64 missrate(ind,:) = zeros(1,u);
65 for v=1:u
66 missrate(ind,v) = lambda_cache(v,:,1)*pij(:,1);
67 end
68 method = 'exact';
69 otherwise
70 line_debug('Default method: using SPM approximation for cache\n');
71 line_debug('Using SPM approximation, calling cache_miss_spm');
72 [~,missrate(ind,:)] = cache_miss_spm(gamma, m, lambda_cache);
73 method = 'spm';
74 end
75
76 missprob(ind,:) = missrate(ind,:) ./ lambda; % we set to NaN if no arrivals
77 hitprob(ind,:) = 1 - missprob(ind,:);
78 hitprob(isnan(hitprob)) = 0;
79 missprob(isnan(missprob)) = 0;
80
81 % bring back the isolated model results into the queueing model
82 for r=inputClass
83 sn.rtnodes((ind-1)*K+r,:) = 0;
84 for jnd=1:I
85 if sn.connmatrix(ind,jnd)
86 sn.rtnodes((ind-1)*K+r,(jnd-1)*K+hitClass(r)) = hitprob(ind,r);
87 sn.rtnodes((ind-1)*K+r,(jnd-1)*K+missClass(r)) = missprob(ind,r);
88 end
89 end
90 end
91 sn.rt = dtmc_stochcomp(sn.rtnodes,statefulNodesClasses);
92 end
93 [visits, nodevisits, sn] = sn_refresh_visits(sn, sn.chains, sn.rt, sn.rtnodes);
94 sn.visits = visits;
95 sn.nodevisits = nodevisits;
96
97 if ~isempty(sn.lldscaling) || ~isempty(sn.cdscaling)
98 [QN,UN,RN,TN,CN,XN,lG,runtime] = solver_ncld_analyzer(sn, options);
99 else
100 [QN,UN,RN,TN,CN,XN,lG,runtime] = solver_nc_analyzer(sn, options);
101 end
102
103 nodevisits = cellsum(nodevisits);
104 for ind=caches
105 for r=inputClass
106 c = find(sn.chains(:,r));
107 inchain = find(sn.chains(c,:));
108 if sn.refclass(c)>0
109 lambda(r) = sum(XN(inchain)) * nodevisits(ind,r) / nodevisits(sn.stationToNode(sn.refstat(r)),sn.refclass(c));
110 else
111 lambda(r) = sum(XN(inchain)) * nodevisits(ind,r) / nodevisits(sn.stationToNode(sn.refstat(r)),r);
112 end
113 end
114 end
115 if norm(lambda-lambda_1,1) < options.iter_tol
116 break
117 end
118 lambda_1 = lambda;
119end
120end