-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexhaustive2.m
163 lines (142 loc) · 5.38 KB
/
exhaustive2.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
%--------------------------------------------------------------------------------
% Algorithm to solve ODSTCA pb by
% using EXHAUSTIVE SEARCH to solve SA pb, instead of using BWOA. (still using WOA to solve TPC problem)
%--------------------------------------------------------------------------------
% Output:
% leader_score_bwoa == double == obtained value of maximum U
% leader_pos_bwoa == (N_ul + M_dl) x K
% time == double
function [leader_score_bwoa, leader_pos_bwoa, time] = exhaustive2(UEs, BS, UE_BS, fobj_bwoa, fobj_woa, fobj_woa_dl, h2h, params, var)
% Input:
tic
sa = zeros(UEs.total(1)+BS.total(2), params.noSubcs); % (N_ul + M_dl) x K matrix
n = 1;
cnt = 0;
noSubcs = params.noSubcs;
N_ul = UEs.total(1);
N_dl = UEs.total(2);
M_dl = BS.total(2);
WOA_rs = 0;
WOA_rs_dl = 0;
leader_pos_bwoa = zeros(size(sa));
leader_score_bwoa = -inf;
bwoa = -inf;
% leader_score_woa
pos_woa = zeros(N_ul, 1);
leader_pos_woa = zeros(N_ul, 1);
pos_woa_dl = zeros(N_dl, M_dl);
leader_pos_woa_dl = zeros(N_dl, M_dl);
leader_pos_woa_dl(:,:) = params.P_SBS_min;
phi = @(y,a,x,eta) y*log2(1 + a*x) - (a/log(2))*(eta + y*x)/(1 + a*x);
fmin = @(y,a,x,eta) (eta+y*x)/(params.B_k*log2(1 + a*x));
varepsilon = 1e-5 ;
TRY(n);
function [] = solution(sa1)
flag = 0;
% COMPUTING RESOURCE ALLOCATION
fitbwoa = fobj_bwoa(sa1);
% % condition 1
% if fitbwoa > 1e2 || fitbwoa <= leader_score_bwoa
% flag = 1;
% end
%
% % condition 2
% if (flag == 0)
% WOA_tmp = 0;
% p_tmp = zeros(N_ul,1);
% % p_tmp = zeros(noUsers,1);
% % bisection
% for n1 = 1: (N_ul)
% m = find(UE_BS(n1,:)>0); % SBS that covers UE n
% for k = 1:noSubcs
% if sa(n1, k) == 0
% continue;
% end
% if phi(var.theta(n1), h2h(n1, n1, m, k)/(params.n0), params.p_max, var.eta(n1)) <= 0
% p_tmp(n1) = params.p_max;
% else
% p_s = params.p_min;
% p_t = params.p_max;
% while (abs(p_t - p_s) > varepsilon)
% p_l = (p_t + p_s)/2;
% if phi(var.theta(n1), h2h(n1, n1, m, k)/(params.n0), p_l, var.eta(n1)) <= 0
% p_s = p_l;
% else
% p_t = p_l;
% end
% end
% p_tmp(n1) = (p_s + p_t)/2;
% end
% WOA_tmp = WOA_tmp + fmin(var.theta(n1), h2h(n1, n1, m, k)/(params.n0), p_tmp(n1), var.eta(n1));
% end
% end
% if (fitbwoa - WOA_tmp) <= leader_score_bwoa
% flag = 1;
% end
if flag == 0
% TRANSMIT POWER ALLOCATION
if N_ul > 0
[WOA_rs, pos_woa, ~] = WOA(params.noSearchAgents, ...
N_ul, params.maxIter_woa, var, fobj_woa, leader_pos_woa_dl, sa1);
end
if N_dl>0
if (cnt==0)
leader_pos_woa = pos_woa;
end
[WOA_rs_dl, pos_woa_dl, ~] = WOA_dl(params.noSearchAgents, ...
N_dl, M_dl, UE_BS, params.maxIter_woa, var, fobj_woa_dl, leader_pos_woa, sa1);
end
end
bwoa = fitbwoa - WOA_rs + WOA_rs_dl; % double
cnt = cnt + 1;
if bwoa > leader_score_bwoa
leader_score_bwoa = bwoa;
% make sure DL association to be reasonable
fl_ = sum(UE_BS,1)>0; % 1 x M
fl_ = fl_(1,BS.total(1)+1 :end)'; % M_dl x 1
sa1((N_ul+1):end, :) = sa((N_ul+1):end, :) .* fl_;
leader_pos_bwoa = sa1;
leader_pos_woa = pos_woa;
leader_pos_woa_dl = pos_woa_dl;
fprintf('exhaustive leader: %i\n', bwoa);
end
end
function [] = TRY(n)
for j = 0:params.noSubcs
if j ~= 0
sa(n, j) = 1;
end
if n == N_ul
if M_dl == 0
sa1 = sa;
solution(sa1);
elseif M_dl>0
TRY2(1);
end
else
TRY(n + 1);
end
if j ~= 0
sa(n, j) = 0;
end
end
end
function [] = TRY2(m)
for k = 1:params.noSubcs
sa(N_ul+m, k) = 1;
if m == M_dl
sa1 = sa;
% make sure DL association to be reasonable
fl_ = sum(UE_BS,1)>0; % 1 x M
fl_ = fl_(1,BS.total(1)+1 :end)'; % M_dl x 1
sa1((N_ul+1):end, :) = sa1((N_ul+1):end, :) .* fl_;
solution(sa1);
else
TRY2(m+1);
end
sa(N_ul+m, k) = 0;
end
end
toc;
time = toc;
end