From da234aae96e15ea2cbfbfb93cafdfc4511420edf Mon Sep 17 00:00:00 2001 From: coolneng Date: Wed, 14 Apr 2021 18:34:52 +0200 Subject: [PATCH] Implement best first local search algorithm --- src/processing.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/processing.py b/src/processing.py index 0feb2bd..664f945 100644 --- a/src/processing.py +++ b/src/processing.py @@ -72,6 +72,17 @@ def local_search(n, m, data): for _ in range(m): pass return solutions +def get_random_solution(previous, data): + solution = previous.copy() + worst_index = previous["distance"].astype(float).idxmin() + 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 + + def execute_algorithm(choice, n, m, data):