Implement best first local search algorithm

This commit is contained in:
coolneng 2021-04-14 18:34:52 +02:00
parent b3211ff682
commit da234aae96
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 11 additions and 0 deletions

View File

@ -72,6 +72,17 @@ def local_search(n, m, data):
for _ in range(m): for _ in range(m):
pass pass
return solutions 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): def execute_algorithm(choice, n, m, data):