Hi,
I am learning LightGraphs.jl and would like to get the list of vertices in my graph in the order they are discovered in BFS.
Is there a simple way?
In case, someone is interested, here is what I had in mind, BFS as an iterator:
using LightGraphs
struct BFS{T}
g::AbstractGraph{T}
list_visited::Vector{T}
list_next::Vector{T}
end
function Base.iterate(b::BFS, state=1)
push!(b.list_visited,state)
if length(b.list_visited) == nv(b.g)
return (state, 0)
elseif length(b.list_visited) > nv(b.g)
nothing
else
for v in outneighbors(b.g,state)
v in b.list_visited || push!(b.list_next, v)
end
v = popfirst!(b.list_next)
return (state, v)
end
end