From fffaaebab31824020db22af62e1a702bb69ff8a6 Mon Sep 17 00:00:00 2001 From: Joey Date: Tue, 20 Feb 2024 14:26:08 -0500 Subject: [PATCH 1/4] Boundary_partitionedges --- src/Graphs/partitionedgraphs/partitionedgraph.jl | 16 +++++++++++++++- test/test_partitionedgraph.jl | 13 ++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Graphs/partitionedgraphs/partitionedgraph.jl b/src/Graphs/partitionedgraphs/partitionedgraph.jl index 3f8cdad..cb1d062 100644 --- a/src/Graphs/partitionedgraphs/partitionedgraph.jl +++ b/src/Graphs/partitionedgraphs/partitionedgraph.jl @@ -94,12 +94,26 @@ 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[partitionvertex]; kwargs...) +end + function copy(pg::PartitionedGraph) return PartitionedGraph( copy(unpartitioned_graph(pg)), copy(partitioned_graph(pg)), copy(partitioned_vertices(pg)), - copy(partitionvertex(pg)), + copy(which_partition(pg)), ) end diff --git a/test/test_partitionedgraph.jl b/test/test_partitionedgraph.jl index 67d047e..a76b2d1 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, @@ -65,11 +66,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 From fd27e88f4d81d7fa2f66fc7c85edc47451afd6a5 Mon Sep 17 00:00:00 2001 From: Joey Date: Tue, 20 Feb 2024 14:32:26 -0500 Subject: [PATCH 2/4] Export boundary_partitionedges --- src/NamedGraphs.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NamedGraphs.jl b/src/NamedGraphs.jl index 7c7e6ee..6e9af0e 100644 --- a/src/NamedGraphs.jl +++ b/src/NamedGraphs.jl @@ -187,6 +187,7 @@ export NamedGraph, partitionvertex, partitionvertices, partitioned_vertices, + boundary_partitionedges, path_digraph, path_graph, periphery, From 3c8f13e85cfae8fed6b395f7f057926aaa6e3618 Mon Sep 17 00:00:00 2001 From: Joey Date: Wed, 21 Feb 2024 08:16:38 -0500 Subject: [PATCH 3/4] No Export --- src/Graphs/partitionedgraphs/partitionedgraph.jl | 2 +- src/NamedGraphs.jl | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Graphs/partitionedgraphs/partitionedgraph.jl b/src/Graphs/partitionedgraphs/partitionedgraph.jl index cb1d062..61984ec 100644 --- a/src/Graphs/partitionedgraphs/partitionedgraph.jl +++ b/src/Graphs/partitionedgraphs/partitionedgraph.jl @@ -105,7 +105,7 @@ end function boundary_partitionedges( pg::PartitionedGraph, partitionvertex::PartitionVertex; kwargs... ) - return boundary_partitionedges(pg, PartitionVertex[partitionvertex]; kwargs...) + return boundary_partitionedges(pg, [partitionvertex]; kwargs...) end function copy(pg::PartitionedGraph) diff --git a/src/NamedGraphs.jl b/src/NamedGraphs.jl index 6e9af0e..7c7e6ee 100644 --- a/src/NamedGraphs.jl +++ b/src/NamedGraphs.jl @@ -187,7 +187,6 @@ export NamedGraph, partitionvertex, partitionvertices, partitioned_vertices, - boundary_partitionedges, path_digraph, path_graph, periphery, From ce49124a953e2be87d9ac8c0c93f06617dbf2177 Mon Sep 17 00:00:00 2001 From: Joey Date: Mon, 4 Mar 2024 10:19:36 -0500 Subject: [PATCH 4/4] Added test for copy(pg::partitionedgraph) --- test/test_partitionedgraph.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/test_partitionedgraph.jl b/test/test_partitionedgraph.jl index a76b2d1..a551ada 100644 --- a/test/test_partitionedgraph.jl +++ b/test/test_partitionedgraph.jl @@ -28,6 +28,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 #Same partitioning but with a dictionary constructor partition_dict = Dictionary([first(partition) for partition in partitions], partitions) @@ -42,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]) @@ -50,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