├── .DS_Store ├── 1_Rayleigh_Fading_Model ├── .DS_Store ├── Throughput.m ├── calcH.m ├── getTransMatrix.m ├── gethopMatrix_1.m ├── gethopMatrix_2.m ├── hitMatrix.m ├── main_numerical.m ├── prodV.m └── zipf_rand.m └── Readme.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dherath/Markov_model_Opportunistic_RequestRouting/599aa240d3c1bb4630cd37b7e7c6e660d2e89a87/.DS_Store -------------------------------------------------------------------------------- /1_Rayleigh_Fading_Model/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dherath/Markov_model_Opportunistic_RequestRouting/599aa240d3c1bb4630cd37b7e7c6e660d2e89a87/1_Rayleigh_Fading_Model/.DS_Store -------------------------------------------------------------------------------- /1_Rayleigh_Fading_Model/Throughput.m: -------------------------------------------------------------------------------- 1 | function t = Throughput(n,p,hits,rho) 2 | %calculates throughput for uncorrelted fading 3 | %n size of matrix 4 | %p the probability for one hop (successive distances are simillar) 5 | %hits hit distribution for the content in question 6 | 7 | P = getTransMatrix(n,p,hits,rho);%transition matrix for some content 8 | steady = P^1000;%assuming 1000 is a reasonable power to get steady state 9 | t = steady(1,end); 10 | end 11 | 12 | -------------------------------------------------------------------------------- /1_Rayleigh_Fading_Model/calcH.m: -------------------------------------------------------------------------------- 1 | function m = calcH(n,H,h) 2 | 3 | m = zeros(1,n-1);% the matrix 4 | 5 | for i = 1:n-1 6 | multV = 1; 7 | p_set = h(i,H); 8 | for k=1:length(p_set) 9 | multV = multV*(1-p_set(k)); 10 | end 11 | m(i) = multV; 12 | end 13 | 14 | end 15 | 16 | -------------------------------------------------------------------------------- /1_Rayleigh_Fading_Model/getTransMatrix.m: -------------------------------------------------------------------------------- 1 | function P = getTransMatrix(n,p,hits,rho) 2 | %n the number of nodes 3 | %p the initial transmission probability 4 | %hits the content placement 5 | %P th transission matrix for some fth content 6 | 7 | N = 2*(n-1); % number of total states 8 | P = zeros(N,N); 9 | H = find(hits==1); % the whole set with possible hits 10 | M = find(hits==0); % the whole set with misses 11 | 12 | h1 = gethopMatrix_1(n,p); 13 | h2 = gethopMatrix_2(n,h1,rho); 14 | % have a function to calculate As and A_ 15 | 16 | % A = zeros(1,n); 17 | %A_ = zeros(1,n); 18 | 19 | A = calcH(n,H,h1); 20 | A_ = calcH(n,H,h2); 21 | 22 | % A 23 | % A_ 24 | %test_matrix = zeros(N,N); %transitions are correct 25 | % I_test = zeros(N,N); 26 | % J_test = zeros(N,N); 27 | 28 | %--------------------- 29 | % I_state = 0 (non star) 1(star) 30 | % J_state = 0 (non star) 1(star) 31 | for I=1:N 32 | for J=1:N 33 | %--------------------------- 34 | if I==1 35 | i=1; 36 | I_state = 1; 37 | elseif I==N 38 | i=n; 39 | I_state = 0; 40 | elseif mod(I,2) == 0 41 | i = ceil((I+1)/2); 42 | I_state = 0; 43 | else 44 | I_state = 1; 45 | end 46 | %--------------------------- 47 | if J == 1 48 | j = 1; 49 | J_state = 1; 50 | elseif J == N 51 | j = n; 52 | J_state = 0; 53 | elseif mod(J,2)==0 54 | j=j+1; 55 | J_state = 0 ; 56 | else 57 | J_state = 1 ; 58 | end 59 | % I_test(I,J) = i; 60 | % J_test(I,J) = j; 61 | % %--------------------------- 62 | if hits(i) == 1 && i ~=n 63 | if isequal(j,n) 64 | P(I,J) = 1; 65 | else 66 | P(I,J) = 0; 67 | end 68 | elseif hits(j) == 1 && j ~=n 69 | P(I,J) = 0; 70 | else 71 | %----P_0, non star-> non star------ 72 | if I_state == 0 && J_state == 0 73 | if i star -------- 86 | elseif I_state == 0 && J_state == 1 87 | %test_matrix(I,J) = 1; 88 | 89 | if i==j && i non_star ------- 96 | elseif I_state == 1 && J_state == 0 97 | %test_matrix(I,J) = 2; 98 | if i star ----------- 105 | elseif I_state == 1 && J_state == 1 106 | %test_matrix(I,J) = 3; 107 | if i==j && i correct 125 | % disp('start relays ->'); 126 | % disp(I_test); 127 | % disp('end relays->'); 128 | % disp(J_test); 129 | 130 | end 131 | 132 | -------------------------------------------------------------------------------- /1_Rayleigh_Fading_Model/gethopMatrix_1.m: -------------------------------------------------------------------------------- 1 | function matrix = gethopMatrix_1(n,p) 2 | % modification- OCt 20 217 3 | % n - size of the matrix 4 | % p - intital probability 5 | matrix = zeros(n,n); 6 | 7 | for i=1:n %rows 8 | p_=p; 9 | count = 1; 10 | count2=i-1; 11 | for j=1:n %columns 12 | if ij && i ~= n 16 | matrix(i,j)= p_^(count2.^2); 17 | count2 = count2-1; 18 | end 19 | end 20 | end 21 | 22 | for i=1:n 23 | matrix(i,1) = 0; 24 | end 25 | 26 | %disp('hops matrix ->'); 27 | %disp(matrix); 28 | end 29 | 30 | -------------------------------------------------------------------------------- /1_Rayleigh_Fading_Model/gethopMatrix_2.m: -------------------------------------------------------------------------------- 1 | function matrix = gethopMatrix_2(n,hopMatrix1,rho) 2 | % modification- OCt 22 2017 3 | % n - size of the matrix 4 | % P_12 P_13 P_14 5 | % P_23 P_24 6 | % P_34 7 | 8 | b = -log(hopMatrix1);% b marix for all transmissions 9 | theta = sqrt((2*b)./(1-rho^2));% theta matrix for all transmissions 10 | matrix = zeros(n,n); 11 | 12 | for i=1:n %rows 13 | for j=1:n %columns 14 | if i ~=j && i ~=n 15 | Q_1 = marcumq( theta(i,j) , ( rho*theta(i,j)) ); 16 | Q_2 = marcumq( (rho*theta(i,j)), theta(i,j) ); 17 | matrix(i,j) = ( Q_1 - Q_2 )/( exp(b(i,j)) - 1 ); 18 | end 19 | end 20 | end 21 | 22 | end 23 | 24 | -------------------------------------------------------------------------------- /1_Rayleigh_Fading_Model/hitMatrix.m: -------------------------------------------------------------------------------- 1 | function h = hitMatrix(n,totContent,cacheSize) 2 | %h - the hit matrix tot * n 3 | %n - number of nodes 4 | %casheSize - cache capacity of a node = 10 5 | %totContent - total number of content 6 | rng(100); 7 | 8 | h = zeros(totContent,n); 9 | h(:,1) = 0; % source node has no cache 10 | h(:,n) = 1;%destination has everyhting 11 | 12 | % cache policy 13 | % 1-5 -> from first 20 content 14 | % 6-10 -> from rest 80 content 15 | 16 | %cacheSize = 10;% < total content 17 | for i=2:n-1 18 | list1 = randperm(20,cacheSize/2); 19 | list2 = randperm(80,cacheSize/2) + 20 ; 20 | list3 = [list1,list2]; 21 | for j = 1:cacheSize 22 | h(list3(j),i) = 1; 23 | end 24 | end 25 | 26 | end 27 | 28 | -------------------------------------------------------------------------------- /1_Rayleigh_Fading_Model/main_numerical.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear; 3 | n=4; % number of nodes 4 | p=0.9;% maximum one hop probability 5 | pList = 0.1:0.1:p;%a list of one hop probabilities 0.1-0.9 6 | alpha = 0.8; % zipfian parameter 7 | totContent = 100; %total content 8 | rho = 0.9; % correlation factor 9 | %---------------------------- 10 | popularity = zipf_rand(1000,alpha,totContent);%seed(100) 11 | popularity = sort(popularity,'descend'); 12 | popularity = popularity/sum(popularity); 13 | %---------------------------- 14 | cacheSize = 10; 15 | content_2 = hitMatrix(n,totContent,cacheSize); 16 | %content_2 = zeros(totContent,n); 17 | %content_2(:,end) = 1; 18 | D_list_num10_r09 = zeros(1,length(pList)); 19 | for i = 1 : length(pList) 20 | %-------- numerical ----------------------- 21 | individual_T = zeros(1,totContent);%delay values for individual content 22 | for j = 1 : totContent 23 | hits = content_2(j,:); 24 | individual_T(j) = Throughput(n,pList(i),hits,rho); 25 | end 26 | D_list_num10_r09(i) = sum(popularity./individual_T); 27 | disp(strcat('numerical done ',num2str(i))); 28 | end 29 | disp('numerical complete : correlated rho =0.9 C = 10'); 30 | %D_list_num = 1./D_list_num; 31 | plot(D_list_num10_r09); 32 | save('D_list_num10_r09.mat','D_list_num10_r09'); 33 | -------------------------------------------------------------------------------- /1_Rayleigh_Fading_Model/prodV.m: -------------------------------------------------------------------------------- 1 | function val = prodV(j,M,h) 2 | loc = M(M>j); 3 | fwd_list = h(loc); 4 | multV = 1; 5 | for c=1:length(fwd_list) 6 | multV = multV * (1-fwd_list(c)); 7 | end 8 | val = multV; 9 | end 10 | 11 | -------------------------------------------------------------------------------- /1_Rayleigh_Fading_Model/zipf_rand.m: -------------------------------------------------------------------------------- 1 | function x = zipf_rand(N, expn, M) 2 | % Generate random numbers based on Zipf distribution 3 | % Author: Tuyen Tran (tuyen.tran@rutgers.edu). Oct 2015 4 | % 5 | % Reference: https://en.wikipedia.org/wiki/Zipf's_law 6 | % 7 | % N Number of Elements 8 | % expn Exponent 9 | % M Number of sample to be generated 10 | % 11 | % Example: zipf_rand(3,1,4) 12 | % ans = 3 2 1 1 13 | rng(100);%uses same seed for all random number generations-dinal 14 | if nargin == 2 15 | M = 1; 16 | end 17 | 18 | ranks = 1:1:N; 19 | 20 | pmf = (ranks.^(-expn))/sum(ranks.^(-expn)); 21 | 22 | samples = rand(1,M); 23 | 24 | p = cumsum(pmf(:)); 25 | 26 | [~,x] = histc(samples,[0;p/p(end)]); 27 | 28 | end 29 | 30 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Code : Analytical Model for Opportunistic Request Routing 2 | 3 | For all models, running the main_numerical.m file will automatically run all the code and generate the output. 4 | The parameters of cache size, correlation, content universe size can be changed in main_numerical.m 5 | 6 | ## papers 7 | 8 | 1. Analyzing Opportunisitic Request Routing in Wireless Cache Networks (ICC 2018) [link](http://dinalherath.com/papers/2018ICC.pdf) 9 | 2. A Markovian Model for Analyzing Opportunisitic Request Routing in Wireless Cache Networks (TVT 2019) [link](http://dinalherath.com/papers/2018tvt.pdf) 10 | 11 | ## folder structure 12 | 13 | 1_Rayleigh_Fading_Model 14 | --------------------------------------------------------------------------------