|
2 | 2 | struct DijkstraState{T, U} |
3 | 3 |
|
4 | 4 | An [`AbstractPathState`](@ref) designed for Dijkstra shortest-paths calculations. |
| 5 | +
|
| 6 | +# Fields |
| 7 | +
|
| 8 | +- `parents::Vector{U}` |
| 9 | +- `dists::Vector{T}` |
| 10 | +- `predecessors::Vector{Vector{U}}`: a vector, indexed by vertex, of all the predecessors discovered during shortest-path calculations. This keeps track of all parents when there are multiple shortest paths available from the source. |
| 11 | +- `pathcounts::Vector{Float64}`: a vector, indexed by vertex, of the number of shortest paths from the source to that vertex. The path count of a source vertex is always `1.0`. The path count of an unreached vertex is always `0.0`. |
| 12 | +- `closest_vertices::Vector{U}`: a vector of all vertices in the graph ordered from closest to farthest. |
5 | 13 | """ |
6 | 14 | struct DijkstraState{T<:Real,U<:Integer} <: AbstractPathState |
7 | 15 | parents::Vector{U} |
|
16 | 24 |
|
17 | 25 | Perform [Dijkstra's algorithm](http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) |
18 | 26 | on a graph, computing shortest distances between `srcs` and all other vertices. |
19 | | -Return a [`Graphs.DijkstraState`](@ref) that contains various traversal information. |
| 27 | +Return a [`Graphs.DijkstraState`](@ref) that contains various traversal information (try querying `state.parents` or `state.dists`). |
20 | 28 |
|
21 | 29 |
|
22 | 30 | ### Optional Arguments |
23 | | -* `allpaths=false`: If true, |
24 | | -
|
25 | | -`state.predecessors` holds a vector, indexed by vertex, |
26 | | -of all the predecessors discovered during shortest-path calculations. |
27 | | -This keeps track of all parents when there are multiple shortest paths available from the source. |
28 | | -
|
29 | | -`state.pathcounts` holds a vector, indexed by vertex, of the number of shortest paths from the source to that vertex. |
30 | | -The path count of a source vertex is always `1.0`. The path count of an unreached vertex is always `0.0`. |
31 | | -
|
32 | | -* `trackvertices=false`: If true, |
33 | | -
|
34 | | -`state.closest_vertices` holds a vector of all vertices in the graph ordered from closest to farthest. |
35 | | -
|
| 31 | +* `allpaths=false`: If true, `state.pathcounts` holds a vector, indexed by vertex, of the number of shortest paths from the source to that vertex. The path count of a source vertex is always `1.0`. The path count of an unreached vertex is always `0.0`. |
| 32 | +* `trackvertices=false`: If true, `state.closest_vertices` holds a vector of all vertices in the graph ordered from closest to farthest. |
36 | 33 | * `maxdist` (default: `typemax(T)`) specifies the maximum path distance beyond which all path distances are assumed to be infinite (that is, they do not exist). |
37 | 34 |
|
38 | 35 | ### Performance |
@@ -75,9 +72,8 @@ function dijkstra_shortest_paths( |
75 | 72 | distmx::AbstractMatrix{T}=weights(g); |
76 | 73 | allpaths=false, |
77 | 74 | trackvertices=false, |
78 | | - maxdist=typemax(T) |
79 | | - ) where T <: Real where U <: Integer |
80 | | - |
| 75 | + maxdist=typemax(T), |
| 76 | +) where {T<:Real} where {U<:Integer} |
81 | 77 | nvg = nv(g) |
82 | 78 | dists = fill(typemax(T), nvg) |
83 | 79 | parents = zeros(U, nvg) |
@@ -163,7 +159,7 @@ function dijkstra_shortest_paths( |
163 | 159 | distmx::AbstractMatrix=weights(g); |
164 | 160 | allpaths=false, |
165 | 161 | trackvertices=false, |
166 | | - maxdist=typemax(eltype(distmx)) |
| 162 | + maxdist=typemax(eltype(distmx)), |
167 | 163 | ) |
168 | 164 | return dijkstra_shortest_paths( |
169 | 165 | g, [src;], distmx; allpaths=allpaths, trackvertices=trackvertices, maxdist=maxdist |
|
0 commit comments