-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEnvironmentalSelection.m
More file actions
51 lines (46 loc) · 1.77 KB
/
EnvironmentalSelection.m
File metadata and controls
51 lines (46 loc) · 1.77 KB
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
function [Population,Fitness] = EnvironmentalSelection(Population,N,isOrigin)
% The environmental selection of SPEA2
%------------------------------- Copyright --------------------------------
% Copyright (c) 2018-2019 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 the fitness of each solution
if isOrigin
Fitness = CalFitness(Population.objs,Population.cons);
else
Fitness = CalFitness(Population.objs);
end
%% Environmental selection
Next = Fitness < 1;
if sum(Next) < N
[~,Rank] = sort(Fitness);
Next(Rank(1:N)) = true;
elseif sum(Next) > N
Del = Truncation(Population(Next).objs,sum(Next)-N);
Temp = find(Next);
Next(Temp(Del)) = false;
end
% Population for next generation
Population = Population(Next);
Fitness = Fitness(Next);
% Sort the population
[Fitness,rank] = sort(Fitness);
Population = Population(rank);
end
function Del = Truncation(PopObj,K)
% Select part of the solutions by truncation
%% Truncation
Distance = pdist2(PopObj,PopObj);
Distance(logical(eye(length(Distance)))) = inf;
Del = false(1,size(PopObj,1));
while sum(Del) < K
Remain = find(~Del);
Temp = sort(Distance(Remain,Remain),2);
[~,Rank] = sortrows(Temp);
Del(Remain(Rank(1))) = true;
end
end