LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
cache_ttl_lrua.m
1%{ @file cache_ttl_lrua.m
2 % @brief Computes steady-state probabilities for TTL-LRU cache with arrivals
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Computes steady-state probabilities for TTL-LRU cache with arrivals
9 %
10 % @details
11 % This function computes the steady-state probability distribution for a
12 % TTL-LRU cache system with multiple users, items, and cache levels.
13 %
14 % @par Syntax:
15 % @code
16 % prob = cache_ttl_lrua(lambda, R, m)
17 % prob = cache_ttl_lrua(lambda, R, m, seed)
18 % @endcode
19 %
20 % @par Parameters:
21 % <table>
22 % <tr><th>Name<th>Description
23 % <tr><td>lambda<td>Arrival rates per user per item per list
24 % <tr><td>R<td>Routing probability structure
25 % <tr><td>m<td>Cache capacity vector
26 % <tr><td>seed<td>(Optional) Random seed for initialization
27 % </table>
28 %
29 % @par Returns:
30 % <table>
31 % <tr><th>Name<th>Description
32 % <tr><td>prob<td>Steady-state probability distribution
33 % </table>
34%}
35function prob=cache_ttl_lrua(lambda, R, m, seed)
36if nargin<4
37 seed = 23000;
38end
39rng(seed,'twister');
40
41u=size(lambda,1); % number of users
42n=size(lambda,2); % number of items
43h=size(lambda,3)-1; % number of lists
44
45fun = @ttl_tree_time;
46
47% random seed to generate the initial value for x
48range_left = 0; range_right = 10;
49x = (range_right-range_left).*rand(1,h) + range_left;
50options = optimoptions('fsolve','MaxIter',1e5,'MaxFunEvals',1e6,'Display','off');
51[listtime,~,~,~] = fsolve(fun,x,options);
52[~,ssprob] = ttl_tree_time(listtime);
53prob = ssprob;
54
55 function [F,ssprob,capadiff] = ttl_tree_time(x)
56 steadystateprob = zeros(n,h+1);
57 randprob = zeros(n,h+1);
58 avgtime = zeros(n,h+1);
59 cdiff = zeros(1,h);
60 capa = zeros(1,h);
61 rpdenominator = zeros(1,n);
62 % the probability of each item at each list
63 for i = 1:n % for all items
64 % An item with no arrivals (lambda == 0 across all lists) is never
65 % requested and so never enters the cache: it stays in the miss
66 % state (list 0) with probability 1 and contributes zero list
67 % occupancy. Handling it explicitly avoids 1/lambda = Inf -> NaN in
68 % the TTL residence times, which otherwise makes the fsolve
69 % objective undefined at the initial point (e.g. when the integrated
70 % cache-queueing solver evaluates the cache before any flow reaches
71 % it, or for items whose read probability is zero).
72 if lambda(1,i,1) == 0
73 steadystateprob(i,1) = 1;
74 randprob(i,1) = 1;
75 continue;
76 end
77 transmatrix = zeros(h+1, h+1);
78 for j = 1:h+1
79 leafnode = find(R{1,i}(j,:));
80 for k = leafnode
81 if j == 1
82 transmatrix(j,k) = R{1,i}(j,k);
83 else
84 transmatrix(j,k) = (1-exp(-lambda(1,i,j)*x(j-1)))*R{1,i}(j,k);
85 end
86 if j ~= k
87 transmatrix(k,j) = exp(-lambda(1,i,k)*x(k-1));
88 end
89 end
90 end
91 missconnection = find(all(transmatrix==0));
92 dtchain = setdiff(1:h+1, missconnection);
93 transmatrix(missconnection,:)=[];
94 transmatrix(:,missconnection)=[]; % remove the unused nodes in the transfer matrix
95 dtmcprob = dtmc_solve(transmatrix); % solution of dtmc, i.e., prob of item i in list j, 1*h
96 for a = 1:numel(dtchain)
97 steadystateprob(i,dtchain(a)) = dtmcprob(a);
98 if dtchain(a)>1
99 avgtime(i,dtchain(a)) = (1-exp(-lambda(1,i,dtchain(a))*x(dtchain(a)-1)))/lambda(1,i,dtchain(a));% average time of item i spent in l , l>=1
100 else
101 avgtime(i,dtchain(a)) = 1/lambda(1,i,dtchain(a));
102 end
103 rpdenominator(i) = rpdenominator(i)+steadystateprob(i,dtchain(a))*avgtime(i,dtchain(a));% denominator for the probability of item i at node j at a random time
104 end
105 for a = 1:numel(dtchain)
106 randprob(i,dtchain(a)) = steadystateprob(i,dtchain(a))*avgtime(i,dtchain(a))/rpdenominator(i); % random time , prob of item i in list j
107 end
108 end
109 ssprob = randprob;
110
111 for l = 1:h
112 capa(l) = sum(randprob(:,l+1));
113 cdiff(l) = m(l)-capa(l);
114 end
115 capadiff = cdiff;
116 F = cdiff;
117 end
118
119end
Definition fjtag.m:157
Definition Station.m:245