shortest_path

Function shortest_path 

Source
pub fn shortest_path<N, E, Ix>(
    graph: &Graph<N, E, Ix>,
    source: &N,
    target: &N,
) -> Result<Option<Path<N, E>>>
where N: Node + Debug, E: EdgeWeight + Zero + One + Add<Output = E> + PartialOrd + Copy + Debug + Default, Ix: IndexType,
👎Deprecated since 0.1.0-beta.2: Use dijkstra_path for future compatibility. This function will return PathResult in v1.0
Expand description

Finds the shortest path between source and target nodes using Dijkstra’s algorithm

§Arguments

  • graph - The graph to search in
  • source - The source node
  • target - The target node

§Returns

  • Ok(Some(Path)) - If a path exists
  • Ok(None) - If no path exists
  • Err(GraphError) - If the source or target node is not in the graph

§Time Complexity

O((V + E) log V) where V is the number of vertices and E is the number of edges. Using a binary heap (min-heap) priority queue implementation.

§Space Complexity

O(V) for the distance array and predecessor tracking.

§Deprecation Notice

This function will be updated in v1.0 to return a standardized PathResult type that provides more detailed information about the path and search process. The current API will remain available but deprecated.