-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimize_cr.m
52 lines (46 loc) · 2.11 KB
/
optimize_cr.m
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
function [p] = optimize_cr(lambda, epsilon, N, precision)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% function: optimize_cr %
% author: Federico Chiariotti ([email protected]) %
% license: GPLv3 %
% %
% %
% %
% Optimize CR transmission probability through bisection search %
% %
% Inputs: %
% -lambda: the generation rate [scalar] %
% -epsilon: the wireless channel error probability [scalar] %
% -N: the number of nodes [scalar] %
% -precision: the required precision on the output [scalar] %
% %
% Outputs: %
% -p: the transmission probability [scalar] %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
p_low = 0;
p_high = 1;
if (N == 1)
p = 1;
return;
end
% Bisection search over the expected resolution time
while (p_low < p_high - precision)
p = (p_high + p_low) / 2;
val = N * lambda * (1- lambda) ^ (N - 1) * epsilon / p;
for c = 2 : N
if (N > 50)
prob = binopdf(c, N, lambda);
else
prob = nchoosek(N, c) * lambda ^ c * (1- lambda) ^ (N - c);
end
val = val + prob * (1 - c * p) / (c * p ^ 2 * (1 - p) ^ c);
end
if (val > 0)
p_low = p;
else
p_high = p;
end
end
end