Refactor genotype obtention into a function

This commit is contained in:
coolneng 2021-05-17 20:50:26 +02:00
parent 921e094858
commit 2e12296f2c
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 8 additions and 4 deletions

View File

@ -10,12 +10,16 @@ def get_first_random_solution(n, m):
return solution return solution
def get_genotype(element):
genotype = where(element == True)
return genotype[0]
def evaluate_element(element, data): def evaluate_element(element, data):
fitness = [] fitness = []
genotype = where(element == True) genotype = get_genotype(element)
indexes = genotype[0] distances = data.query(f"source in @genotype and destination in @genotype")
distances = data.query(f"source in @indexes and destination in @indexes") for item in genotype[:-1]:
for item in indexes[:-1]:
element_df = distances.query(f"source == {item} or destination == {item}") element_df = distances.query(f"source == {item} or destination == {item}")
max_distance = element_df["distance"].astype(float).max() max_distance = element_df["distance"].astype(float).max()
fitness = append(arr=fitness, values=max_distance) fitness = append(arr=fitness, values=max_distance)