Implement furthest element computation
This commit is contained in:
parent
b50d549ce2
commit
8b72d3f01c
|
@ -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()
|
Loading…
Reference in New Issue