Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boundary_partitionedges #51

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Graphs/partitionedgraphs/partitionedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
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

Expand Down
1 change: 1 addition & 0 deletions src/NamedGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export NamedGraph,
partitionvertex,
partitionvertices,
partitioned_vertices,
boundary_partitionedges,
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
path_digraph,
path_graph,
periphery,
Expand Down
13 changes: 10 additions & 3 deletions test/test_partitionedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using NamedGraphs:
forest_cover,
PartitionEdge,
PartitionVertex,
boundary_partitionedges,
parent,
default_root_vertex,
triangular_lattice_graph,
Expand Down Expand Up @@ -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
Expand Down
Loading