from preprocessing import parse_file from genetic_algorithm import genetic_algorithm from memetic_algorithm import memetic_algorithm from sys import argv from time import time def execute_algorithm(choice, n, m, data): if choice == "genetic": return genetic_algorithm(n, m, data) elif choice == "memetic": return memetic_algorithm(m, data) else: print("The valid algorithm choices are 'genetic' and 'memetic'") exit(1) def show_results(solutions, time_delta): distance_sum = solutions["distance"].sum() duplicates = solutions.duplicated().any() print(solutions) print("Total distance: " + str(distance_sum)) if not duplicates: print("No duplicates found") print("Execution time: " + str(time_delta)) def usage(argv): print(f"Usage: python {argv[0]} ") print("algorithm choices:") print("genetic: genetic algorithm") print("memetic: memetic algorithm") exit(1) def main(): if len(argv) != 3: usage(argv) n, m, data = parse_file(argv[1]) start_time = time() solutions = execute_algorithm(choice=argv[2], n=n, m=m, data=data) end_time = time() show_results(solutions, time_delta=end_time - start_time) if __name__ == "__main__": main()