diff --git a/src/genetic_algorithm.py b/src/genetic_algorithm.py index 9cf519c..8dbd6d4 100644 --- a/src/genetic_algorithm.py +++ b/src/genetic_algorithm.py @@ -115,6 +115,11 @@ def crossover(mode, parents, m): return position_crossover(parents, m) +def element_in_dataframe(solution, element): + duplicates = solution.query(f"point == {element}") + return not duplicates.empty + + def mutate(solution, n, probability=0.001): if random() > probability: return solution @@ -127,9 +132,10 @@ def mutate(solution, n, probability=0.001): return solution -def element_in_dataframe(solution, element): - duplicates = solution.query(f"point == {element}") - return not duplicates.empty +def tournament_selection(solution): + individuals = solution.sample(n=2) + best_index = solution["distance"].astype(float).idxmax() + return individuals.iloc[best_index] def replace_worst_element(previous, n, data):