-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnondominated_sort.m
44 lines (41 loc) · 1.1 KB
/
nondominated_sort.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
function F = nondominated_sort(pop)
% non-dominated sorting
num_pop = numel(pop);
for i = 1:num_pop
domination_set{i} = [];
dominated_cnt{i} = 0;
end
F{1} = [];
for i = 1:num_pop
for j = i+1:num_pop
if dominates(pop(i).cost, pop(j).cost)
domination_set{i} = [domination_set{i}, j];
dominated_cnt{j} = dominated_cnt{j} + 1;
end
if dominates(pop(j).cost, pop(i).cost)
domination_set{j} = [domination_set{j}, i];
dominated_cnt{i} = dominated_cnt{i} + 1;
end
end
if dominated_cnt{i} == 0
F{1} = [F{1}, i];
end
end
k = 1;
while true
Q = []; % Q is used to store F in k+1 layer
for i = F{k}
for j = domination_set{i}
dominated_cnt{j} = dominated_cnt{j} - 1;
if dominated_cnt{j} == 0
Q = [Q, j];
end
end
end
if isempty(Q)
break;
end
F{k + 1} = Q;
k = k + 1;
end
end