import sys import json from solution import * def read_instance_json(file_path): with open(file_path) as f: return json.load(f) def write_instance_json(solution, file_path): with open(file_path, 'w') as f: json.dump(solution, f) def print_our_solution(best_route, best_cost): print("Our route:", best_route) print("Our cost:", round(best_cost)) def print_best_solution(instance): print("Best route:", instance['GlobalBest']) print("Best cost:", instance['GlobalBestVal']) # TODO: instead of calculate_distance create incremental evaluation # TODO: look into distance calculation. It seems the matrices are inaccurate because they use only int # TODO: look for better hyperparameters # TODO: are these methods the best possible ones? instance_path = sys.argv[1] output_path = sys.argv[2] instance = read_instance_json(instance_path) best_route, best_cost = lns(instance['Matrix'], instance['Coordinates'], instance['Timeout']-1) # TODO: before submission comment out the next part print_our_solution(best_route, best_cost) print_best_solution(instance) write_instance_json(best_route, output_path) # naive_solution = [i for i in range(len(instance['Matrix']))] # write_instance_json(naive_solution, output_path) ####################################################################### # Example of the required timeout mechanism within the LNS structure: # ####################################################################### # ... # time_limit = instance['Timeout'] # start_time = time.time() # for iteration in range(9999999999): # ...logic of one search iteration... # if time.time() - start_time >= time_limit: # break # ... ####################################################################### #######################################################################