-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvironmentalSelectionMOP.m
105 lines (94 loc) · 3.89 KB
/
EnvironmentalSelectionMOP.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function [Population, FrontNo, CrowdDis] = EnvironmentalSelectionMOP(Population, N)
% Environmental selection of MFFS for multi-objective task
%------------------------------- Copyright --------------------------------
% Copyright (c) 2021 BIMK Group. You are free to use the PlatEMO for
% research purposes. All publications which use this platform or any code
% in the platform should acknowledge the use of "PlatEMO" and reference "Ye
% Tian, Ran Cheng, Xingyi Zhang, and Yaochu Jin, PlatEMO: A MATLAB platform
% for evolutionary multi-objective optimization [educational forum], IEEE
% Computational Intelligence Magazine, 2017, 12(4): 73-87".
%--------------------------------------------------------------------------
% Calculate average distance of the parent population in the search space
PopDec = Population(1:N).decs;
aDist = pdist2(round(PopDec), round(PopDec), "hamming");
aveDis = sum(sum(tril(aDist, 0)))./sum(1:(size(PopDec,1)-1));
% Remove duplicated solutions in te population
PopDec = Population.decs;
[~, index] = unique(PopDec, 'rows');
Population = Population(index);
PopObj = Population.objs;
PopDec = Population.decs;
% Nondominated sorting
FrontNo = NDSort(PopObj, inf);
NextNo = false(1, size(PopObj, 1));
% Directly save solutions in the first front
First = find(FrontNo==1);
NextNo(First) = 1;
NDpoints = Population(First);
while sum(NextNo) < N || sum(NextNo)==size(PopObj, 1)
for i = 2:max(FrontNo)
FrontPop = [];
No = find(FrontNo==i);
No = No(NextNo(No)==0);
Pop = Population(No);
PopObj = Pop.objs;
[Obj, ~, c] = unique(PopObj, 'rows', 'stable');
for j=1:max(c)
index = find(c==j);
if size(index, 1) > 1
selectedNo = DuplicationSelection(No(index), Population, NDpoints, NextNo, aveDis);
FrontPop = [FrontPop, selectedNo];
else
FrontPop = [FrontPop, No(index)];
end
end
NextNo(FrontPop) = 1;
if sum(NextNo) >= N
break;
end
end
end
Population = Population(NextNo);
FrontNo = FrontNo(NextNo);
MaxFNo = max(FrontNo);
Next = FrontNo < MaxFNo;
%% Calculate the crowding distance of each solution
CrowdDis = CrowdingDistance(Population.objs, FrontNo);
%% Select the solutions in the last front based on their crowding distances
Last = find(FrontNo == MaxFNo);
[~,Rank] = sort(CrowdDis(Last), 'descend');
Next(Last(Rank(1:N-sum(Next)))) = true;
%% Population for next generation
Population = Population(Next);
FrontNo = FrontNo(Next);
CrowdDis = CrowdDis(Next);
end
function selectedNo = DuplicationSelection(index, Population, NDpoints, Next, aveDis)
% Choose one solution from many duplicated solutions (objective space)
NDobj = NDpoints.objs;
NDdec = NDpoints.decs;
Nextobj = Population(Next).objs;
Nextdec = Population(Next).decs;
Obj = Population(index).objs;
Dec = Population(index).decs;
[r, c] = ismember(Obj(1,2), Nextobj(:,2));
if r == 1
aDist = pdist2(Dec, Nextdec(c,:), "hamming");
if sum(index(aDist>=aveDis)) >= 1
selectedNo = index(aDist>=aveDis);
else
[~, No] = max(sum(aDist,2), [], 1);
selectedNo = index(No);
end
else
Dis = abs(repmat(Obj(1,2),size(NDobj,1),1) - NDobj(:,2));
[~, no] = min(Dis, [], 1);
aDist = pdist2(Dec, NDdec(no,:), "hamming");
if sum(index(aDist>=aveDis)) >= 1
selectedNo = index(aDist>=aveDis);
else
[~, No] = max(sum(aDist,2), [], 1);
selectedNo = index(No);
end
end
end