-
Notifications
You must be signed in to change notification settings - Fork 29
/
assign_rank_and_crowding_distance.m
42 lines (37 loc) · 1.35 KB
/
assign_rank_and_crowding_distance.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
function [pop] = assign_rank_and_crowding_distance(pop)
% This procedure applies the non-dominated sort and
% then compute the crowding distance within each front.
global nreal ;
global nbin ;
global nbits ;
global nobj ;
global ncon ;
if(nreal > 0)
rank_col = nreal + nobj + ncon + 2 ;
elseif(nbin > 0)
rank_col = sum(nbits) + nobj + ncon + 2 ;
end
[popsize, ~] = size(pop);
all_indices = 1:popsize; % initially start with the whole population
% generate the dominance matrix with the current indices
dominance_matrix = generate_dominance_matrix(... % It's fast now
pop(all_indices,:), ...
all_indices);
front = 1 ; % initial front is 1
while (not(isempty(all_indices)))
% for i = 1:1
% now reduce the dom_mat
dom_mat = [all_indices.', dominance_matrix(all_indices, all_indices+1)];
% get the indices of the current pf
minus_one_count = [all_indices.', sum(dom_mat == -1,2)] ;
pf_indices = minus_one_count(minus_one_count(:,2) == 0,1);
% assign the current front number
pop(pf_indices, rank_col) = front;
% now do the crowding distance assignment for this front
pop = assign_crowding_distance(pop, pf_indices);
% remove the ranked indices from the list
all_indices = all_indices(~ismember(all_indices, pf_indices));
% go to next front
front = front + 1;
end
end