diff --git a/src/genetic_algorithm.py b/src/genetic_algorithm.py index 68027aa..5c96427 100644 --- a/src/genetic_algorithm.py +++ b/src/genetic_algorithm.py @@ -10,12 +10,16 @@ def get_first_random_solution(n, m): return solution +def get_genotype(element): + genotype = where(element == True) + return genotype[0] + + 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]: + genotype = get_genotype(element) + distances = data.query(f"source in @genotype and destination in @genotype") + for item in genotype[:-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)