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)
4% Copyright (c) 2012-2026, Imperial College London
7snorig = self.model.getStruct;
12line_debug(
'NC cacheqn analyzer starting: method=%s, nclasses=%d', options.method, K);
14statefulNodes = find(sn.isstateful)
';
15statefulNodesClasses = [];
16for ind=statefulNodes %#ok<FXSET>
17 statefulNodesClasses(end+1:end+K)= ((ind-1)*K+1):(ind*K);
21caches = find(sn.nodetype == NodeType.Cache);
23hitprob = zeros(length(caches),K);
24missprob = zeros(length(caches),K);
26for it=1:options.iter_max
28 ch = sn.nodeparam{ind};
29 hitClass = ch.hitclass;
30 missClass = ch.missclass;
31 inputClass = find(hitClass);
36 line_error(mfilename,'NC
requires the number of items to exceed the cache capacity at least by 2.
');
38 % initial random value of arrival rates to the cache
39 lambda_1(inputClass) = rand(1,length(inputClass));
41 sn.nodetype(ind) = NodeType.ClassSwitch;
44 % solution of isolated cache
47 lambda_cache = zeros(u,n,h);
52 if ~isnan(ch.pread{v})
53 lambda_cache(v,k,l) = lambda(v) * ch.pread{v}(k);
60 gamma = cache_gamma_lp(lambda_cache,Rcost);
63 [pij] = cache_prob_erec(gamma, m);
64 missrate(ind,:) = zeros(1,u);
66 missrate(ind,v) = lambda_cache(v,:,1)*pij(:,1);
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);
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;
81 % bring back the isolated model results into the queueing model
83 sn.rtnodes((ind-1)*K+r,:) = 0;
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);
91 sn.rt = dtmc_stochcomp(sn.rtnodes,statefulNodesClasses);
93 [visits, nodevisits, sn] = sn_refresh_visits(sn, sn.chains, sn.rt, sn.rtnodes);
95 sn.nodevisits = nodevisits;
97 if ~isempty(sn.lldscaling) || ~isempty(sn.cdscaling)
98 [QN,UN,RN,TN,CN,XN,lG,runtime] = solver_ncld_analyzer(sn, options);
100 [QN,UN,RN,TN,CN,XN,lG,runtime] = solver_nc_analyzer(sn, options);
103 nodevisits = cellsum(nodevisits);
106 c = find(sn.chains(:,r));
107 inchain = find(sn.chains(c,:));
109 lambda(r) = sum(XN(inchain)) * nodevisits(ind,r) / nodevisits(sn.stationToNode(sn.refstat(r)),sn.refclass(c));
111 lambda(r) = sum(XN(inchain)) * nodevisits(ind,r) / nodevisits(sn.stationToNode(sn.refstat(r)),r);
115 if norm(lambda-lambda_1,1) < options.iter_tol