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

made changes to bfs and vistors that didn't return bool #84

Merged
merged 6 commits into from
Jul 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/bfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ function traverse_graph(
visitor::SimpleGraphVisitor;
colormap = zeros(Int, nv(graph)))

que = Queue(Int)
que = @compat Vector{Int}()

for s in sources
colormap[s] = 1
if !discover_vertex!(visitor, s)
return
end
DataStructures.enqueue!(que, s)
push!(que, s)
end

breadth_first_visit_impl!(graph, que, colormap, visitor)
Expand Down
26 changes: 18 additions & 8 deletions src/graphvisit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ end

function discover_vertex!(visitor::VertexListVisitor, v::Int)
push!(visitor.vertices, v)
true
return true
end

function visited_vertices(
Expand All @@ -74,24 +74,34 @@ end

function discover_vertex!(vis::LogGraphVisitor, v::Int)
println(vis.io, "discover vertex: $v")
true
return true
end

open_vertex!(vis::LogGraphVisitor, v::Int) = println(vis.io, "open vertex: $v")
close_vertex!(vis::LogGraphVisitor, v::Int) = println(vis.io, "close vertex: $v")
function open_vertex!(vis::LogGraphVisitor, v::Int)
println(vis.io, "open vertex: $v")
return true
end

function close_vertex!(vis::LogGraphVisitor, v::Int)
println(vis.io, "close vertex: $v")
return true
end

function examine_neighbor!(vis::LogGraphVisitor, u::Int, v::Int, vcolor::Int, ecolor::Int)
println(vis.io, "examine neighbor: $u -> $v (vertexcolor = $vcolor, edgecolor= $ecolor)")
return true
end

function examine_edge!(vis::LogGraphVisitor, e::Edge, color::Int)
println(vis.io, "examine edge: $e")
end

function traverse_graph_withlog(g::SimpleGraph, alg::SimpleGraphVisitAlgorithm, sources::Vector{Int}, io::IO)
function traverse_graph_withlog(
g::SimpleGraph,
alg::SimpleGraphVisitAlgorithm,
sources,
io::IO = STDOUT
)
visitor = LogGraphVisitor(io)
traverse_graph(g, alg, sources, visitor)
end

traverse_graph_withlog(g::SimpleGraph, alg::SimpleGraphVisitAlgorithm,
sources::Vector{Int}) = traverse_graph_withlog(g, alg, sources, STDOUT)
20 changes: 20 additions & 0 deletions test/graphvisit.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# stub tests for coverage; disregards output.

f = IOBuffer()

g = HouseGraph()
@test traverse_graph_withlog(g, BreadthFirst(), [1;], f) == nothing

@test visited_vertices(g, BreadthFirst(), [1;]) == [1, 2, 3, 4, 5]


function trivialgraphvisit(
g::SimpleGraph,
alg::LightGraphs.SimpleGraphVisitAlgorithm,
sources
)
visitor = TrivialGraphVisitor()
traverse_graph(g, alg, sources, visitor)
end

@test trivialgraphvisit(g, BreadthFirst(), 1) == nothing
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ tests = [
"dfs",
"connectivity",
"maxadjvisit",
"graphvisit",
"centrality/betweenness",
"centrality/closeness",
"centrality/degree",
Expand Down