Implement furthest element computation

This commit is contained in:
coolneng 2021-03-22 17:57:25 +01:00
parent b50d549ce2
commit 8b72d3f01c
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 33 additions and 0 deletions

33
src/processing.py Normal file
View File

@ -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]} <file>")
exit(1)
def main():
if len(argv) != 2:
usage(argv)
n, m, data = parse_file(argv[1])
if __name__ == "__main__":
main()