if len(sys.argv) not in [2, 3]: print("Usage: gps.py numCities|atlasFile [debugLevel].") sys.exit(1) if len(sys.argv) > 2: if sys.argv[2] not in ['DEBUG', 'INFO', 'WARNING', 'ERROR']: print('Debug level must be one of: DEBUG, INFO, WARNING, ERROR.') sys.exit(2) logging.getLogger().setLevel(sys.argv[2]) else: logging.getLogger().setLevel('INFO') try: num_cities = int(sys.argv[1]) logging.info( 'Building random atlas with {} cities...'.format(num_cities)) usa = Atlas(num_cities) logging.info('...built.') except: logging.info('Loading atlas from file {}...'.format(sys.argv[1])) usa = Atlas.from_filename(sys.argv[1]) logging.info('...loaded.') path, cost = find_best_path(usa) print('Best path from {} to {} costs {}: {}.'.format( 0, usa.get_num_cities() - 1, cost, path)) print('You expanded {} nodes: {}'.format(len(usa._nodes_expanded), usa._nodes_expanded))