-
Notifications
You must be signed in to change notification settings - Fork 0
/
NDSort.m
79 lines (77 loc) · 3.28 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function [FrontNo,MaxFNo] = NDSort(varargin)
%NDSort - Do non-dominated sorting by efficient non-dominated sort (ENS)
%
% FrontNo = NDSort(F,s) does non-dominated sorting on F, where F is the
% matrix of objective values of a set of individuals, and s is the number
% of individuals to be sorted at least. FrontNo(i) denotes the front
% number of the i-th individual. The individuals have not been sorted are
% assigned a front number of inf.
%
% FrontNo = NDSort(F,C,s) does the non-dominated sorting based on
% constrained-domination, where C is the matrix of constraint values of
% the individuals. In this case, feasible solutions always dominate
% infeasible solutions, and one infeasible solution dominates another
% infeasible solution if the former has a smaller overall constraint
% violation than the latter.
%
% In particular, s = 1 indicates finding only the first non-dominated
% front, s = size(F,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 number besides
% inf.
%
% Example:
% [FrontNo,MaxFNo] = NDSort(PopObj,1)
% [FrontNo,MaxFNo] = NDSort(PopObj,PopCon,inf)
%--------------------------------------------------------------------------
% Copyright (c) 2016-2017 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 [Educational Forum], IEEE
% Computational Intelligence Magazine, 2017, 12(4): 73-87".
%--------------------------------------------------------------------------
if nargin == 2
PopObj = varargin{1};
nSort = varargin{2};
else
PopObj = varargin{1};
PopCon = varargin{2};
nSort = varargin{3};
Infeasible = any(PopCon>0,2);
PopObj(Infeasible,:) = repmat(max(PopObj,[],1),sum(Infeasible),1) + repmat(sum(max(0,PopCon(Infeasible,:)),2),1,size(PopObj,2));
end
[PopObj,~,Loc] = unique(PopObj,'rows');
Table = hist(Loc,1:max(Loc));
[N,M] = size(PopObj);
[PopObj,rank] = sortrows(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