-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalcCrowdingDistance.m
66 lines (38 loc) · 1.14 KB
/
CalcCrowdingDistance.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
%
% Copyright (c) 2015, Yarpiz (www.yarpiz.com)
% All rights reserved. Please read the "license.txt" for license terms.
%
% Project Code: YPEA120
% Project Title: Non-dominated Sorting Genetic Algorithm II (NSGA-II)
% Publisher: Yarpiz (www.yarpiz.com)
%
% Developer: S. Mostapha Kalami Heris (Member of Yarpiz Team)
%
% Contact Info: [email protected], [email protected]
%
function pop=CalcCrowdingDistance(pop)
% Calculate Crowding Distance for Particles in the Repository
Costs=[pop.Cost];
nObj=size(Costs,1);
n=numel(pop);
d=zeros(n,nObj);
for j=1:nObj
[cj, so]=sort(Costs(j,:));
d(so(1),j)=inf;
r=abs(cj(1)-cj(end));
if r==0
r=1;
end
for i=2:n-1
d(so(i),j)=abs(cj(i+1)-cj(i-1))/r;
end
d(so(end),j)=inf;
end
for i=1:n
if sum(pop(i).TargetRegionFlag) == 0 % Particles not in the Target Region
pop(i).CrowdingDistance=0;
continue
end
pop(i).CrowdingDistance=sum(d(i,:));
end
end