From 27df20f7d1fa18837225b521b1f304f717002b58 Mon Sep 17 00:00:00 2001 From: coolneng Date: Mon, 12 Apr 2021 11:21:24 +0200 Subject: [PATCH] Specify algorithm choice via CLI arguments --- src/processing.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/processing.py b/src/processing.py index b2065a9..ced928f 100644 --- a/src/processing.py +++ b/src/processing.py @@ -45,10 +45,20 @@ def greedy_algorithm(n, m, data): # NOTE In each step, switch to the element that gives the least amount -def local_search(): +def local_search(n, m, data): 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): distance_sum = solutions["distance"].sum() print(solutions) @@ -56,15 +66,18 @@ def show_results(solutions): def usage(argv): - print(f"Usage: python {argv[0]} ") + print(f"Usage: python {argv[0]} ") + print("algorithm choices:") + print("greedy: greedy algorithm") + print("local: local search algorithm") exit(1) def main(): - if len(argv) != 2: + if len(argv) != 3: usage(argv) 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)