aonyx/graph/astar
Values
pub fn find_path(
graph: Graph(a, b, c),
start: a,
goal: a,
heuristic: fn(b, b) -> Float,
) -> Option(List(a))
Uses the A* algorithm to search for the shortest path from start to goal in the graph. The heuristic function is used to estimate the remaining distance from a node to the goal and must be admissive (e.g. never overestimate the distance). A heuristic function that always returns 0.0 will make this function equivalent to Dijkstra’s algorithm. If a node does not have a value to be used as a heuristic, the heuristic function is skipped and 0.0 is used. The returned list represents the path in order from the start node to the goal node, or None when no path can be found.
Notes: Since the A* algorithm is susceptible to negative cycles, negative weights are clamped to 0.0 to avoid infinite loops. None values are treated as 1.0.