Compare commits

..

No commits in common. "1cf8a2696a31f428c5c70a59a70a637da543d445" and "da234aae96e15ea2cbfbfb93cafdfc4511420edf" have entirely different histories.

1 changed files with 13 additions and 21 deletions

View File

@ -65,39 +65,31 @@ 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()
worst_element = previous["distance"].loc[worst_index]
random_candidate = data.loc[randint(low=0, high=len(data.index))]
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
while (
solution.loc[worst_index, "distance"] <= previous.loc[worst_index, "distance"]
):
solution.loc[worst_index] = random_candidate
return solution
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(m, data)
return local_search(n, m, data)
else:
print("The valid algorithm choices are 'greedy' and 'local'")
exit(1)