-
Notifications
You must be signed in to change notification settings - Fork 0
/
fast_sort.m
64 lines (52 loc) · 1.91 KB
/
fast_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function[fr_1, fr_2, fr_3, fr_4] = fast_sort(population)
num_fronts = 4;
len = length(population(:,1));
% Allocating Fronts
F_i = cell(num_fronts,1);
fr_1 = [];
fr_2 = [];
fr_3 = [];
fr_4 = [];
f_pop = [];
for i=1:len
n = 0; %domination count
S = []; %empty set
for j=1:len
if ((population(i, 1) < population(j, 1)) && (population(i, 2) < population(j, 2))) || ((population(i, 1) == population(j, 1)) && (population(i, 2) < population(j, 2))) || ((population(i, 1) < population(j, 1)) && (population(i, 2) == population(j, 2)))
S = [S, j];
elseif ((population(i, 1) > population(j, 1) && (population(i, 2) > population(j, 2))) || (population(i, 1) == population(j, 1)) && (population(i, 2) > population(j, 2))) || ((population(i, 1) > population(j, 1)) && (population(i, 2) == population(j, 2)))
n = n + 1;
end
end
% This candidate with fitness 1, fitness 2, and number i
candidate = [population(i, 1), population(i, 2), i];
if n == 0
fr_1 = [fr_1; candidate 1];
else
f_pop = [f_pop; [candidate n]];
end
end
% Find remaining fronts
for i = 2:num_fronts
% Initialize next front
temp_pop = f_pop;
% Last front
if i == num_fronts
fr_2 = F_i{2,1};
fr_3 = F_i{3,1};
fr_4 = sortrows(temp_pop, 4);
if isempty(fr_1)
fr_1 = fr_2;
fr_2 = fr_3;
fr_3 = fr_4;
end
return;
end
% n-array of
n = temp_pop(:,4);
minimum = min(n);
temp_front = n == minimum;
F_i{i,1} = temp_pop(temp_front, :);
f_pop(temp_front, :) = [];
end
end