From 5f69d5a5f1803014deab2e882c675cd3cf32497d Mon Sep 17 00:00:00 2001 From: Seth Bromberger Date: Tue, 7 Jul 2015 15:36:09 -0500 Subject: [PATCH 1/6] made changes to bfs and vistors that didn't return bool --- src/bfs.jl | 4 ++-- src/graphvisit.jl | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/bfs.jl b/src/bfs.jl index 80b845bec..af2b78fbe 100644 --- a/src/bfs.jl +++ b/src/bfs.jl @@ -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) diff --git a/src/graphvisit.jl b/src/graphvisit.jl index a9f056d30..3175bfa75 100644 --- a/src/graphvisit.jl +++ b/src/graphvisit.jl @@ -52,7 +52,7 @@ end function discover_vertex!(visitor::VertexListVisitor, v::Int) push!(visitor.vertices, v) - true + return true end function visited_vertices( @@ -74,14 +74,22 @@ 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) From 9d95208ef5717710f46d71dd4af7651d7bec4c8b Mon Sep 17 00:00:00 2001 From: Iain Dunning Date: Tue, 7 Jul 2015 16:28:55 -0400 Subject: [PATCH 2/6] Fix some doc weirdness --- doc/pathing.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/pathing.md b/doc/pathing.md index 96a346819..cc7a96049 100644 --- a/doc/pathing.md +++ b/doc/pathing.md @@ -3,10 +3,10 @@ various utility functions. Where appropriate, edge distances may be passed in as matrix of real number values. The matrix should be indexed by `[src, dst]` (see [Getting Started](gettingstarted.html) for more information). ### Graph Traversal -`Graph traversal` refers to a process that traverses vertices of a graph following certain order (starting from user-input sources). This package implements three traversal schemes: -` `BreadthFirst`, -` `DepthFirst`, and -` `MaximumAdjacency`. +"Graph traversal" refers to a process that traverses vertices of a graph following certain order (starting from user-input sources). This package implements three traversal schemes: +* `BreadthFirst`, +* `DepthFirst`, and +* `MaximumAdjacency`. `bfs_tree(g)` `dfs_tree(g)` @@ -25,7 +25,7 @@ of weak connectivity. `is_weakly_connected(g)` DiGraphs only: returns true if `g` is strongly (weakly) connected. -`connected components(g)` +`connected_components(g)` Will return the [connected components](https://en.wikipedia.org/wiki/Connectivity_(graph_theory)) of an undirected graph `g` as a vector of components, each represented by a vector of vectors of vertices belonging to the component. @@ -85,8 +85,8 @@ displayed. ### Shortest-Path Algorithms #### General properties of shortest path algorithms -` The distance from a vertex to itself is always `0`. -` The distance between two vertices with no connecting edge is always `Inf`. +* The distance from a vertex to itself is always `0`. +* The distance between two vertices with no connecting edge is always `Inf`. `a_star(g, s, t[, heuristic, distmx])` From 9c19c44f27d1f923181ed1bb30d7f2042d105786 Mon Sep 17 00:00:00 2001 From: Iain Dunning Date: Tue, 7 Jul 2015 16:38:47 -0400 Subject: [PATCH 3/6] Update pathing.md --- doc/pathing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/pathing.md b/doc/pathing.md index cc7a96049..8d4d5b0fe 100644 --- a/doc/pathing.md +++ b/doc/pathing.md @@ -3,7 +3,7 @@ various utility functions. Where appropriate, edge distances may be passed in as matrix of real number values. The matrix should be indexed by `[src, dst]` (see [Getting Started](gettingstarted.html) for more information). ### Graph Traversal -"Graph traversal" refers to a process that traverses vertices of a graph following certain order (starting from user-input sources). This package implements three traversal schemes: +*Graph traversal* refers to a process that traverses vertices of a graph following certain order (starting from user-input sources). This package implements three traversal schemes: * `BreadthFirst`, * `DepthFirst`, and * `MaximumAdjacency`. From b28337b4ecb9f38b261880e399085dbeb3081f79 Mon Sep 17 00:00:00 2001 From: Seth Bromberger Date: Tue, 7 Jul 2015 15:38:10 -0500 Subject: [PATCH 4/6] Update pathing.md --- doc/pathing.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/pathing.md b/doc/pathing.md index 8d4d5b0fe..3f091f3c0 100644 --- a/doc/pathing.md +++ b/doc/pathing.md @@ -8,10 +8,10 @@ matrix of real number values. The matrix should be indexed by `[src, dst]` (see * `DepthFirst`, and * `MaximumAdjacency`. -`bfs_tree(g)` -`dfs_tree(g)` -Provides a breadth-first or depth-first traversal of the graph `g`, and returns -a directed acyclic graph of vertices in the order they were discovered. +`bfs_tree(g, s)` +`dfs_tree(g, s)` +Provides a breadth-first or depth-first traversal of the graph `g` starting with source vertex `s`, +and returns a directed acyclic graph of vertices in the order they were discovered. ### Connectivity / Bipartiteness From 4139d2b71e1cc9ed04bcaa0e8a69363110fc9ee7 Mon Sep 17 00:00:00 2001 From: Seth Bromberger Date: Tue, 7 Jul 2015 16:29:24 -0500 Subject: [PATCH 5/6] tests --- test/graphvisit.jl | 6 ++++++ test/runtests.jl | 1 + 2 files changed, 7 insertions(+) create mode 100644 test/graphvisit.jl diff --git a/test/graphvisit.jl b/test/graphvisit.jl new file mode 100644 index 000000000..0fed2a025 --- /dev/null +++ b/test/graphvisit.jl @@ -0,0 +1,6 @@ +# stub tests for coverage; disregards output. + +f = IOBuffer() + +g = HouseGraph() +@test traverse_graph_withlog(g, BreadthFirst(), [1;], f) == nothing diff --git a/test/runtests.jl b/test/runtests.jl index 02ad28422..9ec6ff896 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -52,6 +52,7 @@ tests = [ "dfs", "connectivity", "maxadjvisit", + "graphvisit", "centrality/betweenness", "centrality/closeness", "centrality/degree", From 22d4980a566920b3c0fcfbb4383e0068c80a694f Mon Sep 17 00:00:00 2001 From: Seth Bromberger Date: Tue, 7 Jul 2015 16:34:25 -0500 Subject: [PATCH 6/6] Revert "Merge branch 'master' into hotfix-1" This reverts commit dbf785610ef248a26ed5b3a95d7c5d05e447fb89, reversing changes made to 5f69d5a5f1803014deab2e882c675cd3cf32497d. more optimizations trivial --- doc/pathing.md | 22 +++++++++++----------- src/graphvisit.jl | 10 ++++++---- test/graphvisit.jl | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/doc/pathing.md b/doc/pathing.md index 3f091f3c0..96a346819 100644 --- a/doc/pathing.md +++ b/doc/pathing.md @@ -3,15 +3,15 @@ various utility functions. Where appropriate, edge distances may be passed in as matrix of real number values. The matrix should be indexed by `[src, dst]` (see [Getting Started](gettingstarted.html) for more information). ### Graph Traversal -*Graph traversal* refers to a process that traverses vertices of a graph following certain order (starting from user-input sources). This package implements three traversal schemes: -* `BreadthFirst`, -* `DepthFirst`, and -* `MaximumAdjacency`. +`Graph traversal` refers to a process that traverses vertices of a graph following certain order (starting from user-input sources). This package implements three traversal schemes: +` `BreadthFirst`, +` `DepthFirst`, and +` `MaximumAdjacency`. -`bfs_tree(g, s)` -`dfs_tree(g, s)` -Provides a breadth-first or depth-first traversal of the graph `g` starting with source vertex `s`, -and returns a directed acyclic graph of vertices in the order they were discovered. +`bfs_tree(g)` +`dfs_tree(g)` +Provides a breadth-first or depth-first traversal of the graph `g`, and returns +a directed acyclic graph of vertices in the order they were discovered. ### Connectivity / Bipartiteness @@ -25,7 +25,7 @@ of weak connectivity. `is_weakly_connected(g)` DiGraphs only: returns true if `g` is strongly (weakly) connected. -`connected_components(g)` +`connected components(g)` Will return the [connected components](https://en.wikipedia.org/wiki/Connectivity_(graph_theory)) of an undirected graph `g` as a vector of components, each represented by a vector of vectors of vertices belonging to the component. @@ -85,8 +85,8 @@ displayed. ### Shortest-Path Algorithms #### General properties of shortest path algorithms -* The distance from a vertex to itself is always `0`. -* The distance between two vertices with no connecting edge is always `Inf`. +` The distance from a vertex to itself is always `0`. +` The distance between two vertices with no connecting edge is always `Inf`. `a_star(g, s, t[, heuristic, distmx])` diff --git a/src/graphvisit.jl b/src/graphvisit.jl index 3175bfa75..0c806f4e1 100644 --- a/src/graphvisit.jl +++ b/src/graphvisit.jl @@ -96,10 +96,12 @@ 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) diff --git a/test/graphvisit.jl b/test/graphvisit.jl index 0fed2a025..90b608bfd 100644 --- a/test/graphvisit.jl +++ b/test/graphvisit.jl @@ -4,3 +4,17 @@ 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