From 8b72d3f01cf976650bc1018ab67c982e13b0f875 Mon Sep 17 00:00:00 2001 From: coolneng Date: Mon, 22 Mar 2021 17:57:25 +0100 Subject: [PATCH] Implement furthest element computation --- src/processing.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/processing.py diff --git a/src/processing.py b/src/processing.py new file mode 100644 index 0000000..4336bf1 --- /dev/null +++ b/src/processing.py @@ -0,0 +1,33 @@ +from preprocessing import parse_file +from pandas import DataFrame +from secrets import randbelow +from sys import argv + + +def get_furthest_element(element, data): + element_df = data.query(f"source == {element} or destination == {element}") + furthest_index = element_df["distance"].idxmax() + furthest_row = data.iloc[furthest_index] + return furthest_row + + +def greedy_algorithm(n, m, data): + solutions = DataFrame(columns=["source", "destination", "distance"]) + for _ in range(m): + centroid = get_furthest_element(element=randbelow(n), data=data) + solutions = solutions.append(centroid) + + +def usage(argv): + print(f"Usage: python {argv[0]} ") + exit(1) + + +def main(): + if len(argv) != 2: + usage(argv) + n, m, data = parse_file(argv[1]) + + +if __name__ == "__main__": + main()