-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP1_1.m
70 lines (62 loc) · 1.28 KB
/
P1_1.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
clc
clear
Weather = [0,1,0,0,0,0,1,1,1,1];
map = [2,4,5,0,0,0
1,3,4,0,0,0
2,4,8,9,0,0
1,2,3,5,6,7
1,4,6,0,0,0
4,5,7,12,13,0
4,6,11,12,0,0
3,9,0,0,0,0
3,8,10,11,0,0
9,11,13,0,0,0
7,9,10,12,13,0
6,7,11,13,0,0
-1,-1,-1,-1,-1,-1];
N = 100*2;
c = 0;
adaption = zeros(1,N/2);
descendants = zeros(N,10);
best = 0;
for i0 = 1:N
groupa(i0,:) = ance;
end
bestGene_a = zeros(2,10);
bestGene_d = zeros(2,10);
groupd = ones(N,10);
for J = 1 : 20000
[gamete_d] = mate(groupd);
for i = 1:2:N
adaption((i+1)/2) = adapt([gamete_d(i,:);gamete_d(i+1,:)]);
end
[H2L,rank] = sort(adaption,'descend');
adaptionsum = zeros(1,N/2);
adaptionsum(1) = H2L(1);
for i1 = 2 : N/2
adaptionsum(i1) = adaptionsum(i1-1)+H2L(i1);
end
if H2L(1)>best
best = H2L(1);
c = c+1;
bestGene_d(1,:) = gamete_d(2*rank(1)-1,:);
bestGene_d(2,:) = gamete_d(2*rank(1),:);
end
ALL = sum(adaption);
ratio = adaptionsum/ALL;
a= 1;
a= fix(ratio*N/2);
b = 1;
for i2 = 1:N/2
for t = b:a(i2)
groupd(2*t,:) = gamete_d(2*rank(i2),:);
groupd(2*t-1,:) = gamete_d(2*rank(i2)-1,:);
end
b = a(i2)+1;
if a(i2)==N
continue
end
end
end
bestGene_d
best = best