-
Notifications
You must be signed in to change notification settings - Fork 32
/
Sort_Q.m
43 lines (40 loc) · 1.37 KB
/
Sort_Q.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
function [chromosome] = Sort_Q(chromosome,whole_size,signal)
% sort the chromosomes by modularity:
% signal = 1£¬sort chromosomes by the modularity value calculated from the adjacent matrix;
% signal = 2£¬sort chromosomes by the modularity values calculated from the chromosome vector
if signal == 1
for i = 1:whole_size
k = i;
for j = i + 1:whole_size
if chromosome(j).fitness_1(1) > chromosome(k).fitness_1(1)
k = j;
end
end
if k ~= i
temp = chromosome(i);
chromosome(i) = chromosome(k);
chromosome(k) = temp;
end
end
end
if signal == 2
for i = 1:whole_size
k = i;
for j = i + 1:whole_size
if chromosome(j).fitness_2 > chromosome(k).fitness_2
k = j;
end
% compare the modularity values calculated from the adjacent matrix
% when the modularity values calculated from the chromosome vector are the same
if chromosome(j).fitness_2(1) == chromosome(k).fitness_2(1) && chromosome(j).fitness_1(1) > chromosome(k).fitness_1(1)
k = j;
end
end
if k ~= i
temp = chromosome(i);
chromosome(i) = chromosome(k);
chromosome(k) = temp;
end
end
end
end