-
Notifications
You must be signed in to change notification settings - Fork 1
/
NonDominatedSorting.m
71 lines (49 loc) · 1.42 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
function [pop F]=NonDominatedSorting(pop)
nPop=numel(pop);
for i=1:nPop
pop(i).DominationSet=[];
pop(i).DominatedCount=0;
end
F{1}=[];
for i=1:nPop
for j=i+1:nPop
p=pop(i);
q=pop(j);
if Dominates(p,q)
p.DominationSet=[p.DominationSet j];
q.DominatedCount=q.DominatedCount+1;
end
if Dominates(q.Cost,p.Cost)
q.DominationSet=[q.DominationSet i];
p.DominatedCount=p.DominatedCount+1;
end
pop(i)=p;
pop(j)=q;
end
if pop(i).DominatedCount==0
F{1}=[F{1} i];
pop(i).Rank=1;
end
end
k=1;
while true
Q=[];
for i=F{k}
p=pop(i);
for j=p.DominationSet
q=pop(j);
q.DominatedCount=q.DominatedCount-1;
if q.DominatedCount==0
Q=[Q j];
q.Rank=k+1;
end
pop(j)=q;
end
end
if isempty(Q)
break;
end
F{k+1}=Q;
k=k+1;
end
end