revrt.RouteFinder#
- class RouteFinder(zarr_fp, cost_function, route_definitions, algorithm='long_range_dijkstra', routing_layer_out_fp=None, mem_limit_bytes=250000000, log_level=None)#
Bases:
objectFind least-cost paths for one or more starting points in parallel.
- 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.route_definitions (
listoftuple) – List of tuples containing path definitions. Each path definition tuple should be of the form (int, list, list). The int input is a route ID (non-negative) that you can use to link results to input route definitions. The first list contains the starting points and the second list contains the ending points. Each point is represented as a two-tuple of non-negative integers representing the indices in the array for the pixel indicating where routing should begin/end. A unique path will be returned for each of the starting points in each of the path definition tuples (assuming a valid path exists).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.
mem_limit_bytes (
int, default250_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".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.
- Yields:
tuple– A tuple representing the route finding result for a single path definition. The first element is the route definition ID (as given in the input) and the second element is a list of path routing results. Each routing 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). This generator will yield one tuple per path definition. Order is not guaranteed, so use the route ID input to match results to inputs.
Methods
Attributes
Algorithm used for routing
JSON string representation of the cost function configuration
Cache size used during routing, in bytes
Route definitions as
(route_id, start_points, end_points)tuplesOptional output path where routing layers are persisted
Path to the Zarr file containing the cost layers
- algorithm#
Algorithm used for routing
- cost_function#
JSON string representation of the cost function configuration
- mem_limit_bytes#
Cache size used during routing, in bytes
- route_definitions#
Route definitions as
(route_id, start_points, end_points)tuples
- routing_layer_out_fp#
Optional output path where routing layers are persisted
- zarr_fp#
Path to the Zarr file containing the cost layers