Skip to content

Commit 3219f9c

Browse files
authored
Partitioned graphs bug fix (#88)
1 parent cec001a commit 3219f9c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/lib/PartitionedGraphs/src/partitionedgraph.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ function partitionedges(pg::PartitionedGraph)
9090
end
9191

9292
function Graphs.edges(pg::PartitionedGraph, partitionedge::PartitionEdge)
93-
psrc_vs = vertices(pg, PartitionVertex(src(partitionedge)))
94-
pdst_vs = vertices(pg, PartitionVertex(dst(partitionedge)))
95-
psrc_subgraph = subgraph(unpartitioned_graph(pg), psrc_vs)
96-
pdst_subgraph = subgraph(pg, pdst_vs)
97-
full_subgraph = subgraph(pg, vcat(psrc_vs, pdst_vs))
93+
psrc_vs = vertices(pg, src(partitionedge))
94+
pdst_vs = vertices(pg, dst(partitionedge))
95+
psrc_subgraph, _ = induced_subgraph(unpartitioned_graph(pg), psrc_vs)
96+
pdst_subgraph, _ = induced_subgraph(pg, pdst_vs)
97+
full_subgraph, _ = induced_subgraph(pg, vcat(psrc_vs, pdst_vs))
9898

9999
return setdiff(edges(full_subgraph), vcat(edges(psrc_subgraph), edges(pdst_subgraph)))
100100
end

test/test_partitionedgraph.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ using NamedGraphs.GraphsExtensions:
2828
vertextype
2929
using NamedGraphs.NamedGraphGenerators:
3030
named_comb_tree, named_grid, named_triangular_lattice_graph
31+
using NamedGraphs.OrderedDictionaries: OrderedDictionary
3132
using NamedGraphs.PartitionedGraphs:
3233
PartitionEdge,
3334
PartitionedGraph,
@@ -52,7 +53,7 @@ using Test: @test, @testset
5253
pg = PartitionedGraph(g, partitions)
5354
@test vertextype(partitioned_graph(pg)) == Int64
5455
@test vertextype(unpartitioned_graph(pg)) == vertextype(g)
55-
@test isa(partitionvertices(pg), Dictionary{Int64,PartitionVertex{Int64}})
56+
@test isa(partitionvertices(pg), OrderedDictionary{Int64,PartitionVertex{Int64}})
5657
@test isa(partitionedges(pg), Vector{PartitionEdge{Int64,NamedEdge{Int64}}})
5758
@test is_tree(partitioned_graph(pg))
5859
@test nv(pg) == nx * ny
@@ -67,7 +68,7 @@ using Test: @test, @testset
6768
@test vertextype(unpartitioned_graph(pg)) == vertextype(g)
6869
@test isa(
6970
partitionvertices(pg),
70-
Dictionary{Tuple{Int64,Int64},PartitionVertex{Tuple{Int64,Int64}}},
71+
OrderedDictionary{Tuple{Int64,Int64},PartitionVertex{Tuple{Int64,Int64}}},
7172
)
7273
@test isa(
7374
partitionedges(pg),
@@ -109,6 +110,7 @@ end
109110
inter_column_edges = [(1, 1, i) => (2, 1, i) for i in 1:nz]
110111
@test length(partitionedges(pg, inter_column_edges)) == 1
111112
@test length(partitionvertices(pg, [(1, 2, i) for i in 1:nz])) == 1
113+
@test all([length(edges(pg, pe)) == nz for pe in partitionedges(pg)])
112114

113115
boundary_sizes = [length(boundary_partitionedges(pg, pv)) for pv in partitionvertices(pg)]
114116
#Partitions into a square grid so each partition should have maximum 4 incoming edges and minimum 2

0 commit comments

Comments
 (0)