revrt.find_paths#

find_paths(zarr_fp, cost_function, start, end, algorithm='long_range_dijkstra', routing_layer_out_fp=None, mem_limit_bytes=250000000, log_level=None)#

Find least-cost paths for one or more starting points.

This function determined the least cost path for one or more starting points to one or more ending points. A unique path is returned for every starting point, but each route terminates when any of the ending points are found. To ensure that a path is found to every end point, call this function N times if you have N end points and pass a single end point each time.

Parameters:
  • zarr_fp (path-like) – Path to zarr file containing cost layers.

  • cost_function (str) – JSON string representation of the cost function. The following keys are allowed in the cost function: “cost_layers”, “friction_layers”, “barrier_layers”, and “ignore_invalid_costs”. See the documentation of the cost function for details on each of these inputs.

  • start (list of tuple) – List of two-tuples containing non-negative integers representing the indices in the array for the pixel from which routing should begin. A unique path will be returned for each of the starting points.

  • end (list of tuple) – List of two-tuples containing non-negative integers representing the indices in the array for the any allowed final pixel. When the algorithm reaches any of these points, the routing is terminated and the final path + cost is returned.

  • routing_layer_out_fp (path-like, optional) – Optional path to a cost zarr file that will be used to store the routing cost layers. If not given, the routing layers will be kept in a temporary directory and deleted after the routing is done. By default, None.

  • log_level (int, optional) – Logging level for Rust tracing emitted to stderr. Roughly follows the Python logging module levels, where 0 = TRACE, 10 = DEBUG, 20 = INFO, 30 = WARN, and 40 = ERROR. If None is given, no logging is set up. By default, None.

  • mem_limit_bytes (int, default 250_000_000) – Overall memory limit to use for routing computations, in bytes. By default, 250,000,000 (250MB).

  • algorithm (str, default "long_range_dijkstra") – Routing algorithm implementation to use. Supported values are "astar", "long_range_astar", "long_range_dijkstra", "bidirectional_long_range_dijkstra", and "dijkstra". "astar" and "dijkstra" are faster in-memory implementations but do not respect the mem_limit_bytes input. Prefer a long-range option unless you know for a fact that your route computations will not need much memory and speed is very important to you. By default, "long_range_dijkstra".

Returns:

list of tuple – List of path routing results. Each result is a tuple where the first element is a list of points that the route goes through, the second element is the final route cost, and the third element is a list containing the names of any soft barriers dropped to obtain that specific path. The result list will contain multiple tuples if the path definition had multiple starting points. An empty list will be returned if no paths were found from any of the starting points to any of the ending points (even with soft barriers dropped).