Skip to content

Commit 7f95bb5

Browse files
authored
Define subgraph for PartitionsGraphView (#106)
1 parent 941fe8a commit 7f95bb5

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "NamedGraphs"
22
uuid = "678767b0-92e7-4007-89e4-4527a8725b19"
33
authors = ["Matthew Fishman <mfishman@flatironinstitute.org>, Joseph Tindall <jtindall@flatironinstitute.org> and contributors"]
4-
version = "0.7.0"
4+
version = "0.7.1"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/lib/GraphsExtensions/src/trees_and_forests.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ end
4848
function forest_cover(g::AbstractGraph; spanning_tree=spanning_tree)
4949
edges_collected = edgetype(g)[]
5050
remaining_edges = edges(g)
51+
g_reduced = rem_edges(g, edges_collected)
5152
forests = typeof(g)[]
5253
while !isempty(remaining_edges)
53-
g_reduced = rem_edges(g, edges_collected)
5454
g_reduced_spanning_forest = spanning_forest(g_reduced; spanning_tree)
55-
push!(edges_collected, edges(g_reduced_spanning_forest)...)
56-
push!(forests, g_reduced_spanning_forest)
57-
setdiff!(remaining_edges, edges(g_reduced_spanning_forest))
55+
edges_collected = [edges_collected; collect(edges(g_reduced_spanning_forest))]
56+
g_reduced = rem_edges(g, edges_collected)
57+
forests = [forests; [g_reduced_spanning_forest]]
58+
remaining_edges = setdiff(remaining_edges, edges(g_reduced_spanning_forest))
5859
end
59-
return forests
60+
# Narrow the element type if possible.
61+
return identity.(forests)
6062
end
6163

6264
# TODO: Define in `NamedGraphs.PartitionedGraphs`.

src/lib/PartitionedGraphs/src/partitionsgraphview.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ for f in [
1919
:(Graphs.edges),
2020
:(Graphs.vertices),
2121
:(Graphs.rem_vertex!),
22+
:(NamedGraphs.edgetype),
23+
:(NamedGraphs.namedgraph_induced_subgraph),
24+
:(NamedGraphs.ordered_vertices),
2225
:(NamedGraphs.position_graph),
2326
:(NamedGraphs.vertex_positions),
24-
:(NamedGraphs.ordered_vertices),
25-
:(NamedGraphs.edgetype),
2627
:(NamedGraphs.vertextype),
2728
]
2829
@eval begin

test/test_partitionedgraph.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ using NamedGraphs.GraphsExtensions:
2323
add_vertices!,
2424
boundary_edges,
2525
default_root_vertex,
26+
edgetype,
2627
forest_cover,
2728
is_path_graph,
2829
is_self_loop,
@@ -72,6 +73,8 @@ using Test: @test, @testset
7273
@test edges(pgv) == parent.(partitionedges(pg))
7374
@test is_tree(pgv) == true
7475
@test neighbors(pgv, 1) == [2]
76+
@test issetequal(vertices(subgraph(pgv, [2, 3, 4])), [2, 3, 4])
77+
@test issetequal(edges(subgraph(pgv, [2, 3, 4])), edgetype(pgv).([2 => 3, 3 => 4]))
7578

7679
#Same partitioning but with a dictionary constructor
7780
partition_dict = Dictionary([first(partition) for partition in partitions], partitions)

0 commit comments

Comments
 (0)