-
Notifications
You must be signed in to change notification settings - Fork 1
/
BinaryTournamentSelection.m
40 lines (34 loc) · 1.5 KB
/
BinaryTournamentSelection.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MATLAB Code for %
% %
% Non-dominated Sorting Genetic Algorithm II (NSGA-II) %
% Version 1.0 - April 2010 %
% %
% Programmed By: S. Mostapha Kalami Heris %
% %
% e-Mail: sm.kalami@gmail.com %
% kalami@ee.kntu.ac.ir %
% %
% Homepage: http://www.kalami.ir %
% %
% BinaryTournamentSelection.m : implelemnts binary tournament %
% selection %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function p=BinaryTournamentSelection(pop)
npop=numel(pop);
i=randi(npop,1,2); %randint depreciated
p1=pop(i(1));
p2=pop(i(2));
if p1.Rank < p2.Rank
p=p1;
elseif p1.Rank > p2.Rank
p=p2;
else
if p1.CrowdingDistance>p2.CrowdingDistance
p=p1;
else
p=p2;
end
end
end