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