-
Notifications
You must be signed in to change notification settings - Fork 1
/
NonDominatedSorting.m
82 lines (63 loc) · 2.43 KB
/
NonDominatedSorting.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
80
81
82
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MATLAB Code for %
% %
% Non-dominated Sorting Genetic Algorithm II (NSGA-II) %
% Version 1.0 - April 2010 %
% %
% Programmed By: S. Mostapha Kalami Heris %
% %
% e-Mail: [email protected] %
% %
% Homepage: http://www.kalami.ir %
% %
% NonDominatedSorting.m : implements the non-dominated sorting %
% procedures %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [pop F]=NonDominatedSorting(pop)
F{1}=[];
npop=numel(pop);
for i=1:npop
p=pop(i);
p.DominationSet=[];
p.DominatedCount=0;
for j=1:npop
if j==i
continue;
end
q=pop(j);
if Dominates(p,q)
p.DominationSet=[p.DominationSet j];
elseif Dominates(q,p)
p.DominatedCount=p.DominatedCount+1;
end
end
if p.DominatedCount==0
p.Rank=1;
F{1}=[F{1} i];
end
pop(i)=p;
end
f=1;
while true
Q=[];
for i=1:numel(F{f})
p=pop(F{f}(i));
for j=1:numel(p.DominationSet)
q=pop(p.DominationSet(j));
q.DominatedCount=q.DominatedCount-1;
if q.DominatedCount==0
q.Rank=f+1;
Q=[Q p.DominationSet(j)];
end
pop(p.DominationSet(j))=q;
end
end
if isempty(Q)
break;
end
F{f+1}=Q;
f=f+1;
end
end