-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMating.m
More file actions
29 lines (23 loc) · 1003 Bytes
/
Mating.m
File metadata and controls
29 lines (23 loc) · 1003 Bytes
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
function Mating()
global mop pop popc;
popcIndex = 1;
RandRange = size(pop, 1);
RandTemp1 = randperm(RandRange);
CandidateIndex1 = RandTemp1(1 : size(pop, 1));
for i1 = 1 : 4 : (size(pop, 1) - mod(size(pop,1), 4))
Candidate1 = pop(CandidateIndex1(i1));
Candidate2 = pop(CandidateIndex1(i1 + 1));
Parent1 = tournament(Candidate1, Candidate2);
Candidate1 = pop(CandidateIndex1(i1 + 2));
Candidate2 = pop(CandidateIndex1(i1 + 3));
Parent2 = tournament(Candidate1, Candidate2);
[popc(popcIndex).Position, popc(popcIndex + 1).Position] = Crossover(Parent1.Position, Parent2.Position);
[popc(popcIndex).RawCost, popc(popcIndex).Cost, popc(popcIndex).Constrains] ...
= costFunction(mop, popc(popcIndex).Position);
[popc(popcIndex + 1).RawCost, popc(popcIndex + 1).Cost, popc(popcIndex + 1).Constrains] ...
= costFunction(mop, popc(popcIndex + 1).Position);
popcIndex = popcIndex + 2;
end
% Merge
pop=[pop; popc];
end