From 33a9cf323a90dcf99a6ac1a9287478feec8c1bff Mon Sep 17 00:00:00 2001 From: coolneng Date: Wed, 14 Apr 2021 19:25:25 +0200 Subject: [PATCH] Check if the random candidate is a duplicate --- src/processing.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/processing.py b/src/processing.py index 664f945..f682e08 100644 --- a/src/processing.py +++ b/src/processing.py @@ -75,12 +75,14 @@ def local_search(n, m, data): def get_random_solution(previous, data): solution = previous.copy() worst_index = previous["distance"].astype(float).idxmin() + worst_element = previous["distance"].loc[worst_index] random_candidate = data.loc[randint(low=0, high=len(data.index))] - while ( - solution.loc[worst_index, "distance"] <= previous.loc[worst_index, "distance"] - ): - solution.loc[worst_index] = random_candidate - return solution + while solution["distance"].loc[worst_index] <= worst_element: + if random_candidate["distance"] not in solution["distance"].values: + solution.loc[worst_index] = random_candidate + else: + return solution, True + return solution, False