Check if the random candidate is a duplicate
This commit is contained in:
parent
da234aae96
commit
33a9cf323a
|
@ -75,12 +75,14 @@ def local_search(n, m, data):
|
||||||
def get_random_solution(previous, data):
|
def get_random_solution(previous, data):
|
||||||
solution = previous.copy()
|
solution = previous.copy()
|
||||||
worst_index = previous["distance"].astype(float).idxmin()
|
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))]
|
random_candidate = data.loc[randint(low=0, high=len(data.index))]
|
||||||
while (
|
while solution["distance"].loc[worst_index] <= worst_element:
|
||||||
solution.loc[worst_index, "distance"] <= previous.loc[worst_index, "distance"]
|
if random_candidate["distance"] not in solution["distance"].values:
|
||||||
):
|
solution.loc[worst_index] = random_candidate
|
||||||
solution.loc[worst_index] = random_candidate
|
else:
|
||||||
return solution
|
return solution, True
|
||||||
|
return solution, False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue