-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMatingPool.m
More file actions
55 lines (48 loc) · 1.87 KB
/
MatingPool.m
File metadata and controls
55 lines (48 loc) · 1.87 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
52
53
54
55
function MatingPool = MatingPool(Population,Archive,N)
% MATINGPOOL 产生更多可行解
MatingPool = [];
if length(Archive)<N
PopAll = [Population,Archive];
[~,b]=unique(PopAll.objs,'rows');
PopAll = PopAll(1,b);
SelectedIndex= TournamentSelection(2,N,sum(PopAll.objs,2),DensityCal(PopAll.decs));
MatingPool= PopAll(SelectedIndex);
else
AllPop = [ Population,Archive];
Zmin = min(AllPop.objs,[],1);
PopObj = (AllPop.objs-repmat(Zmin,length(AllPop.objs),1))./(repmat(max(AllPop.objs),length(AllPop.objs),1)-repmat(Zmin,length(AllPop.objs),1)+1e-10)+1e-10;
Cosine = 1 - pdist2(PopObj,PopObj,'cosine');
Cosine = Cosine.*(1-eye(size(PopObj,1)));
Temp = sort(-Cosine,2);
[~,Rank] = sortrows(Temp);
CV1 = sum(max(0,Population.cons),2);
CV2 = sum(max(0,Archive.cons),2);
Angle1 = Rank(1:N);
Angle2 = Rank(N+1:length(AllPop));
Index1 = randi(N,1,N);
Index2 = randi(length(Archive),1,N);
i = 0;
while length(MatingPool) < N
if CV1(Index1(i+1)) < CV2(Index2(i+1))
MatingPool = [MatingPool,Population(Index1(i+1))];
else
MatingPool = [MatingPool,Archive(Index2(i+1))];
end
if Angle1(Index1(i+2)) < Angle2(Index2(i+2))
MatingPool = [MatingPool,Population(Index1(i+2))];
else
MatingPool = [MatingPool,Archive(Index2(i+2))];
end
i = i + 2;
end
end
end
function Density = DensityCal(PopObj)
[N,~] = size(PopObj);
Zmin = min(PopObj,[],1);
PopObj = (PopObj-repmat(Zmin,N,1))./(repmat(max(PopObj),N,1)-repmat(Zmin,N,1)+1e-20);
Distance = pdist2(PopObj,PopObj);
Distance(logical(eye(length(Distance)))) = Inf;
DistanceSort = sort(Distance,2);
Density = 1./(1+DistanceSort(:,floor(sqrt(length(Distance)))+1));
end