-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcrossover.m
More file actions
49 lines (22 loc) · 686 Bytes
/
crossover.m
File metadata and controls
49 lines (22 loc) · 686 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function crosspop=crossover(crosspop,pop,ncross)
% Ali Mohammadi_INS/GNSS
f = [pop.fit] ;
f = max(f)-f+eps ;
f = f./sum(f) ;
f = cumsum(f) ;
for n = 1:2:ncross
i1 = find(rand<=f,1,'first') ;
i2 = find(rand<=f,1,'first') ;
p1 = pop(i1).var ;
p2 = pop(i2).var ;
R = rand(size(p1)) ;
o1 = (R.*p1)+((1-R).*p2) ;
o2 = (R.*p2)+((1-R).*p1) ;
crosspop(n).var = o1 ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
crosspop(n).fit = fitness1(o1) ;
crosspop(n+1).var = o2 ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
crosspop(n+1).fit = fitness1(o2) ;
end
end