-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrankability_fitness3.m
28 lines (23 loc) · 1.03 KB
/
rankability_fitness3.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
function [y,fitness,perms,unique_rows] = rankability_fitness3(perm_real_P,maxP,D)
perm_real_P_reshaped = reshape(perm_real_P,maxP,size(D,1));
fitness = zeros(1,maxP);
perms = zeros(size(perm_real_P_reshaped));
for i = 1:maxP
perm_real = perm_real_P_reshaped(i,:);
[vs,perm] = sort(perm_real);
perms(i,:) = perm;
n=size(D,1); % n=number of items to be ranked, e.g., number of teams
fitness(i)=nnz(tril(D(perm,perm)))+(n*(n-1)/2 - nnz(triu(D(perm,perm))));
end
% obj1 is simply the minimum fitness
obj1 = min(fitness);
% obj2 is how many unique ways we've found to accomplish this task
unique_rows = unique(perms(fitness == obj1,:),'rows');
obj2 = -size(unique_rows,1);
% obj3 is the tau ranking score between all pairs of solutions
tau_scores = triu(corr(perms',perms','type','Kendall'));
obj3 = sum(sum(abs(tau_scores)));
% probably are going to want to dynamically increase the number of
% solutions, P
y = [obj1,obj2,obj3];
end