-
Notifications
You must be signed in to change notification settings - Fork 1
/
initpop.m
52 lines (45 loc) · 1.24 KB
/
initpop.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
function [pop, posup, posup2] = initpop(pop_size,wup, wdown, k)
rng(k, 'twister');
[rows, cols] = size(wup);
[rows2, cols2] = size(wdown);
posup = zeros(12, 12);
posup2 = zeros(12, 12);
r1 = [];
r2 = [];
pop = [];
for i=1:rows-1
for j=1:12
if(wup(i,j) ~= 0 && i <= 12)
posup(i,j) = j;
elseif(wup(i,j) ~= 0 && i > 12)
posup2(i-12, j) = j;
end
end
end
for i=1:pop_size
for j=1:12
aux1 = nonzeros(posup(j, :));
aux2 = nonzeros(posup2(j, :));
if(isempty(aux1) == 0 && isempty(aux2) == 0)
rd = randi([1 length(aux2)], 1, 1);
rp = randi([1 length(aux1)], 1, 1);
r1 = [r1, aux1(rp)];
r2 = [r2, aux2(rd)];
elseif(isempty(aux1) == 0 && isempty(aux2) == 1)
rp = randi([1 length(aux1)], 1, 1);
r1 = [r1, aux1(rp)];
r2 = [r2, 0];
elseif(isempty(aux1) == 1 && isempty(aux2) == 0)
rd = randi([1 length(aux2)], 1, 1);
r2 = [r2, aux2(rd)];
r1 = [r1, 1];
else
r1 = [r1, 1];
r2 = [r2, 1];
end
end
pop = [pop; r2; r1];
r1 = [];
r2 = [];
end
end