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