shortest_path_generic_graph

Function shortest_path_generic_graph 

Source
pub fn shortest_path_generic_graph<T: AStarNode, P, N, G, F, O>(
    start: &[T],
    goal_fn: &P,
    neighbors_fn: &N,
    max_ops: u32,
    max_cost: O,
    initial_cost: O,
    initial_estimate: O,
) -> AStarSearchResults<T, O>
where P: Fn(T) -> bool, N: Fn(T, O) -> Vec<(T, O, O)>, O: AStarCost,
Expand description

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

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.

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
  • neighbors_fn: A function that takes in the current node and its g score and returns its neighbors, as well as their f and g scores
  • 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; this is the g_score
  • initial_estimate: The initial estimate to start the search with; this is the f_score

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.