forked from sefaaras/2024-mso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfitnessDistanceBalance.m
40 lines (28 loc) · 1.05 KB
/
fitnessDistanceBalance.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
function index = fitnessDistanceBalance( population, fitness )
[~, bestIndex] = min(fitness);
best = population(bestIndex, :);
[populationSize, dimension] = size(population);
distances = zeros(1, populationSize);
normFitness = zeros(1, populationSize);
normDistances = zeros(1, populationSize);
divDistances = zeros(1, populationSize);
if min(fitness) == max(fitness)
index = randi(populationSize);
else
for i = 1 : populationSize
value = 0;
for j = 1 : dimension
value = value + abs(best(j) - population(i, j));
end
distances(i) = value;
end
minFitness = min(fitness); maxMinFitness = max(fitness) - minFitness;
minDistance = min(distances); maxMinDistance = max(distances) - minDistance;
for i = 1 : populationSize
normFitness(i) = 1 - ((fitness(i) - minFitness) / maxMinFitness);
normDistances(i) = (distances(i) - minDistance) / maxMinDistance;
divDistances(i) = normFitness(i) + normDistances(i);
end
[~, index] = max(divDistances);
end
end