From 04c92add449f0dd04e612c414405fa4a6cd38595 Mon Sep 17 00:00:00 2001 From: coolneng Date: Mon, 12 Apr 2021 12:22:26 +0200 Subject: [PATCH] Cast distance to float to get the maximum value --- src/processing.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/processing.py b/src/processing.py index 3dad429..b39d140 100644 --- a/src/processing.py +++ b/src/processing.py @@ -12,7 +12,7 @@ def get_first_solution(n, data): distance_sum = distance_sum.append( {"point": element, "distance": distance}, ignore_index=True ) - furthest_index = distance_sum["distance"].idxmax() + furthest_index = distance_sum["distance"].astype(float).idxmax() furthest_row = distance_sum.iloc[furthest_index] furthest_row["distance"] = 0 return furthest_row @@ -26,13 +26,14 @@ def get_different_element(original, row): def get_furthest_element(element, data): element_df = data.query(f"source == {element} or destination == {element}") - furthest_index = element_df["distance"].idxmax() + furthest_index = element_df["distance"].astype(float).idxmax() furthest_row = data.iloc[furthest_index] furthest_point = get_different_element(original=element, row=furthest_row) furthest_element = {"point": furthest_point, "distance": furthest_row["distance"]} return furthest_element, furthest_index +# FIXME Remove duplicated elements properly def greedy_algorithm(n, m, data): solutions = DataFrame(columns=["point", "distance"]) first_solution = get_first_solution(n, data) @@ -50,7 +51,6 @@ def get_pseudorandom_solution(n, data): return data.iloc[randint(a=0, b=n)] -# NOTE In each step, switch to the element that gives the least amount def local_search(n, m, data): solutions = DataFrame(columns=["point", "distance"]) first_solution = get_pseudorandom_solution(n=n, data=data) @@ -74,6 +74,7 @@ def show_results(solutions): distance_sum = solutions["distance"].sum() print(solutions) print("Total distance: " + str(distance_sum)) + print(solutions.duplicated()) def usage(argv):