-
Notifications
You must be signed in to change notification settings - Fork 0
/
NDSort.m
64 lines (60 loc) · 2.42 KB
/
NDSort.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 [FrontNo,MaxFNo] = NDSort(PopObj,nSort)
%NDSort - Do non-dominated sorting by efficient non-dominated sort (ENS)
%
% FrontNo = NDSort(A,s) does non-dominated sorting on A, where A is the
% matrix of objective values of a set of individuals, and s is the number
% of individuals being sorted at least. FrontNo(i) means the front No. of
% the i-th individual. The individuals have not been sorted are assigned
% a front No. of inf.
%
% In particular, s = 1 indicates finding only the first non-dominated
% front, s = size(A,1)/2 indicates sorting only half of the population
% (which is often used in the algorithm), and s = inf indicates sorting
% the whole population.
%
% [FrontNo,K] = NDSort(...) also returns the maximum front No. besides
% inf.
%
% Example:
% [FrontNo,MaxFNo] = NDSort(PopObj,1)
%--------------------------------------------------------------------------
% The copyright of the PlatEMO belongs to the BIMK Group. You are free to
% use the PlatEMO for research purposes. All publications which use this
% platform or any code in the platform should acknowledge the use of
% "PlatEMO" and reference "Ye Tian, Ran Cheng, Xingyi Zhang, and Yaochu
% Jin, PlatEMO: A MATLAB Platform for Evolutionary Multi-Objective
% Optimization, 2016".
%--------------------------------------------------------------------------
% Copyright (c) 2016-2017 BIMK Group
[PopObj,~,Loc] = unique(PopObj,'rows');
[PopObj,rank] = sortrows(PopObj);
Table = hist(Loc,1:max(Loc));
[N,M] = size(PopObj);
FrontNo = inf(1,N);
MaxFNo = 0;
while sum(Table(FrontNo<inf)) < min(nSort,length(Loc))
MaxFNo = MaxFNo + 1;
for i = 1 : N
if FrontNo(i) == inf
Dominated = false;
for j = i-1 : -1 : 1
if FrontNo(j) == MaxFNo
m = 2;
while m <= M && PopObj(i,m) >= PopObj(j,m)
m = m + 1;
end
Dominated = m > M;
if Dominated || M == 2
break;
end
end
end
if ~Dominated
FrontNo(i) = MaxFNo;
end
end
end
end
FrontNo(rank) = FrontNo;
FrontNo = FrontNo(Loc);
end