Remove duplicates in local search

This commit is contained in:
coolneng 2021-04-16 20:07:31 +02:00
parent 028db4ba91
commit 5e6a6d00e9
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 8 additions and 0 deletions

View File

@ -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)