Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

two sided dijkstra #268

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
removed spaces, Int64[]->Int[]
  • Loading branch information
Alexandre Schulz committed Jul 3, 2023
commit 2abd6b79a285f4169d0a63b9f7addce9955dd511
19 changes: 5 additions & 14 deletions src/shortestpaths/dijkstra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,29 +223,20 @@ function bidijkstra_shortest_path(
distmx::AbstractMatrix{T}=weights(g)
) where {T<:Real} where {U<:Integer}
if src == dst
return Int64[]
return Int[]
end
# keep weight of the best seen path and the midpoint vertex
mu, mid_v = typemax(T), -1
gdalle marked this conversation as resolved.
Show resolved Hide resolved

nvg = nv(g)
dists_f, dists_b= fill(typemax(T), nvg), fill(typemax(T), nvg)

parents_f, parents_b= zeros(U, nvg), zeros(U, nvg)

visited_f, visited_b = zeros(Bool, nvg),zeros(Bool, nvg)

preds_f, preds_b = fill(Vector{U}(), nvg), fill(Vector{U}(), nvg)

Qf, Qb = PriorityQueue{U,T}(), PriorityQueue{U,T}()

dists_f[src] = zero(T)
visited_f[src] = true
Qf[src] = zero(T)

dists_b[dst] = zero(T)
visited_b[dst] = true
Qb[dst] = zero(T)
dists_f[src], dists_b[dst]= zero(T), zero(T)
visited_f[src], visited_b[dst]= true, true
Qf[src], Qb[dst] = zero(T), zero(T)

while !isempty(Qf) && !isempty(Qb)
uf, ub = dequeue!(Qf), dequeue!(Qb)
Expand Down Expand Up @@ -273,7 +264,7 @@ function bidijkstra_shortest_path(
end
if mid_v == -1
# no path exists between source and destination
return Int64[]
return Int[]
end
ds_f = DijkstraState{T,U}(parents_f, dists_f, preds_f, zeros(nvg), Vector{U}())
ds_b = DijkstraState{T,U}(parents_b, dists_b, preds_b, zeros(nvg), Vector{U}())
Expand Down
Loading