Implement local search algorithm

This commit is contained in:
coolneng 2021-04-14 19:26:13 +02:00
parent 33a9cf323a
commit 1cf8a2696a
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 14 additions and 8 deletions

View File

@ -65,13 +65,6 @@ def get_first_random_solution(m, data):
return data.iloc[random_indexes]
def local_search(n, m, data):
solutions = DataFrame(columns=["point", "distance"])
first_solution = get_pseudorandom_solution(n=n, data=data)
solutions = solutions.append(first_solution, ignore_index=True)
for _ in range(m):
pass
return solutions
def get_random_solution(previous, data):
solution = previous.copy()
worst_index = previous["distance"].astype(float).idxmin()
@ -85,13 +78,26 @@ def get_random_solution(previous, data):
return solution, False
def explore_neighbourhood(element, data, max_iterations=100000):
neighbour = DataFrame()
for _ in range(max_iterations):
neighbour, stop_condition = get_random_solution(element, data)
if stop_condition:
break
return neighbour
def local_search(m, data):
first_solution = get_first_random_solution(m=m, data=data)
best_solution = explore_neighbourhood(element=first_solution, data=data)
return best_solution
def execute_algorithm(choice, n, m, data):
if choice == "greedy":
return greedy_algorithm(n, m, data)
elif choice == "local":
return local_search(n, m, data)
return local_search(m, data)
else:
print("The valid algorithm choices are 'greedy' and 'local'")
exit(1)