Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
fix for #1405
Browse files Browse the repository at this point in the history
  • Loading branch information
sbromberger committed Apr 23, 2020
1 parent a63d2f7 commit a821600
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/shortestpaths/dijkstra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct DijkstraState{T <: Real,U <: Integer} <: AbstractPathState
parents::Vector{U}
dists::Vector{T}
predecessors::Vector{Vector{U}}
pathcounts::Vector{UInt64}
pathcounts::Vector{Float64}
closest_vertices::Vector{U}
end

Expand Down Expand Up @@ -68,15 +68,15 @@ function dijkstra_shortest_paths(g::AbstractGraph,
parents = zeros(U, nvg)
visited = zeros(Bool, nvg)

pathcounts = zeros(UInt64, nvg)
pathcounts = zeros(nvg)
preds = fill(Vector{U}(), nvg)
H = PriorityQueue{U,T}()
# fill creates only one array.

for src in srcs
dists[src] = zero(T)
visited[src] = true
pathcounts[src] = 1
pathcounts[src] = one(Float64)
H[src] = zero(T)
end

Expand Down Expand Up @@ -132,7 +132,7 @@ function dijkstra_shortest_paths(g::AbstractGraph,
end

for src in srcs
pathcounts[src] = 1
pathcounts[src] = one(Float64)
parents[src] = 0
empty!(preds[src])
end
Expand Down
4 changes: 4 additions & 0 deletions test/centrality/betweenness.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@
@test isapprox(betweenness_centrality(g, vertices(g), distmx2; normalize=true), [0.0,0.5,0.0])
@test isapprox(betweenness_centrality(g, vertices(g), distmx2; normalize=true, endpoints=true), [2.0,2.5,2.0])
end
# test #1405 / #1406
g = grid([50, 50])
z = betweenness_centrality(g, normalize=false)
@test maximum(z) < nv(g) * (nv(g)-1)
end
4 changes: 2 additions & 2 deletions test/shortestpaths/dijkstra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@
add_edge!(G, 4, 5)
for g in testgraphs(G)
ds = @inferred(dijkstra_shortest_paths(g, 1, m; allpaths=true))
@test ds.pathcounts == [1, 1, 1, 1, 2]
@test ds.pathcounts == [1.0, 1.0, 1.0, 1.0, 2.0]
@test ds.predecessors == [[], [1], [1], [3], [3, 4]]
@test ds.predecessors == [[], [1], [1], [3], [3, 4]]

dm = @inferred(dijkstra_shortest_paths(g, 1; allpaths=true, trackvertices=true))
@test dm.pathcounts == [1, 1, 1, 1, 2]
@test dm.pathcounts == [1.0, 1.0, 1.0, 1.0, 2.0]
@test dm.predecessors == [[], [1], [1], [3], [2, 3]]
@test dm.closest_vertices == [1, 2, 3, 5, 4]
end
Expand Down

0 comments on commit a821600

Please sign in to comment.