Skip to content

Commit

Permalink
Add section on utility functions for paths (#409)
Browse files Browse the repository at this point in the history
Give short descriptions of utility functions (as mentioned in the first paragraph) that complement the main shortest path algorithms.
  • Loading branch information
jd-foster authored Nov 21, 2024
1 parent 24539fd commit 2957506
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions docs/src/first_steps/paths_traversal.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ The following properties always hold for shortest path algorithms implemented he
- The distance from a vertex to itself is always `0`.
- The distance between two vertices with no connecting edge is always `Inf` or `typemax(eltype(distmx))`.

The [`dijkstra_shortest_paths`](@ref), [`desopo_pape_shortest_paths`](@ref), [`floyd_warshall_shortest_paths`](@ref), [`bellman_ford_shortest_paths`](@ref), and [`yen_k_shortest_paths`](@ref) functions return path states (subtypes of `Graphs.AbstractPathState`) that contain various information about the graph learned during traversal.
The [`dijkstra_shortest_paths`](@ref), [`desopo_pape_shortest_paths`](@ref), [`floyd_warshall_shortest_paths`](@ref), [`bellman_ford_shortest_paths`](@ref), and [`yen_k_shortest_paths`](@ref) functions return _path states_ (subtypes of `Graphs.AbstractPathState`) that contain various information about the graph learned during traversal.

The corresponding state types (with the exception of `YenState`) have the following common fields:

- `state.dists` holds a vector with the distances computed, indexed by source vertex.
- `state.parents` holds a vector of parents of each vertex on the shortest paths (the parent of a source vertex is always `0`). `YenState` substitutes `.paths` for `.parents`.

In addition, with the appropriate optional arguments, [`dijkstra_shortest_paths`](@ref) will return information on all possible shortest paths available from the source.
In addition, with the appropriate optional arguments, [`dijkstra_shortest_paths`](@ref) will return information on all possible shortest paths available from the source.

## Utility functions

- Once a path state is found using a shortest path algorithm, some or all of the paths can be obtained using [`enumerate_paths`](@ref).
- A longest path within a directed acyclic graph can be found with [`dag_longest_path`](@ref).
- In the case of a graph with some edges having negative weights, the existence of a cycle whose edges sum to a negative value can be detected with [`has_negative_edge_cycle_spfa`](@ref).

0 comments on commit 2957506

Please sign in to comment.