diff --git a/Project.toml b/Project.toml index c839c81b..acb648e8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NamedGraphs" uuid = "678767b0-92e7-4007-89e4-4527a8725b19" authors = ["Matthew Fishman , Joseph Tindall and contributors"] -version = "0.7.0" +version = "0.7.1" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" diff --git a/src/lib/GraphsExtensions/src/trees_and_forests.jl b/src/lib/GraphsExtensions/src/trees_and_forests.jl index 505d6383..c9c2dd00 100644 --- a/src/lib/GraphsExtensions/src/trees_and_forests.jl +++ b/src/lib/GraphsExtensions/src/trees_and_forests.jl @@ -48,15 +48,17 @@ end function forest_cover(g::AbstractGraph; spanning_tree=spanning_tree) edges_collected = edgetype(g)[] remaining_edges = edges(g) + g_reduced = rem_edges(g, edges_collected) forests = typeof(g)[] while !isempty(remaining_edges) - g_reduced = rem_edges(g, edges_collected) g_reduced_spanning_forest = spanning_forest(g_reduced; spanning_tree) - push!(edges_collected, edges(g_reduced_spanning_forest)...) - push!(forests, g_reduced_spanning_forest) - setdiff!(remaining_edges, edges(g_reduced_spanning_forest)) + edges_collected = [edges_collected; collect(edges(g_reduced_spanning_forest))] + g_reduced = rem_edges(g, edges_collected) + forests = [forests; [g_reduced_spanning_forest]] + remaining_edges = setdiff(remaining_edges, edges(g_reduced_spanning_forest)) end - return forests + # Narrow the element type if possible. + return identity.(forests) end # TODO: Define in `NamedGraphs.PartitionedGraphs`. diff --git a/src/lib/PartitionedGraphs/src/partitionsgraphview.jl b/src/lib/PartitionedGraphs/src/partitionsgraphview.jl index 20d294b4..381841b5 100644 --- a/src/lib/PartitionedGraphs/src/partitionsgraphview.jl +++ b/src/lib/PartitionedGraphs/src/partitionsgraphview.jl @@ -19,10 +19,11 @@ for f in [ :(Graphs.edges), :(Graphs.vertices), :(Graphs.rem_vertex!), + :(NamedGraphs.edgetype), + :(NamedGraphs.namedgraph_induced_subgraph), + :(NamedGraphs.ordered_vertices), :(NamedGraphs.position_graph), :(NamedGraphs.vertex_positions), - :(NamedGraphs.ordered_vertices), - :(NamedGraphs.edgetype), :(NamedGraphs.vertextype), ] @eval begin diff --git a/test/test_partitionedgraph.jl b/test/test_partitionedgraph.jl index 8f42a9c9..118883bb 100644 --- a/test/test_partitionedgraph.jl +++ b/test/test_partitionedgraph.jl @@ -23,6 +23,7 @@ using NamedGraphs.GraphsExtensions: add_vertices!, boundary_edges, default_root_vertex, + edgetype, forest_cover, is_path_graph, is_self_loop, @@ -72,6 +73,8 @@ using Test: @test, @testset @test edges(pgv) == parent.(partitionedges(pg)) @test is_tree(pgv) == true @test neighbors(pgv, 1) == [2] + @test issetequal(vertices(subgraph(pgv, [2, 3, 4])), [2, 3, 4]) + @test issetequal(edges(subgraph(pgv, [2, 3, 4])), edgetype(pgv).([2 => 3, 3 => 4])) #Same partitioning but with a dictionary constructor partition_dict = Dictionary([first(partition) for partition in partitions], partitions)