Remove duplicates in local search
This commit is contained in:
parent
028db4ba91
commit
5e6a6d00e9
|
@ -28,12 +28,20 @@ def get_random_solution(previous, data):
|
||||||
return solution
|
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):
|
def explore_neighbourhood(element, data, max_iterations=100000):
|
||||||
neighbourhood = []
|
neighbourhood = []
|
||||||
neighbourhood.append(element)
|
neighbourhood.append(element)
|
||||||
for _ in range(max_iterations):
|
for _ in range(max_iterations):
|
||||||
previous_solution = neighbourhood[-1]
|
previous_solution = neighbourhood[-1]
|
||||||
neighbour = get_random_solution(previous=previous_solution, data=data)
|
neighbour = get_random_solution(previous=previous_solution, data=data)
|
||||||
|
data = remove_duplicates(element=neighbour, data=data)
|
||||||
if neighbour.equals(previous_solution):
|
if neighbour.equals(previous_solution):
|
||||||
break
|
break
|
||||||
neighbourhood.append(neighbour)
|
neighbourhood.append(neighbour)
|
||||||
|
|
Loading…
Reference in New Issue