def __init__(self, eps=1e-5, city='Amherst, Massachusetts, USA', network_type='drive', timeout=100): ''' Parameters: eps (float): epsilon value for the inverse grade calculation city (str): city of the map network_type (str): type of the map timeout (int): timeout for path finding algorithm ''' self._eps = eps # parameter for the inverse calculation self.pathFinder = PathFinder(timeout) # get map data graph for some city self.G = ox.graph_from_place(city, network_type=network_type) self.min_x = float('inf') self.max_x = -float('inf') self.min_y = float('inf') self.max_y = -float('inf') for node in self.G.nodes: nd = self.G.nodes[node] if nd['x'] > self.max_x: self.max_x = nd['x'] if nd['x'] < self.min_x: self.min_x = nd['x'] if nd['y'] > self.max_y: self.max_y = nd['y'] if nd['y'] < self.min_y: self.min_y = nd['y']
args = sys.argv[1:] try: if args: if os.path.exists(args[0]): # Starting time of the script startTime = time.time() # Intantiate a new Parser Parser = MatrixParser() # Parse the matrix from the file given matrix = Parser.getFileMatrix(args[0]) # Intantiate a new Path Finder Finder = PathFinder(matrix["rows"], matrix["columns"], matrix["content"]) # Get the longest (and steepest path) path = Finder.getLongestDescendentPath() # Execution time executionTime = time.time() - startTime print( json.dumps( {"ok": True, "result": path, "executionTime": executionTime}, ensure_ascii=False, ) ) else: raise FileNotFoundError(f"File {args[0]} does not exist")
def __init__(self): self.move_speed = 3 self.path_finder = PathFinder()