feat(eta_calculation): Implementing "Joint Caching and Freshness Optimization" (in progress)

Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
This commit is contained in:
Tuan-Dat Tran
2024-12-02 18:07:08 +01:00
parent b2cc80bb09
commit 4ea5505130
7 changed files with 47164 additions and 42 deletions

View File

@@ -1,25 +1,25 @@
function [h_optt] = Theoritical_opt(lambda,B,c_f,c_delta)
%% Theoritical optimization
%% Theoritical optimization
%% Iterative identification of active constraints
N=length(lambda)
flag=1;
h_optt=zeros(N,1); %optimal hit prob
differenc_set=1:N; % the set of variables to optimize
differenc_set=1:N; % the set of variables to optimize
fix_i=[]; % set of variables that reached optimality and are excluded from the optimization
n=N;
n=N;
b=B;
%%
while flag
if(n==0)
if(n==0)
if(b>0) % if there is left over cache size and mu is not zero (the loop would break), redistribute it among the zero hit probability
differenc_set=find(h_optt==0)';
fix_i=setdiff(1:N,differenc_set)';
n=length(differenc_set);
continue;
else
continue;
else
h_optt(differenc_set)=0;
break;
end
@@ -27,23 +27,23 @@ while flag
% Optimal Lagrangian mult. and hit prob. calculated theoritically for the set of variables in differenc_set
mu=max(0,(n*c_f-b*c_delta)/ sum(1./lambda(differenc_set))); %optimal lagrangian mult.
h_optt(differenc_set)=(c_f-mu./lambda(differenc_set))/c_delta %optimal hit prob
% mu has to be >=0
if(mu<0)
b=(n*c_f/c_delta); % this sets mu to zero in the next iteration
continue;
end
% check the violation of the hit_prob const
% check the violation of the hit_prob const
larger_i=find(h_optt>1); % h>1
smaller_i=find(h_optt<0); % h<0
if(length(smaller_i)==0 && length(larger_i)==0)
break;
end
% find the furthest object from the 0 boundary
min_viol=0;
min_viol_i=-1;
@@ -51,14 +51,14 @@ while flag
[min_viol, min_viol_i]=min(h_optt);
end
% find the furthest object from the 1 boundary
max_viol=0;
max_viol=0;
max_viol_i=-1;
if(length(larger_i)>0)
larger=h_optt-1;
[max_viol ,max_viol_i]=max(h_optt-1);
end
% compare both furthest objects from both boundaries
viol_i=min_viol_i;
min_viol_flag=1; % True if the furthest one is from the left
@@ -73,18 +73,15 @@ while flag
else
h_optt(viol_i)=min(1,b);
end
%calculate the new parameters after removing the furthest object from
%the decision variables
B_new=b-(h_optt(viol_i));
b=B_new;
fix_i=[fix_i' viol_i']';
differenc_set=setdiff(1:N,fix_i) ;
differenc_set=setdiff(1:N,fix_i) ;
n=N-length(fix_i);
end
end