Specify algorithm choice via CLI arguments
This commit is contained in:
parent
6a3bdc44e3
commit
27df20f7d1
|
@ -45,10 +45,20 @@ def greedy_algorithm(n, m, data):
|
||||||
|
|
||||||
|
|
||||||
# NOTE In each step, switch to the element that gives the least amount
|
# NOTE In each step, switch to the element that gives the least amount
|
||||||
def local_search():
|
def local_search(n, m, data):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def execute_algorithm(choice, n, m, data):
|
||||||
|
if choice == "greedy":
|
||||||
|
return greedy_algorithm(n, m, data)
|
||||||
|
elif choice == "local":
|
||||||
|
return local_search(n, m, data)
|
||||||
|
else:
|
||||||
|
print("The valid algorithm choices are 'greedy' and 'local'")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def show_results(solutions):
|
def show_results(solutions):
|
||||||
distance_sum = solutions["distance"].sum()
|
distance_sum = solutions["distance"].sum()
|
||||||
print(solutions)
|
print(solutions)
|
||||||
|
@ -56,15 +66,18 @@ def show_results(solutions):
|
||||||
|
|
||||||
|
|
||||||
def usage(argv):
|
def usage(argv):
|
||||||
print(f"Usage: python {argv[0]} <file>")
|
print(f"Usage: python {argv[0]} <file> <algorithm choice>")
|
||||||
|
print("algorithm choices:")
|
||||||
|
print("greedy: greedy algorithm")
|
||||||
|
print("local: local search algorithm")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(argv) != 2:
|
if len(argv) != 3:
|
||||||
usage(argv)
|
usage(argv)
|
||||||
n, m, data = parse_file(argv[1])
|
n, m, data = parse_file(argv[1])
|
||||||
solutions = greedy_algorithm(n, m, data)
|
solutions = execute_algorithm(choice=argv[2], n=n, m=m, data=data)
|
||||||
show_results(solutions)
|
show_results(solutions)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue