Add correct index to the solutions list
This commit is contained in:
parent
38585aa16b
commit
dfdd142fdb
|
@ -29,10 +29,12 @@ def get_closest_element(element, data):
|
|||
return Series(data={"point": closest_point, "distance": closest_row["distance"]})
|
||||
|
||||
|
||||
def explore_solutions(solutions, data):
|
||||
def explore_solutions(solutions, data, index):
|
||||
closest_elements = solutions["point"].apply(func=get_closest_element, data=data)
|
||||
furthest_index = closest_elements["distance"].astype(float).idxmax()
|
||||
return closest_elements.iloc[furthest_index]
|
||||
solution = closest_elements.iloc[furthest_index]
|
||||
solution.name = index
|
||||
return solution
|
||||
|
||||
|
||||
def remove_duplicates(current, previous, data):
|
||||
|
@ -46,8 +48,8 @@ def greedy_algorithm(n, m, data):
|
|||
solutions = DataFrame(columns=["point", "distance"])
|
||||
first_solution = get_first_solution(n, data)
|
||||
solutions = solutions.append(first_solution, ignore_index=True)
|
||||
for _ in range(m - 1):
|
||||
element = explore_solutions(solutions, data)
|
||||
for iteration in range(m - 1):
|
||||
element = explore_solutions(solutions, data, index=iteration + 1)
|
||||
solutions = solutions.append(element)
|
||||
data = remove_duplicates(
|
||||
current=element["point"], previous=solutions["point"], data=data
|
||||
|
|
Loading…
Reference in New Issue