Created
August 2, 2017 20:25
-
-
Save mschauer/263d84267f21c276db44df3c13eb848f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function has_path(g::AbstractGraph, u::Integer, v::Integer; exclude_vertices::AbstractVector=Vector{eltype(g)}()) | |
T = eltype(g) | |
seen = falses(nv(g)) | |
next = Vector{T}() | |
push!(next, u) | |
excludeset = Set(exclude_vertices) | |
while !isempty(next) | |
src = shift!(next) #Get first element | |
src in excludeset && continue | |
vertexneighbors = neighbors(g, src) | |
for vertex in vertexneighbors | |
if vertex == v | |
return true | |
end | |
#If not already set, and is not found in the queue. | |
if !seen[vertex] | |
push!(next, vertex) #Push onto queue | |
seen[vertex] = true | |
end | |
end | |
end | |
return false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment