-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreclin.m
32 lines (21 loc) · 971 Bytes
/
reclin.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
function NewChrom = reclin(OldChrom, XOVR);
% Identify the population size (Nind) and the number of variables (Nvar)
[Nind,Nvar] = size(OldChrom);
% Identify the number of matings
Xops = floor(Nind/2);
% Performs recombination
odd = 1:2:Nind-1;
even= 2:2:Nind;
% position of value of offspring compared to parents
Alpha = -0.25 + 1.5 * rand(Xops,1);
Alpha = Alpha(1:Xops,ones(Nvar,1));
% recombination
NewChrom(odd,:) = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:));
% the same ones more for second half of offspring
Alpha = -0.25 + 1.5 * rand(Xops,1);
Alpha = Alpha(1:Xops,ones(Nvar,1));
NewChrom(even,:) = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:));
% If the number of individuals is odd, the last individual cannot be mated
% but must be included in the new population
if rem(Nind,2), NewChrom(Nind,:)=OldChrom(Nind,:); end
% End of function