MH-P1/src/processing.py

34 lines
824 B
Python
Raw Normal View History

2021-03-22 17:57:25 +01:00
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()