-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfitness.m
54 lines (40 loc) · 770 Bytes
/
fitness.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
function y = fitness(A,ind)
nodes = length(ind);
com= max(ind);
individual = -1*ones(nodes, nodes-1);
individual(:,1:com)=0;
for i=1:nodes
individual(i,ind(1,i))=1;
end
Q = 0;
edges = 0;
for i = 1:nodes
for j = 1:nodes
if(A(i,j)==1)
edges = edges+1 ;
end
end
end
edges = sum(sum(A))/2;
for i = 1:com
vert = zeros(1,nodes);
for j =1:nodes
vert(j) = -1;
end
ind = 1;
for j = 1:nodes
if(individual(j,i) == 1)
vert(ind) = j;
ind = ind + 1;
end
end
ind = ind -1;
for j = 1:ind
for k =j+1:ind
Q = Q + (A(vert(j),vert(k)) - (del(A,vert(j))*del(A,vert(k))/(2*edges)));
end
end
end
Q = Q /(edges);
y = Q;
end