-
Notifications
You must be signed in to change notification settings - Fork 1
/
Setting2-MC.jl
130 lines (108 loc) · 2.7 KB
/
Setting2-MC.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using Distributions
InP=[250,250];
# User generation
# No_MNO=5
# N_UE_s=[20,18,20,15,25]
# ReRate_MNO=[15,12,18,10,16]
# F=5*10^4
# S=220
# B=1000
# L= 100*1024*8 #File size
function random_input()
# global N_UE_s=[20,19,19,18]
global No_MNO=2
global N_UE_s = rand(10:30,No_MNO)
global ReRate_MNO=[16,16] #request rate of each user
N_UE=sum(N_UE_s,1)[1]
UE = zeros(2,N_UE)
uniform_loc = Uniform(1,500)
UE[1,1:N_UE]=rand(uniform_loc,N_UE)
UE[2,1:N_UE]=rand(uniform_loc,N_UE)
# BS and UE distance
d=zeros(N_UE,1)
for i = 1:N_UE
d[i,1]=norm(InP-UE[:,i])
end
d;
for i = 1:N_UE
if(d[i,1]==0)
d[i,1]=d[i,1]+randi([1,500]);
end
end
# pathloss calculation
PL = zeros(N_UE);
for i = 1:N_UE
PL[i]=34 + 40*log10(d[i,1]/1000);
end
# channel gain calculation
normal_distribution = Normal(0,8)
H = zeros(N_UE)
for i = 1:N_UE
H[i]= PL[i]+ rand(normal_distribution)
end
# Power reduction
Pr = zeros(N_UE)
for i = 1:N_UE
Pr[i]= 49 - H[i]
end
# C_u
gxP = 10.^(Pr/10)
SNR=zeros(N_UE)
C_u=zeros(N_UE)
for i = 1:N_UE
SNR[i]= gxP[i]/(20*10^(6-17.4))
C_u[i]=20*10^6*log2(1+SNR[i])
end
# matrix lambda_u,f
Zipf_parameter =rand(N_UE)
prob_u_f_temp=zeros(N_UE, F)
for i =1:N_UE
for j=1:F
prob_u_f_temp[i,j]=1/(j^Zipf_parameter[i])
end
end
prob_sum=1./(sum(prob_u_f_temp,2))
reprob_sum=repmat(prob_sum, 1,F)
prob_u_f= prob_u_f_temp .* reprob_sum
rate_vt=[ReRate_MNO[1]*ones(N_UE_s[1],1); ReRate_MNO[2]*ones(N_UE_s[2],1)]
# rate_vt=[15*ones(N_UE_s[1],1); 12*ones(N_UE_s[2],1); 18*ones(N_UE_s[3],1); 10*ones(N_UE_s[4],1); 16*ones(N_UE_s[5],1)]
rate_matrix=repmat(rate_vt, 1,F)
lamb_u_f=rate_matrix.*prob_u_f
lamb_u=sum(lamb_u_f,2)
global lamb_n = ReRate_MNO.*N_UE_s
# index bat dua user cua tung mvno
# index=[1,21,40,59,77]
index= [1, N_UE_s[1]+1, sum(N_UE_s[1:2])+1]
constant_hf=zeros(No_MNO,F)
sum_n=zeros(No_MNO,F)
for n=1:No_MNO
sum_n[n,:]=sum(lamb_u_f[index[n]:index[n]+N_UE_s[n]-1,:],1)
constant_hf[n,:]=sum_n[n,:] /lamb_n[n]*S
end
w_lamb_hit_u=zeros(N_UE,1)
for i=1:N_UE
if i< index[2]
m=1
elseif i<index[3]
m=2
elseif i<index[4]
m=3
elseif i<index[5]
m=4
else
m=5
end
w_lamb_hit_u[i]= sum(sum_n[m,:].*constant_hf[m,:],2)[1]
end
w_mu_u = C_u/L
global w_ulti = zeros(No_MNO)
global w_lamb_hit_n = zeros(No_MNO)
w_ulti_u = w_lamb_hit_u./w_mu_u
for n=1:No_MNO
w_ulti[n] = sum(w_ulti_u[index[n]:index[n]+N_UE_s[n]-1])
w_lamb_hit_n[n] = sum(w_lamb_hit_u[index[n]:index[n]+N_UE_s[n]-1])
end
end
# println(w_ulti)
# # println(w_lamb_hit_u)
# println(w_lamb_hit_n)