diff --git a/src/genetic_algorithm.py b/src/genetic_algorithm.py index 9357842..68027aa 100644 --- a/src/genetic_algorithm.py +++ b/src/genetic_algorithm.py @@ -1,3 +1,4 @@ +from numpy import put, sum, append, where, zeros from numpy.random import choice, seed @@ -9,6 +10,17 @@ def get_first_random_solution(n, m): 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):