Implement element evaluation

This commit is contained in:
coolneng 2021-05-17 20:42:17 +02:00
parent 74528b8c39
commit 921e094858
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 12 additions and 0 deletions

View File

@ -1,3 +1,4 @@
from numpy import put, sum, append, where, zeros
from numpy.random import choice, seed from numpy.random import choice, seed
@ -9,6 +10,17 @@ def get_first_random_solution(n, m):
return solution return solution
def evaluate_element(element, data):
fitness = []
genotype = where(element == True)
indexes = genotype[0]
distances = data.query(f"source in @indexes and destination in @indexes")
for item in indexes[:-1]:
element_df = distances.query(f"source == {item} or destination == {item}")
max_distance = element_df["distance"].astype(float).max()
fitness = append(arr=fitness, values=max_distance)
distances = distances.query(f"source != {item} and destination != {item}")
return sum(fitness)
def element_in_dataframe(solution, element): def element_in_dataframe(solution, element):