diff --git a/src/local_search.py b/src/local_search.py index 66e7ae9..8377654 100644 --- a/src/local_search.py +++ b/src/local_search.py @@ -28,12 +28,20 @@ def get_random_solution(previous, data): return solution +def remove_duplicates(element, data): + duplicate_free_df = data.query( + "(source not in @element.source) or (destination not in @element.destination)" + ) + return duplicate_free_df + + def explore_neighbourhood(element, data, max_iterations=100000): neighbourhood = [] neighbourhood.append(element) for _ in range(max_iterations): previous_solution = neighbourhood[-1] neighbour = get_random_solution(previous=previous_solution, data=data) + data = remove_duplicates(element=neighbour, data=data) if neighbour.equals(previous_solution): break neighbourhood.append(neighbour)