diff --git a/src/Graphs/partitionedgraphs/partitionedgraph.jl b/src/Graphs/partitionedgraphs/partitionedgraph.jl index 45a6ec6..61984ec 100644 --- a/src/Graphs/partitionedgraphs/partitionedgraph.jl +++ b/src/Graphs/partitionedgraphs/partitionedgraph.jl @@ -94,6 +94,20 @@ function edges(pg::PartitionedGraph, partitionedges::Vector{<:PartitionEdge}) return unique(reduce(vcat, [edges(pg, pe) for pe in partitionedges])) end +function boundary_partitionedges( + pg::PartitionedGraph, partitionvertices::Vector{<:PartitionVertex}; kwargs... +) + return PartitionEdge.( + boundary_edges(partitioned_graph(pg), parent.(partitionvertices); kwargs...) + ) +end + +function boundary_partitionedges( + pg::PartitionedGraph, partitionvertex::PartitionVertex; kwargs... +) + return boundary_partitionedges(pg, [partitionvertex]; kwargs...) +end + function copy(pg::PartitionedGraph) return PartitionedGraph( copy(unpartitioned_graph(pg)), diff --git a/test/test_partitionedgraph.jl b/test/test_partitionedgraph.jl index 9a4aea7..a551ada 100644 --- a/test/test_partitionedgraph.jl +++ b/test/test_partitionedgraph.jl @@ -6,6 +6,7 @@ using NamedGraphs: forest_cover, PartitionEdge, PartitionVertex, + boundary_partitionedges, parent, default_root_vertex, triangular_lattice_graph, @@ -43,6 +44,8 @@ using Graphs @test is_tree(partitioned_graph(pg)) @test nv(pg) == nx * ny @test nv(partitioned_graph(pg)) == nx + pg_c = copy(pg) + @test pg_c == pg #Partition the whole thing into just 1 vertex pg = PartitionedGraph([i for i in 1:nx]) @@ -51,6 +54,8 @@ using Graphs @test nv(partitioned_graph(pg)) == nx @test ne(pg) == 0 @test ne(partitioned_graph(pg)) == 0 + pg_c = copy(pg) + @test pg_c == pg end @testset "Test Partitioned Graph Partition Edge and Vertex Finding" begin @@ -67,11 +72,17 @@ end @test partitionvertex(pg, (1, 1, 1)) == partitionvertex(pg, (1, 1, nz)) @test partitionvertex(pg, (2, 1, 1)) != partitionvertex(pg, (1, 1, nz)) - @test partitionedge(pg, NamedEdge((1, 1, 1) => (2, 1, 1))) == - partitionedge(pg, NamedEdge((1, 1, 2) => (2, 1, 2))) - inter_column_edges = NamedEdge.([(1, 1, i) => (2, 1, i) for i in 1:nz]) + @test partitionedge(pg, (1, 1, 1) => (2, 1, 1)) == + partitionedge(pg, (1, 1, 2) => (2, 1, 2)) + inter_column_edges = [(1, 1, i) => (2, 1, i) for i in 1:nz] @test length(partitionedges(pg, inter_column_edges)) == 1 @test length(partitionvertices(pg, [(1, 2, i) for i in 1:nz])) == 1 + + boundary_sizes = [length(boundary_partitionedges(pg, pv)) for pv in partitionvertices(pg)] + #Partitions into a square grid so each partition should have maximum 4 incoming edges and minimum 2 + @test maximum(boundary_sizes) == 4 + @test minimum(boundary_sizes) == 2 + @test isempty(boundary_partitionedges(pg, partitionvertices(pg))) end @testset "Test Partitioned Graph Vertex/Edge Addition and Removal" begin