shortest_path_generic_grid

Function shortest_path_generic_grid 

Source
pub fn shortest_path_generic_grid<T: AStarGridNode, P, G, F, O>(
    start: &[T],
    goal_fn: &P,
    cost_fn: G,
    heuristic_fn: F,
    max_ops: u32,
    max_cost: O,
    initial_cost: O,
) -> AStarSearchResults<T, O>
where P: Fn(T) -> bool, G: Fn(T, T) -> Option<O>, F: Fn(T) -> O, O: AStarCost,
Expand description

Highly-generic implementation of A* search algorithm on a grid.

Allows multiple starting nodes, a generic goal function, generic cost and heuristic functions, control over the maximum operations performed while searching, and the maximum travel cost the final path can have.

Generally, you should not need to use this directly; use one of the convenience functions instead: shortest_path_roomxy_single_goal and shortest_path_roomxy_multiple_goals

Parameters:

  • start: A slice of the starting nodes for the search
  • goal_fn: A predicate function that takes a node and returns true if the node is a goal node
  • cost_fn: A function that takes in the current node and a neighbor node and returns the cost of moving to that neighbor node, or None if the transition is invalid
  • heuristic_fn: A function that takes a node and returns the estimated cost of moving to the goal node from that node
  • max_ops: The maximum number of expand operations to perform before stopping search
  • max_cost: The maximum cost to allow for the final path before stopping search
  • initial_cost: The initial cost to start the search with

Note: This function assumes that the heuristic function is consistent, and optimizes accordingly. If your heuristic function is admissible but not consistent, then you risk getting suboptimal paths, just like if your heuristic function is not admissible.