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 % see _kb/09-ldes-and-cache.md (mean-field cache fixed points and TTL edge cases)
65 if lambda(1,i,1) == 0
66 steadystateprob(i,1) = 1;
67 randprob(i,1) = 1;
68 continue;
69 end
70 transmatrix = zeros(h+1, h+1);
71 for j = 1:h+1
72 leafnode = find(R{1,i}(j,:));
73 for k = leafnode
74 if j == 1
75 transmatrix(j,k) = R{1,i}(j,k);
76 else
77 transmatrix(j,k) = (1-exp(-lambda(1,i,j)*x(j-1)))*R{1,i}(j,k);
78 end
79 if j ~= k
80 transmatrix(k,j) = exp(-lambda(1,i,k)*x(k-1));
81 end
82 end
83 end
84 missconnection = find(all(transmatrix==0));
85 dtchain = setdiff(1:h+1, missconnection);
86 transmatrix(missconnection,:)=[];
87 transmatrix(:,missconnection)=[]; % remove the unused nodes in the transfer matrix
88 dtmcprob = dtmc_solve(transmatrix); % solution of dtmc, i.e., prob of item i in list j, 1*h
89 for a = 1:numel(dtchain)
90 steadystateprob(i,dtchain(a)) = dtmcprob(a);
91 if dtchain(a)>1
92 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
93 else
94 avgtime(i,dtchain(a)) = 1/lambda(1,i,dtchain(a));
95 end
96 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
97 end
98 for a = 1:numel(dtchain)
99 randprob(i,dtchain(a)) = steadystateprob(i,dtchain(a))*avgtime(i,dtchain(a))/rpdenominator(i); % random time , prob of item i in list j
100 end
101 end
102 ssprob = randprob;
103
104 for l = 1:h
105 capa(l) = sum(randprob(:,l+1));
106 cdiff(l) = m(l)-capa(l);
107 end
108 capadiff = cdiff;
109 F = cdiff;
110 end
111
112end
Definition fjtag.m:161