forked from ankurzing/bleaq2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculateCrowdingDistance.m
38 lines (29 loc) · 1.27 KB
/
calculateCrowdingDistance.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
function [crowdingDistance] = calculateCrowdingDistance(functionValue, paretoRank)
noOfObj = size(functionValue,2);
popSize = size(functionValue,1);
crowdingDistance = zeros(popSize,1);
for i=1:max(paretoRank)
indices = find(paretoRank==i);
[crowdingDistance(indices)] = calculateFrontCrowdingDistance(functionValue(indices,:));
end
function [crowdingDistance] = calculateFrontCrowdingDistance(functionValue)
noOfObj = size(functionValue,2);
popSize = size(functionValue,1);
sortingRank = zeros(size(functionValue));
sortedFunctionValue = zeros(size(functionValue));
for i=1:noOfObj
[sortedFunctionValue(:,i), sortingIndices(:,i)] = sort(functionValue(:,i),'descend');
[~,sortingRank(:,i)] = sort(sortingIndices(:,i),'ascend');
end
crowdingDistance = zeros(popSize,1);
for i=1:popSize
for j=1:noOfObj
lowerRank = find(sortingRank(i,j)+1==sortingRank(:,j));
upperRank = find(sortingRank(i,j)-1==sortingRank(:,j));
if ~isempty(lowerRank) && ~isempty(upperRank)
crowdingDistance(i) = crowdingDistance(i) + abs(functionValue(i,j)-functionValue(lowerRank,j)) + abs(functionValue(i,j)-functionValue(upperRank,j));
else
crowdingDistance(i) = crowdingDistance(i)+Inf;
end
end
end