Skip to content

Commit

Permalink
Removed redundant functions in dfs.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Oct 26, 2023
1 parent b34511a commit fbc3b90
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions src/traversals/dfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,3 @@ end
function dfs_parents(graph::AbstractNamedGraph, vertex; kwargs...)
return _dfs_parents(graph, vertex; kwargs...)
end

#Given a graph, split it into its connected components, construct a spanning tree over each of them
# and take the union (adding in edges between the trees to recover a connected graph)
function spanning_forest(
g::AbstractNamedGraph;
tree_constructor=g ->
undirected_graph(bfs_tree(g, first(keys(sort(eccentricities(g); rev=true))))),
)
component_vertices = connected_components(g)
return reduce(union, (tree_constructor(g[vs]) for vs in component_vertices))
end

#Given an undirected graph g with vertex set V, build a set of forests (each with vertex set V) which covers all edges in g
# (see https://en.wikipedia.org/wiki/Arboricity) We do not find the minimum but our tests show this algorithm performs well
function build_forest_cover(
g::AbstractNamedGraph;
tree_constructor=g ->
undirected_graph(bfs_tree(g, first(keys(sort(eccentricities(g); rev=true))))),
)
@assert !NamedGraphs.is_directed(g)
edges_collected = edgetype(g)[]
remaining_edges = edges(g)
forests = NamedGraph[]
while !isempty(remaining_edges)
g_reduced = rem_edges(g, edges_collected)
g_reduced_spanning_forest = spanning_forest(g_reduced; tree_constructor)
push!(edges_collected, edges(g_reduced_spanning_forest)...)
push!(forests, g_reduced_spanning_forest)
setdiff!(remaining_edges, edges(g_reduced_spanning_forest))
end

return forests
end

0 comments on commit fbc3b90

Please sign in to comment.