LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
matlab
src
solvers
FLD
solver_fld_cacheqn_analyzer.m
1
function [QN, UN, RN, TN, CN, XN, t, QNt, UNt, TNt, xvec_iter, hitprob, missprob, runtime, it] = solver_fld_cacheqn_analyzer(sn, options)
2
% SOLVER_FLD_CACHEQN_ANALYZER Fluid solver
for
integrated caching-queueing networks
3
%
4
% Iterates between:
5
% 1. Isolated cache analysis (
using
cache_miss_fpi / RMF)
6
% 2. Fluid ODE solution of the surrounding queueing network
7
% until arrival rates to the cache converge.
8
9
% Copyright (c) 2012-2026, Imperial College London
10
% All rights reserved.
11
12
T0 = tic;
13
I = sn.nnodes;
14
K = sn.nclasses;
15
M = sn.nstations;
16
17
statefulNodes = find(sn.isstateful)
';
18
statefulNodesClasses = [];
19
for ind = statefulNodes %#ok<FXSET>
20
statefulNodesClasses(end+1:end+K) = ((ind-1)*K+1):(ind*K);
21
end
22
lambda = zeros(1, K);
23
lambda_1 = zeros(1, K);
24
caches = find(sn.nodetype == NodeType.Cache);
25
26
hitprob = zeros(length(caches), K);
27
missprob = zeros(length(caches), K);
28
29
for it = 1:options.iter_max
30
for cIdx = 1:length(caches)
31
ind = caches(cIdx);
32
ch = sn.nodeparam{ind};
33
hitClass = ch.hitclass;
34
missClass = ch.missclass;
35
inputClass = find(hitClass);
36
m = ch.itemcap;
37
n = ch.nitems;
38
if it == 1
39
% initial random value of arrival rates to the cache
40
lambda_1(inputClass) = rand(1, length(inputClass));
41
lambda = lambda_1;
42
sn.nodetype(ind) = NodeType.ClassSwitch;
43
end
44
45
% solution of isolated cache
46
h = length(m);
47
u = length(lambda);
48
lambda_cache = zeros(u, n, h);
49
50
for v = 1:u
51
for k = 1:n
52
for l = 1:(h+1)
53
if ~isnan(ch.pread{v})
54
lambda_cache(v, k, l) = lambda(v) * ch.pread{v}(k);
55
end
56
end
57
end
58
end
59
60
Rcost = ch.accost;
61
if isempty(Rcost)
62
% Default linear cache routing: items flow from list l to list l+1
63
Rcost = cell(u, n);
64
for v = 1:u
65
for k = 1:n
66
Rmat = diag(ones(1, h), 1);
67
Rmat(h+1, h+1) = 1;
68
Rcost{v, k} = Rmat;
69
end
70
end
71
end
72
gamma = cache_gamma_lp(lambda_cache, Rcost);
73
74
[~, missrate(cIdx, :)] = cache_miss_fpi(gamma, m, lambda_cache); %#ok<AGROW>
75
76
missprob(cIdx, :) = missrate(cIdx, :) ./ lambda;
77
hitprob(cIdx, :) = 1 - missprob(cIdx, :);
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(cIdx, r);
87
sn.rtnodes((ind-1)*K+r, (jnd-1)*K+missClass(r)) = missprob(cIdx, 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
% Solve the queueing network using the fluid matrix method
98
fluid_options = options;
99
fluid_options.method = '
matrix
';
100
fluid_options.init_sol = solver_fluid_initsol(sn, fluid_options);
101
[QN, UN, RN, TN, xvec_iter, QNt, UNt, TNt, ~, t] = solver_fluid_matrix(sn, fluid_options);
102
103
% Compute system throughputs
104
XN = zeros(1, K);
105
for k = 1:K
106
if sn.refstat(k) > 0
107
XN(k) = TN(sn.refstat(k), k);
108
end
109
end
110
111
% Update arrival rates to the cache
112
nodevisits = cellsum(nodevisits);
113
for cIdx = 1:length(caches)
114
ind = caches(cIdx);
115
ch = sn.nodeparam{ind};
116
inputClass = find(ch.hitclass);
117
for r = inputClass
118
c = find(sn.chains(:, r));
119
inchain = find(sn.chains(c, :));
120
if sn.refclass(c) > 0
121
lambda(r) = sum(XN(inchain)) * nodevisits(ind, r) / nodevisits(sn.stationToNode(sn.refstat(r)), sn.refclass(c));
122
else
123
lambda(r) = sum(XN(inchain)) * nodevisits(ind, r) / nodevisits(sn.stationToNode(sn.refstat(r)), r);
124
end
125
end
126
end
127
if norm(lambda - lambda_1, 1) < options.iter_tol
128
break
129
end
130
lambda_1 = lambda;
131
end
132
133
% Compute CN
134
CN = zeros(1, K);
135
for k = 1:K
136
if sn.refstat(k) > 0
137
CN(k) = sn.njobs(k) ./ XN(k);
138
end
139
end
140
141
% xvec_iter is already a cell array from solver_fluid_matrix
142
runtime = toc(T0);
143
end
Generated by
1.9.8