Refactor fitness calculation using combinations
This commit is contained in:
parent
9a4831e31e
commit
550f0bb043
16
src/main.py
16
src/main.py
|
@ -3,6 +3,7 @@ from greedy import greedy_algorithm
|
||||||
from local_search import local_search
|
from local_search import local_search
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from time import time
|
from time import time
|
||||||
|
from itertools import combinations
|
||||||
|
|
||||||
|
|
||||||
def execute_algorithm(choice, n, m, data):
|
def execute_algorithm(choice, n, m, data):
|
||||||
|
@ -25,13 +26,14 @@ def get_row_distance(source, destination, data):
|
||||||
|
|
||||||
def get_fitness(solutions, data):
|
def get_fitness(solutions, data):
|
||||||
counter = 0
|
counter = 0
|
||||||
for i in range(len(solutions) - 1):
|
comb = combinations(solutions.index, r=2)
|
||||||
for j in range(i + 1, len(solutions)):
|
for index in list(comb):
|
||||||
counter += get_row_distance(
|
elements = solutions.loc[index, :]
|
||||||
source=solutions["point"].iloc[i],
|
counter += get_row_distance(
|
||||||
destination=solutions["point"].iloc[j],
|
source=elements["point"].head(n=1).values[0],
|
||||||
data=data,
|
destination=elements["point"].tail(n=1).values[0],
|
||||||
)
|
data=data,
|
||||||
|
)
|
||||||
return counter
|
return counter
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue