From e45385ad5639128f13258f03cd0942f928b72e98 Mon Sep 17 00:00:00 2001 From: Jack Dunham Date: Mon, 3 Nov 2025 16:03:30 -0500 Subject: [PATCH 1/6] Rename `PartitionsGraphView` -> `QuotientGraph` and `partitions_graph` -> `quotient_graph`. --- .../src/abstractpartitionedgraph.jl | 18 +++++++++--------- .../PartitionedGraphs/src/partitionedgraph.jl | 2 +- ...partitionsgraphview.jl => quotientgraph.jl} | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) rename src/lib/PartitionedGraphs/src/{partitionsgraphview.jl => quotientgraph.jl} (71%) diff --git a/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl b/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl index 45ccce7..9f095e8 100644 --- a/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl +++ b/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl @@ -16,7 +16,7 @@ using ..NamedGraphs.GraphsExtensions: abstract type AbstractPartitionedGraph{V, PV} <: AbstractNamedGraph{V} end #Needed for interface -partitions_graph(pg::AbstractPartitionedGraph) = not_implemented() +quotient_graph(pg::AbstractPartitionedGraph) = not_implemented() unpartitioned_graph(pg::AbstractPartitionedGraph) = not_implemented() function unpartitioned_graph_type(pg::Type{<:AbstractPartitionedGraph}) return not_implemented() @@ -75,11 +75,11 @@ end function Graphs.has_vertex( pg::AbstractPartitionedGraph, partitionvertex::AbstractPartitionVertex ) - return has_vertex(partitions_graph(pg), parent(partitionvertex)) + return has_vertex(quotient_graph(pg), parent(partitionvertex)) end function Graphs.has_edge(pg::AbstractPartitionedGraph, partitionedge::AbstractPartitionEdge) - return has_edge(partitions_graph(pg), parent(partitionedge)) + return has_edge(quotient_graph(pg), parent(partitionedge)) end function is_boundary_edge(pg::AbstractPartitionedGraph, edge::AbstractEdge) @@ -91,17 +91,17 @@ function Graphs.add_edge!(pg::AbstractPartitionedGraph, edge::AbstractEdge) add_edge!(unpartitioned_graph(pg), edge) pg_edge = parent(partitionedge(pg, edge)) if src(pg_edge) != dst(pg_edge) - add_edge!(partitions_graph(pg), pg_edge) + add_edge!(quotient_graph(pg), pg_edge) end return pg end function Graphs.rem_edge!(pg::AbstractPartitionedGraph, edge::AbstractEdge) pg_edge = partitionedge(pg, edge) - if has_edge(partitions_graph(pg), pg_edge) + if has_edge(quotient_graph(pg), pg_edge) g_edges = edges(pg, pg_edge) if length(g_edges) == 1 - rem_edge!(partitions_graph(pg), pg_edge) + rem_edge!(quotient_graph(pg), pg_edge) end end return rem_edge!(unpartitioned_graph(pg), edge) @@ -118,7 +118,7 @@ function Graphs.add_vertex!( pg::AbstractPartitionedGraph, vertex, partitionvertex::AbstractPartitionVertex ) add_vertex!(unpartitioned_graph(pg), vertex) - add_vertex!(partitions_graph(pg), parent(partitionvertex)) + add_vertex!(quotient_graph(pg), parent(partitionvertex)) insert_to_vertex_map!(pg, vertex, partitionvertex) return pg end @@ -148,7 +148,7 @@ function Graphs.rem_vertex!(pg::AbstractPartitionedGraph, vertex) delete_from_vertex_map!(pg, pv, vertex) rem_vertex!(unpartitioned_graph(pg), vertex) if !haskey(partitioned_vertices(pg), parent(pv)) - rem_vertex!(partitions_graph(pg), parent(pv)) + rem_vertex!(quotient_graph(pg), parent(pv)) end return pg end @@ -174,7 +174,7 @@ end function Base.:(==)(pg1::AbstractPartitionedGraph, pg2::AbstractPartitionedGraph) if unpartitioned_graph(pg1) != unpartitioned_graph(pg2) || - partitions_graph(pg1) != partitions_graph(pg2) + quotient_graph(pg1) != quotient_graph(pg2) return false end for v in vertices(pg1) diff --git a/src/lib/PartitionedGraphs/src/partitionedgraph.jl b/src/lib/PartitionedGraphs/src/partitionedgraph.jl index 9192d61..cd3277a 100644 --- a/src/lib/PartitionedGraphs/src/partitionedgraph.jl +++ b/src/lib/PartitionedGraphs/src/partitionedgraph.jl @@ -46,7 +46,7 @@ function PartitionedGraph(g::AbstractGraph; kwargs...) end #Needed for interface -partitions_graph(pg::PartitionedGraph) = PartitionsGraphView(pg) +quotient_graph(pg::PartitionedGraph) = QuotientGraph(pg) unpartitioned_graph(pg::PartitionedGraph) = getfield(pg, :graph) function unpartitioned_graph_type(graph_type::Type{<:PartitionedGraph}) return fieldtype(graph_type, :graph) diff --git a/src/lib/PartitionedGraphs/src/partitionsgraphview.jl b/src/lib/PartitionedGraphs/src/quotientgraph.jl similarity index 71% rename from src/lib/PartitionedGraphs/src/partitionsgraphview.jl rename to src/lib/PartitionedGraphs/src/quotientgraph.jl index 461d8ab..f319633 100644 --- a/src/lib/PartitionedGraphs/src/partitionsgraphview.jl +++ b/src/lib/PartitionedGraphs/src/quotientgraph.jl @@ -1,16 +1,16 @@ -struct PartitionsGraphView{V, G <: AbstractGraph{V}} <: AbstractNamedGraph{V} +struct QuotientGraph{V, G <: AbstractGraph{V}} <: AbstractNamedGraph{V} graph::G end -Base.copy(g::PartitionsGraphView) = PartitionsGraphView(copy(g.graph)) +Base.copy(g::QuotientGraph) = QuotientGraph(copy(g.graph)) using Graphs: AbstractGraph -partitions_graph(g::AbstractGraph) = PartitionsGraphView(PartitionedGraph(g, [vertices(g)])) +quotient_graph(g::AbstractGraph) = QuotientGraph(PartitionedGraph(g, [vertices(g)])) # Graphs.jl and NamedGraphs.jl interface overloads for `PartitionsGraphView` wrapping # a `PartitionedGraph`. function NamedGraphs.position_graph_type( - type::Type{<:PartitionsGraphView{V, G}} + type::Type{<:QuotientGraph{V, G}} ) where {V, G <: PartitionedGraph{V}} return fieldtype(fieldtype(fieldtype(type, :graph), :partitions_graph), :position_graph) end @@ -28,7 +28,7 @@ for f in [ ] @eval begin function $f( - g::PartitionsGraphView{V, G}, args...; kwargs... + g::QuotientGraph{V, G}, args...; kwargs... ) where {V, G <: PartitionedGraph{V}} return $f(g.graph.partitions_graph, args...; kwargs...) end From 609c855166a3ecc4dc2c44b2bffef5938470bf1b Mon Sep 17 00:00:00 2001 From: Jack Dunham Date: Mon, 3 Nov 2025 16:41:33 -0500 Subject: [PATCH 2/6] Rename `PartitionVertex` -> `SuperVertex` and `PartitionEdge` -> `SuperEdge`; fix tests --- .../src/PartitionedGraphs.jl | 10 +- .../src/abstractpartitionedge.jl | 11 -- .../src/abstractpartitionedgraph.jl | 86 +++++++------- .../src/abstractpartitionvertex.jl | 4 - .../src/abstractsuperedge.jl | 11 ++ .../src/abstractsupervertex.jl | 4 + .../PartitionedGraphs/src/partitionedge.jl | 12 -- .../PartitionedGraphs/src/partitionedgraph.jl | 74 ++++++------ .../PartitionedGraphs/src/partitionvertex.jl | 5 - src/lib/PartitionedGraphs/src/superedge.jl | 12 ++ src/lib/PartitionedGraphs/src/supervertex.jl | 5 + test/test_partitionedgraph.jl | 112 +++++++++--------- 12 files changed, 173 insertions(+), 173 deletions(-) delete mode 100644 src/lib/PartitionedGraphs/src/abstractpartitionedge.jl delete mode 100644 src/lib/PartitionedGraphs/src/abstractpartitionvertex.jl create mode 100644 src/lib/PartitionedGraphs/src/abstractsuperedge.jl create mode 100644 src/lib/PartitionedGraphs/src/abstractsupervertex.jl delete mode 100644 src/lib/PartitionedGraphs/src/partitionedge.jl delete mode 100644 src/lib/PartitionedGraphs/src/partitionvertex.jl create mode 100644 src/lib/PartitionedGraphs/src/superedge.jl create mode 100644 src/lib/PartitionedGraphs/src/supervertex.jl diff --git a/src/lib/PartitionedGraphs/src/PartitionedGraphs.jl b/src/lib/PartitionedGraphs/src/PartitionedGraphs.jl index a14d5ef..7390ee9 100644 --- a/src/lib/PartitionedGraphs/src/PartitionedGraphs.jl +++ b/src/lib/PartitionedGraphs/src/PartitionedGraphs.jl @@ -1,9 +1,9 @@ module PartitionedGraphs -include("abstractpartitionvertex.jl") -include("abstractpartitionedge.jl") +include("abstractsupervertex.jl") +include("abstractsuperedge.jl") include("abstractpartitionedgraph.jl") -include("partitionvertex.jl") -include("partitionedge.jl") +include("supervertex.jl") +include("superedge.jl") include("partitionedgraph.jl") -include("partitionsgraphview.jl") +include("quotientgraph.jl") end diff --git a/src/lib/PartitionedGraphs/src/abstractpartitionedge.jl b/src/lib/PartitionedGraphs/src/abstractpartitionedge.jl deleted file mode 100644 index 57188e6..0000000 --- a/src/lib/PartitionedGraphs/src/abstractpartitionedge.jl +++ /dev/null @@ -1,11 +0,0 @@ -using Graphs: Graphs -using ..NamedGraphs: AbstractNamedEdge - -abstract type AbstractPartitionEdge{V} <: AbstractNamedEdge{V} end - -Base.parent(pe::AbstractPartitionEdge) = not_implemented() -Graphs.src(pe::AbstractPartitionEdge) = not_implemented() -Graphs.dst(pe::AbstractPartitionEdge) = not_implemented() -Base.reverse(pe::AbstractPartitionEdge) = not_implemented() - -#Don't have the vertices wrapped. But wrap them with source and edge. diff --git a/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl b/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl index 9f095e8..e59c16b 100644 --- a/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl +++ b/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl @@ -21,28 +21,28 @@ unpartitioned_graph(pg::AbstractPartitionedGraph) = not_implemented() function unpartitioned_graph_type(pg::Type{<:AbstractPartitionedGraph}) return not_implemented() end -partitionvertex(pg::AbstractPartitionedGraph, vertex) = not_implemented() -partitionvertices(pg::AbstractPartitionedGraph, verts) = not_implemented() -partitionvertices(pg::AbstractPartitionedGraph) = not_implemented() +supervertex(pg::AbstractPartitionedGraph, vertex) = not_implemented() +supervertex(pg::AbstractPartitionedGraph, verts) = not_implemented() +supervertex(pg::AbstractPartitionedGraph) = not_implemented() Base.copy(pg::AbstractPartitionedGraph) = not_implemented() delete_from_vertex_map!(pg::AbstractPartitionedGraph, vertex) = not_implemented() insert_to_vertex_map!(pg::AbstractPartitionedGraph, vertex) = not_implemented() -partitionedge(pg::AbstractPartitionedGraph, edge) = not_implemented() -partitionedges(pg::AbstractPartitionedGraph, edges) = not_implemented() -partitionedges(pg::AbstractPartitionedGraph) = not_implemented() +superedge(pg::AbstractPartitionedGraph, edge) = not_implemented() +superedges(pg::AbstractPartitionedGraph, edges) = not_implemented() +superedges(pg::AbstractPartitionedGraph) = not_implemented() function unpartitioned_graph_type(pg::AbstractPartitionedGraph) return typeof(unpartitioned_graph(pg)) end -function Graphs.edges(pg::AbstractPartitionedGraph, partitionedge::AbstractPartitionEdge) +function Graphs.edges(pg::AbstractPartitionedGraph, superedge::AbstractSuperEdge) return not_implemented() end -function Graphs.vertices(pg::AbstractPartitionedGraph, pv::AbstractPartitionVertex) +function Graphs.vertices(pg::AbstractPartitionedGraph, supervertex::AbstractSuperVertex) return not_implemented() end function Graphs.vertices( - pg::AbstractPartitionedGraph, partitionverts::Vector{V} - ) where {V <: AbstractPartitionVertex} + pg::AbstractPartitionedGraph, supervertices::Vector{V} + ) where {V <: AbstractSuperVertex} return not_implemented() end function GraphsExtensions.directed_graph_type(PG::Type{<:AbstractPartitionedGraph}) @@ -69,27 +69,27 @@ function NamedGraphs.ordered_vertices(pg::AbstractPartitionedGraph) return NamedGraphs.ordered_vertices(unpartitioned_graph(pg)) end Graphs.edgetype(pg::AbstractPartitionedGraph) = edgetype(unpartitioned_graph(pg)) -function Graphs.nv(pg::AbstractPartitionedGraph, pv::AbstractPartitionVertex) - return length(vertices(pg, pv)) +function Graphs.nv(pg::AbstractPartitionedGraph, sv::AbstractSuperVertex) + return length(vertices(pg, sv)) end function Graphs.has_vertex( - pg::AbstractPartitionedGraph, partitionvertex::AbstractPartitionVertex + pg::AbstractPartitionedGraph, supervertex::AbstractSuperVertex ) - return has_vertex(quotient_graph(pg), parent(partitionvertex)) + return has_vertex(quotient_graph(pg), parent(supervertex)) end -function Graphs.has_edge(pg::AbstractPartitionedGraph, partitionedge::AbstractPartitionEdge) - return has_edge(quotient_graph(pg), parent(partitionedge)) +function Graphs.has_edge(pg::AbstractPartitionedGraph, superedge::AbstractSuperEdge) + return has_edge(quotient_graph(pg), parent(superedge)) end function is_boundary_edge(pg::AbstractPartitionedGraph, edge::AbstractEdge) - p_edge = partitionedge(pg, edge) + p_edge = superedge(pg, edge) return src(p_edge) == dst(p_edge) end function Graphs.add_edge!(pg::AbstractPartitionedGraph, edge::AbstractEdge) add_edge!(unpartitioned_graph(pg), edge) - pg_edge = parent(partitionedge(pg, edge)) + pg_edge = parent(superedge(pg, edge)) if src(pg_edge) != dst(pg_edge) add_edge!(quotient_graph(pg), pg_edge) end @@ -97,7 +97,7 @@ function Graphs.add_edge!(pg::AbstractPartitionedGraph, edge::AbstractEdge) end function Graphs.rem_edge!(pg::AbstractPartitionedGraph, edge::AbstractEdge) - pg_edge = partitionedge(pg, edge) + pg_edge = superedge(pg, edge) if has_edge(quotient_graph(pg), pg_edge) g_edges = edges(pg, pg_edge) if length(g_edges) == 1 @@ -108,63 +108,63 @@ function Graphs.rem_edge!(pg::AbstractPartitionedGraph, edge::AbstractEdge) end function Graphs.rem_edge!( - pg::AbstractPartitionedGraph, partitionedge::AbstractPartitionEdge + pg::AbstractPartitionedGraph, superedge::AbstractSuperEdge ) - return rem_edges!(pg, edges(pg, parent(partitionedge))) + return rem_edges!(pg, edges(pg, parent(superedge))) end #Vertex addition and removal. I think it's important not to allow addition of a vertex without specification of PV function Graphs.add_vertex!( - pg::AbstractPartitionedGraph, vertex, partitionvertex::AbstractPartitionVertex + pg::AbstractPartitionedGraph, vertex, supervertex::AbstractSuperVertex ) add_vertex!(unpartitioned_graph(pg), vertex) - add_vertex!(quotient_graph(pg), parent(partitionvertex)) - insert_to_vertex_map!(pg, vertex, partitionvertex) + add_vertex!(quotient_graph(pg), parent(supervertex)) + insert_to_vertex_map!(pg, vertex, supervertex) return pg end function GraphsExtensions.add_vertices!( pg::AbstractPartitionedGraph, vertices::Vector, - partitionvertices::Vector{<:AbstractPartitionVertex}, + supervertices::Vector{<:AbstractSuperVertex}, ) - @assert length(vertices) == length(partitionvertices) - for (v, pv) in zip(vertices, partitionvertices) - add_vertex!(pg, v, pv) + @assert length(vertices) == length(supervertices) + for (v, sv) in zip(vertices, supervertices) + add_vertex!(pg, v, sv) end return pg end function GraphsExtensions.add_vertices!( - pg::AbstractPartitionedGraph, vertices::Vector, partitionvertex::AbstractPartitionVertex + pg::AbstractPartitionedGraph, vertices::Vector, supervertex::AbstractSuperVertex ) - add_vertices!(pg, vertices, fill(partitionvertex, length(vertices))) + add_vertices!(pg, vertices, fill(supervertex, length(vertices))) return pg end function Graphs.rem_vertex!(pg::AbstractPartitionedGraph, vertex) - pv = partitionvertex(pg, vertex) - delete_from_vertex_map!(pg, pv, vertex) + sv = supervertex(pg, vertex) + delete_from_vertex_map!(pg, sv, vertex) rem_vertex!(unpartitioned_graph(pg), vertex) - if !haskey(partitioned_vertices(pg), parent(pv)) - rem_vertex!(quotient_graph(pg), parent(pv)) + if !haskey(partitioned_vertices(pg), parent(sv)) + rem_vertex!(quotient_graph(pg), parent(sv)) end return pg end function Graphs.rem_vertex!( - pg::AbstractPartitionedGraph, partitionvertex::AbstractPartitionVertex + pg::AbstractPartitionedGraph, supervertex::AbstractSuperVertex ) - rem_vertices!(pg, vertices(pg, partitionvertex)) + rem_vertices!(pg, vertices(pg, supervertex)) return pg end function GraphsExtensions.rem_vertex( - pg::AbstractPartitionedGraph, partitionvertex::AbstractPartitionVertex + pg::AbstractPartitionedGraph, supervertex::AbstractSuperVertex ) pg_new = copy(pg) - rem_vertex!(pg_new, partitionvertex) + rem_vertex!(pg_new, supervertex) return pg_new end @@ -178,7 +178,7 @@ function Base.:(==)(pg1::AbstractPartitionedGraph, pg2::AbstractPartitionedGraph return false end for v in vertices(pg1) - if partitionvertex(pg1, v) != partitionvertex(pg2, v) + if supervertex(pg1, v) != supervertex(pg2, v) return false end end @@ -186,13 +186,13 @@ function Base.:(==)(pg1::AbstractPartitionedGraph, pg2::AbstractPartitionedGraph end function GraphsExtensions.subgraph( - pg::AbstractPartitionedGraph, partitionvertex::AbstractPartitionVertex + pg::AbstractPartitionedGraph, supervertex::AbstractSuperVertex ) - return first(induced_subgraph(unpartitioned_graph(pg), vertices(pg, [partitionvertex]))) + return first(induced_subgraph(unpartitioned_graph(pg), vertices(pg, [supervertex]))) end function Graphs.induced_subgraph( - pg::AbstractPartitionedGraph, partitionvertex::AbstractPartitionVertex + pg::AbstractPartitionedGraph, supervertex::AbstractSuperVertex ) - return subgraph(pg, partitionvertex), nothing + return subgraph(pg, supervertex), nothing end diff --git a/src/lib/PartitionedGraphs/src/abstractpartitionvertex.jl b/src/lib/PartitionedGraphs/src/abstractpartitionvertex.jl deleted file mode 100644 index 31bc58b..0000000 --- a/src/lib/PartitionedGraphs/src/abstractpartitionvertex.jl +++ /dev/null @@ -1,4 +0,0 @@ -abstract type AbstractPartitionVertex{V} <: Any where {V} end - -#Parent, wrap, unwrap, vertex? -Base.parent(pv::AbstractPartitionVertex) = not_implemented() diff --git a/src/lib/PartitionedGraphs/src/abstractsuperedge.jl b/src/lib/PartitionedGraphs/src/abstractsuperedge.jl new file mode 100644 index 0000000..f4fe71d --- /dev/null +++ b/src/lib/PartitionedGraphs/src/abstractsuperedge.jl @@ -0,0 +1,11 @@ +using Graphs: Graphs +using ..NamedGraphs: AbstractNamedEdge + +abstract type AbstractSuperEdge{V} <: AbstractNamedEdge{V} end + +Base.parent(se::AbstractSuperEdge) = not_implemented() +Graphs.src(se::AbstractSuperEdge) = not_implemented() +Graphs.dst(se::AbstractSuperEdge) = not_implemented() +Base.reverse(se::AbstractSuperEdge) = not_implemented() + +#Don't have the vertices wrapped. But wrap them with source and edge. diff --git a/src/lib/PartitionedGraphs/src/abstractsupervertex.jl b/src/lib/PartitionedGraphs/src/abstractsupervertex.jl new file mode 100644 index 0000000..62d3f75 --- /dev/null +++ b/src/lib/PartitionedGraphs/src/abstractsupervertex.jl @@ -0,0 +1,4 @@ +abstract type AbstractSuperVertex{V} <: Any where {V} end + +#Parent, wrap, unwrap, vertex? +Base.parent(sv::AbstractSuperVertex) = not_implemented() diff --git a/src/lib/PartitionedGraphs/src/partitionedge.jl b/src/lib/PartitionedGraphs/src/partitionedge.jl deleted file mode 100644 index d473522..0000000 --- a/src/lib/PartitionedGraphs/src/partitionedge.jl +++ /dev/null @@ -1,12 +0,0 @@ -using Graphs: Graphs, AbstractEdge, dst, src - -struct PartitionEdge{V, E <: AbstractEdge{V}} <: AbstractPartitionEdge{V} - edge::E -end - -Base.parent(pe::PartitionEdge) = getfield(pe, :edge) -Graphs.src(pe::PartitionEdge) = PartitionVertex(src(parent(pe))) -Graphs.dst(pe::PartitionEdge) = PartitionVertex(dst(parent(pe))) -PartitionEdge(p::Pair) = PartitionEdge(NamedEdge(first(p) => last(p))) -PartitionEdge(vsrc, vdst) = PartitionEdge(vsrc => vdst) -Base.reverse(pe::PartitionEdge) = PartitionEdge(reverse(parent(pe))) diff --git a/src/lib/PartitionedGraphs/src/partitionedgraph.jl b/src/lib/PartitionedGraphs/src/partitionedgraph.jl index cd3277a..cbd0fce 100644 --- a/src/lib/PartitionedGraphs/src/partitionedgraph.jl +++ b/src/lib/PartitionedGraphs/src/partitionedgraph.jl @@ -55,43 +55,43 @@ function GraphsExtensions.partitioned_vertices(pg::PartitionedGraph) return getfield(pg, :partitioned_vertices) end which_partition(pg::PartitionedGraph) = getfield(pg, :which_partition) -function Graphs.vertices(pg::PartitionedGraph, partitionvert::PartitionVertex) - return partitioned_vertices(pg)[parent(partitionvert)] +function Graphs.vertices(pg::PartitionedGraph, supervertex::SuperVertex) + return partitioned_vertices(pg)[parent(supervertex)] end -function Graphs.vertices(pg::PartitionedGraph, partitionverts::Vector{<:PartitionVertex}) - return unique(reduce(vcat, Iterators.map(pv -> vertices(pg, pv), partitionverts))) +function Graphs.vertices(pg::PartitionedGraph, supervertices::Vector{<:SuperVertex}) + return unique(reduce(vcat, Iterators.map(sv -> vertices(pg, sv), supervertices))) end -function partitionvertex(pg::PartitionedGraph, vertex) - return PartitionVertex(which_partition(pg)[vertex]) +function supervertex(pg::PartitionedGraph, vertex) + return SuperVertex(which_partition(pg)[vertex]) end -function partitionvertices(pg::PartitionedGraph, verts) - return unique(partitionvertex(pg, v) for v in verts) +function supervertices(pg::PartitionedGraph, verts) + return unique(supervertex(pg, v) for v in verts) end -function partitionvertices(pg::PartitionedGraph) - return PartitionVertex.(vertices(pg.partitions_graph)) +function supervertices(pg::PartitionedGraph) + return SuperVertex.(vertices(pg.partitions_graph)) end -function partitionedge(pg::PartitionedGraph, edge::AbstractEdge) - return PartitionEdge( - parent(partitionvertex(pg, src(edge))) => parent(partitionvertex(pg, dst(edge))) +function superedge(pg::PartitionedGraph, edge::AbstractEdge) + return SuperEdge( + parent(supervertex(pg, src(edge))) => parent(supervertex(pg, dst(edge))) ) end -partitionedge(pg::PartitionedGraph, p::Pair) = partitionedge(pg, edgetype(pg)(p)) +superedge(pg::PartitionedGraph, p::Pair) = superedge(pg, edgetype(pg)(p)) -function partitionedges(pg::PartitionedGraph, edges::Vector) - return filter(!is_self_loop, unique([partitionedge(pg, e) for e in edges])) +function superedges(pg::PartitionedGraph, edges::Vector) + return filter(!is_self_loop, unique([superedge(pg, e) for e in edges])) end -function partitionedges(pg::PartitionedGraph) - return PartitionEdge.(edges(pg.partitions_graph)) +function superedges(pg::PartitionedGraph) + return SuperEdge.(edges(pg.partitions_graph)) end -function Graphs.edges(pg::PartitionedGraph, partitionedge::PartitionEdge) - psrc_vs = vertices(pg, src(partitionedge)) - pdst_vs = vertices(pg, dst(partitionedge)) +function Graphs.edges(pg::PartitionedGraph, superedge::SuperEdge) + psrc_vs = vertices(pg, src(superedge)) + pdst_vs = vertices(pg, dst(superedge)) psrc_subgraph, _ = induced_subgraph(unpartitioned_graph(pg), psrc_vs) pdst_subgraph, _ = induced_subgraph(pg, pdst_vs) full_subgraph, _ = induced_subgraph(pg, vcat(psrc_vs, pdst_vs)) @@ -99,20 +99,20 @@ function Graphs.edges(pg::PartitionedGraph, partitionedge::PartitionEdge) return setdiff(edges(full_subgraph), vcat(edges(psrc_subgraph), edges(pdst_subgraph))) end -function Graphs.edges(pg::PartitionedGraph, partitionedges::Vector{<:PartitionEdge}) - return unique(reduce(vcat, [edges(pg, pe) for pe in partitionedges])) +function Graphs.edges(pg::PartitionedGraph, superedges::Vector{<:SuperEdge}) + return unique(reduce(vcat, [edges(pg, se) for se in superedges])) end -function boundary_partitionedges(pg::PartitionedGraph, partitionvertices; kwargs...) - return PartitionEdge.( - boundary_edges(pg.partitions_graph, parent.(partitionvertices); kwargs...) +function boundary_superedges(pg::PartitionedGraph, supervertices; kwargs...) + return SuperEdge.( + boundary_edges(pg.partitions_graph, parent.(supervertices); kwargs...) ) end -function boundary_partitionedges( - pg::PartitionedGraph, partitionvertex::PartitionVertex; kwargs... +function boundary_superedges( + pg::PartitionedGraph, supervertex::SuperVertex; kwargs... ) - return boundary_partitionedges(pg, [partitionvertex]; kwargs...) + return boundary_superedges(pg, [supervertex]; kwargs...) end function Base.copy(pg::PartitionedGraph) @@ -125,13 +125,13 @@ function Base.copy(pg::PartitionedGraph) end function insert_to_vertex_map!( - pg::PartitionedGraph, vertex, partitionvertex::PartitionVertex + pg::PartitionedGraph, vertex, supervertex::SuperVertex ) - pv = parent(partitionvertex) + pv = parent(supervertex) if pv ∉ keys(partitioned_vertices(pg)) insert!(partitioned_vertices(pg), pv, [vertex]) else - partitioned_vertices(pg)[pv] = unique(vcat(vertices(pg, partitionvertex), [vertex])) + partitioned_vertices(pg)[pv] = unique(vcat(vertices(pg, supervertex), [vertex])) end insert!(which_partition(pg), vertex, pv) @@ -139,12 +139,12 @@ function insert_to_vertex_map!( end function delete_from_vertex_map!(pg::PartitionedGraph, vertex) - pv = partitionvertex(pg, vertex) - return delete_from_vertex_map!(pg, pv, vertex) + sv = supervertex(pg, vertex) + return delete_from_vertex_map!(pg, sv, vertex) end function delete_from_vertex_map!( - pg::PartitionedGraph, partitioned_vertex::PartitionVertex, vertex + pg::PartitionedGraph, partitioned_vertex::SuperVertex, vertex ) vs = vertices(pg, partitioned_vertex) delete!(partitioned_vertices(pg), parent(partitioned_vertex)) @@ -173,9 +173,9 @@ function partitionedgraph_induced_subgraph(pg::PartitionedGraph, vertices::Vecto end function partitionedgraph_induced_subgraph( - pg::PartitionedGraph, partitionverts::Vector{<:PartitionVertex} + pg::PartitionedGraph, supervertices::Vector{<:SuperVertex} ) - return induced_subgraph(pg, vertices(pg, partitionverts)) + return induced_subgraph(pg, vertices(pg, supervertices)) end function Graphs.induced_subgraph(pg::PartitionedGraph, vertices) diff --git a/src/lib/PartitionedGraphs/src/partitionvertex.jl b/src/lib/PartitionedGraphs/src/partitionvertex.jl deleted file mode 100644 index a2d46c6..0000000 --- a/src/lib/PartitionedGraphs/src/partitionvertex.jl +++ /dev/null @@ -1,5 +0,0 @@ -struct PartitionVertex{V} <: AbstractPartitionVertex{V} - vertex::V -end - -Base.parent(pv::PartitionVertex) = getfield(pv, :vertex) diff --git a/src/lib/PartitionedGraphs/src/superedge.jl b/src/lib/PartitionedGraphs/src/superedge.jl new file mode 100644 index 0000000..4ce55df --- /dev/null +++ b/src/lib/PartitionedGraphs/src/superedge.jl @@ -0,0 +1,12 @@ +using Graphs: Graphs, AbstractEdge, dst, src + +struct SuperEdge{V, E <: AbstractEdge{V}} <: AbstractSuperEdge{V} + edge::E +end + +Base.parent(se::SuperEdge) = getfield(se, :edge) +Graphs.src(se::SuperEdge) = SuperVertex(src(parent(se))) +Graphs.dst(se::SuperEdge) = SuperVertex(dst(parent(se))) +SuperEdge(p::Pair) = SuperEdge(NamedEdge(first(p) => last(p))) +SuperEdge(vsrc, vdst) = SuperEdge(vsrc => vdst) +Base.reverse(se::SuperEdge) = SuperEdge(reverse(parent(se))) diff --git a/src/lib/PartitionedGraphs/src/supervertex.jl b/src/lib/PartitionedGraphs/src/supervertex.jl new file mode 100644 index 0000000..16d5e29 --- /dev/null +++ b/src/lib/PartitionedGraphs/src/supervertex.jl @@ -0,0 +1,5 @@ +struct SuperVertex{V} <: AbstractSuperVertex{V} + vertex::V +end + +Base.parent(sv::SuperVertex) = getfield(sv, :vertex) diff --git a/test/test_partitionedgraph.jl b/test/test_partitionedgraph.jl index e3c35d3..ecf5b63 100644 --- a/test/test_partitionedgraph.jl +++ b/test/test_partitionedgraph.jl @@ -35,16 +35,16 @@ using NamedGraphs.NamedGraphGenerators: named_comb_tree, named_grid, named_triangular_lattice_graph using NamedGraphs.OrderedDictionaries: OrderedDictionary using NamedGraphs.PartitionedGraphs: - PartitionEdge, - PartitionVertex, + SuperEdge, + SuperVertex, PartitionedGraph, - PartitionsGraphView, - boundary_partitionedges, - partitions_graph, - partitionedge, - partitionedges, - partitionvertex, - partitionvertices, + QuotientGraph, + boundary_superedges, + quotient_graph, + superedge, + superedges, + supervertex, + supervertices, unpartitioned_graph using Dictionaries: Dictionary, dictionary using Pkg: Pkg @@ -57,20 +57,20 @@ using Test: @test, @testset #Partition it column-wise (into a 1D chain) partitions = [[(i, j) for j in 1:ny] for i in 1:nx] pg = PartitionedGraph(g, partitions) - @test vertextype(partitions_graph(pg)) == Int64 + @test vertextype(quotient_graph(pg)) == Int64 @test vertextype(unpartitioned_graph(pg)) == vertextype(g) - @test isa(partitionvertices(pg), OrderedDictionary{Int64, PartitionVertex{Int64}}) - @test isa(partitionedges(pg), Vector{PartitionEdge{Int64, NamedEdge{Int64}}}) - @test is_tree(partitions_graph(pg)) + @test isa(supervertices(pg), OrderedDictionary{Int64, SuperVertex{Int64}}) + @test isa(superedges(pg), Vector{SuperEdge{Int64, NamedEdge{Int64}}}) + @test is_tree(quotient_graph(pg)) @test nv(pg) == nx * ny - @test nv(partitions_graph(pg)) == nx + @test nv(quotient_graph(pg)) == nx pg_c = copy(pg) @test pg_c == pg #PartionsGraphView test - pgv = PartitionsGraphView(pg) - @test vertices(pgv) == parent.(partitionvertices(pg)) - @test edges(pgv) == parent.(partitionedges(pg)) + pgv = QuotientGraph(pg) + @test vertices(pgv) == parent.(supervertices(pg)) + @test edges(pgv) == parent.(superedges(pg)) @test is_tree(pgv) == true @test neighbors(pgv, 1) == [2] @test issetequal(vertices(subgraph(pgv, [2, 3, 4])), [2, 3, 4]) @@ -79,29 +79,29 @@ using Test: @test, @testset #Same partitioning but with a dictionary constructor partition_dict = Dictionary([first(partition) for partition in partitions], partitions) pg = PartitionedGraph(g, partition_dict) - @test vertextype(partitions_graph(pg)) == vertextype(g) + @test vertextype(quotient_graph(pg)) == vertextype(g) @test vertextype(unpartitioned_graph(pg)) == vertextype(g) @test isa( - partitionvertices(pg), - OrderedDictionary{Tuple{Int64, Int64}, PartitionVertex{Tuple{Int64, Int64}}}, + supervertices(pg), + OrderedDictionary{Tuple{Int64, Int64}, SuperVertex{Tuple{Int64, Int64}}}, ) @test isa( - partitionedges(pg), - Vector{PartitionEdge{Tuple{Int64, Int64}, NamedEdge{Tuple{Int64, Int64}}}}, + superedges(pg), + Vector{SuperEdge{Tuple{Int64, Int64}, NamedEdge{Tuple{Int64, Int64}}}}, ) - @test is_tree(partitions_graph(pg)) + @test is_tree(quotient_graph(pg)) @test nv(pg) == nx * ny - @test nv(partitions_graph(pg)) == nx + @test nv(quotient_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]) - @test unpartitioned_graph(pg) == partitions_graph(pg) + @test unpartitioned_graph(pg) == quotient_graph(pg) @test nv(pg) == nx - @test nv(partitions_graph(pg)) == nx + @test nv(quotient_graph(pg)) == nx @test ne(pg) == 0 - @test ne(partitions_graph(pg)) == 0 + @test ne(quotient_graph(pg)) == 0 pg_c = copy(pg) @test pg_c == pg end @@ -113,25 +113,25 @@ end #Partition it column-wise (into a square grid) partitions = [[(i, j, k) for k in 1:nz] for i in 1:nx for j in 1:ny] pg = PartitionedGraph(g, partitions) - @test Set(partitionvertices(pg)) == Set(partitionvertices(pg, vertices(g))) - @test Set(partitionedges(pg)) == Set(partitionedges(pg, edges(g))) - @test is_self_loop(partitionedge(pg, (1, 1, 1) => (1, 1, 2))) - @test !is_self_loop(partitionedge(pg, (1, 2, 1) => (1, 1, 1))) - @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, (1, 1, 1) => (2, 1, 1)) == - partitionedge(pg, (1, 1, 2) => (2, 1, 2)) + @test Set(supervertices(pg)) == Set(supervertices(pg, vertices(g))) + @test Set(superedges(pg)) == Set(superedges(pg, edges(g))) + @test is_self_loop(superedge(pg, (1, 1, 1) => (1, 1, 2))) + @test !is_self_loop(superedge(pg, (1, 2, 1) => (1, 1, 1))) + @test supervertex(pg, (1, 1, 1)) == supervertex(pg, (1, 1, nz)) + @test supervertex(pg, (2, 1, 1)) != supervertex(pg, (1, 1, nz)) + + @test superedge(pg, (1, 1, 1) => (2, 1, 1)) == + superedge(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 - @test all([length(edges(pg, pe)) == nz for pe in partitionedges(pg)]) + @test length(superedges(pg, inter_column_edges)) == 1 + @test length(supervertices(pg, [(1, 2, i) for i in 1:nz])) == 1 + @test all([length(edges(pg, pe)) == nz for pe in superedges(pg)]) - boundary_sizes = [length(boundary_partitionedges(pg, pv)) for pv in partitionvertices(pg)] + boundary_sizes = [length(boundary_superedges(pg, pv)) for pv in supervertices(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))) + @test isempty(boundary_superedges(pg, supervertices(pg))) end @testset "Test Partitioned Graph Vertex/Edge Addition and Removal" begin @@ -141,28 +141,28 @@ end partitions = [[(i, j) for j in 1:ny] for i in 1:nx] pg = PartitionedGraph(g, partitions) - pv = PartitionVertex(5) + pv = SuperVertex(5) v_set = vertices(pg, pv) edges_involving_v_set = boundary_edges(g, v_set) #Strip the middle column from pg via the partitioned graph vertex, and make a new pg rem_vertex!(pg, pv) - @test !is_connected(unpartitioned_graph(pg)) && !is_connected(partitions_graph(pg)) - @test parent(pv) ∉ vertices(partitions_graph(pg)) + @test !is_connected(unpartitioned_graph(pg)) && !is_connected(quotient_graph(pg)) + @test parent(pv) ∉ vertices(quotient_graph(pg)) @test !has_vertex(pg, pv) @test nv(pg) == (nx - 1) * ny - @test nv(partitions_graph(pg)) == nx - 1 - @test !is_tree(partitions_graph(pg)) + @test nv(quotient_graph(pg)) == nx - 1 + @test !is_tree(quotient_graph(pg)) #Add the column back to the in place graph add_vertices!(pg, v_set, pv) add_edges!(pg, edges_involving_v_set) - @test is_connected(pg.graph) && is_path_graph(partitions_graph(pg)) - @test parent(pv) ∈ vertices(partitions_graph(pg)) + @test is_connected(pg.graph) && is_path_graph(quotient_graph(pg)) + @test parent(pv) ∈ vertices(quotient_graph(pg)) @test has_vertex(pg, pv) - @test is_tree(partitions_graph(pg)) + @test is_tree(quotient_graph(pg)) @test nv(pg) == nx * ny - @test nv(partitions_graph(pg)) == nx + @test nv(quotient_graph(pg)) == nx end @testset "Test Partitioned Graph Subgraph Functionality" begin @@ -180,15 +180,15 @@ end vcat, [partitions[spv] for spv in subgraph_partitioned_vertices] ) - pg_1 = subgraph(pg, PartitionVertex.(subgraph_partitioned_vertices)) + pg_1 = subgraph(pg, SuperVertex.(subgraph_partitioned_vertices)) pg_2 = subgraph(pg, subgraph_vertices) @test pg_1 == pg_2 @test nv(pg_1) == length(subgraph_vertices) - @test nv(partitions_graph(pg_1)) == length(subgraph_partitioned_vertices) + @test nv(quotient_graph(pg_1)) == length(subgraph_partitioned_vertices) subgraph_partitioned_vertex = 3 subgraph_vertices = partitions[subgraph_partitioned_vertex] - g_1 = subgraph(pg, PartitionVertex(subgraph_partitioned_vertex)) + g_1 = subgraph(pg, SuperVertex(subgraph_partitioned_vertex)) pg_1 = subgraph(pg, subgraph_vertices) @test unpartitioned_graph(pg_1) == subgraph(g, subgraph_vertices) @test g_1 == subgraph(g, subgraph_vertices) @@ -207,9 +207,9 @@ end pg = PartitionedGraph(g, [vertices(g)]) @test f(pg) == f(unpartitioned_graph(pg)) @test nv(pg) == nv(g) - @test nv(partitions_graph(pg)) == 1 + @test nv(quotient_graph(pg)) == 1 @test ne(pg) == ne(g) - @test ne(partitions_graph(pg)) == 0 + @test ne(quotient_graph(pg)) == 0 end end end @@ -226,7 +226,7 @@ end for backend in backends pg = PartitionedGraph(g; npartitions, backend = "metis") @test pg isa PartitionedGraph - @test nv(partitions_graph(pg)) == npartitions + @test nv(quotient_graph(pg)) == npartitions end end end From c8805cd4aad7f989df015d31cb2e6014615c927f Mon Sep 17 00:00:00 2001 From: Jack Dunham Date: Mon, 3 Nov 2025 16:46:52 -0500 Subject: [PATCH 3/6] Remove some duplicate methods overwriting each other --- src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl b/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl index e59c16b..f2fc61d 100644 --- a/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl +++ b/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl @@ -22,13 +22,11 @@ function unpartitioned_graph_type(pg::Type{<:AbstractPartitionedGraph}) return not_implemented() end supervertex(pg::AbstractPartitionedGraph, vertex) = not_implemented() -supervertex(pg::AbstractPartitionedGraph, verts) = not_implemented() supervertex(pg::AbstractPartitionedGraph) = not_implemented() Base.copy(pg::AbstractPartitionedGraph) = not_implemented() delete_from_vertex_map!(pg::AbstractPartitionedGraph, vertex) = not_implemented() insert_to_vertex_map!(pg::AbstractPartitionedGraph, vertex) = not_implemented() superedge(pg::AbstractPartitionedGraph, edge) = not_implemented() -superedges(pg::AbstractPartitionedGraph, edges) = not_implemented() superedges(pg::AbstractPartitionedGraph) = not_implemented() function unpartitioned_graph_type(pg::AbstractPartitionedGraph) return typeof(unpartitioned_graph(pg)) From 345ef6b75ad449f1d4866cf3b11c1d65ee1c83bf Mon Sep 17 00:00:00 2001 From: Jack Dunham Date: Mon, 3 Nov 2025 16:52:50 -0500 Subject: [PATCH 4/6] Version bump --- Project.toml | 2 +- docs/Project.toml | 2 +- examples/Project.toml | 2 +- test/Project.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 7a69e9d..883294d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NamedGraphs" uuid = "678767b0-92e7-4007-89e4-4527a8725b19" authors = ["Matthew Fishman , Joseph Tindall and contributors"] -version = "0.7.4" +version = "0.8.0" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" diff --git a/docs/Project.toml b/docs/Project.toml index 16ff40a..2309122 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -6,4 +6,4 @@ NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19" [compat] Documenter = "1.10" Literate = "2.20.1" -NamedGraphs = "0.7" +NamedGraphs = "0.8" diff --git a/examples/Project.toml b/examples/Project.toml index 123e6c3..07edffc 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -4,4 +4,4 @@ NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19" [compat] Graphs = "1.12.0" -NamedGraphs = "0.7.0" +NamedGraphs = "0.8.0" diff --git a/test/Project.toml b/test/Project.toml index e75deaf..b78e64e 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -24,7 +24,7 @@ Graphs = "1.12" GraphsFlows = "0.1.1" KaHyPar = "0.3.1" Metis = "1.5.0" -NamedGraphs = "0.7.0" +NamedGraphs = "0.8.0" SafeTestsets = "0.1.0" SimpleGraphAlgorithms = "0.6.0" SimpleGraphConverter = "0.1.0" From c412e315b6a1bac5d49f51470fe8a4f7a5e4bdff Mon Sep 17 00:00:00 2001 From: Jack Dunham Date: Tue, 4 Nov 2025 09:50:51 -0500 Subject: [PATCH 5/6] Remove `quotient_graph` function in favour of a direct call to `QuotientGraph`. --- .../src/abstractpartitionedgraph.jl | 18 +++---- .../PartitionedGraphs/src/partitionedgraph.jl | 1 - .../PartitionedGraphs/src/quotientgraph.jl | 7 +-- test/test_partitionedgraph.jl | 47 +++++++++---------- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl b/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl index f2fc61d..da2ccb2 100644 --- a/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl +++ b/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl @@ -16,7 +16,7 @@ using ..NamedGraphs.GraphsExtensions: abstract type AbstractPartitionedGraph{V, PV} <: AbstractNamedGraph{V} end #Needed for interface -quotient_graph(pg::AbstractPartitionedGraph) = not_implemented() +QuotientGraph(pg::AbstractPartitionedGraph) = not_implemented() unpartitioned_graph(pg::AbstractPartitionedGraph) = not_implemented() function unpartitioned_graph_type(pg::Type{<:AbstractPartitionedGraph}) return not_implemented() @@ -73,11 +73,11 @@ end function Graphs.has_vertex( pg::AbstractPartitionedGraph, supervertex::AbstractSuperVertex ) - return has_vertex(quotient_graph(pg), parent(supervertex)) + return has_vertex(QuotientGraph(pg), parent(supervertex)) end function Graphs.has_edge(pg::AbstractPartitionedGraph, superedge::AbstractSuperEdge) - return has_edge(quotient_graph(pg), parent(superedge)) + return has_edge(QuotientGraph(pg), parent(superedge)) end function is_boundary_edge(pg::AbstractPartitionedGraph, edge::AbstractEdge) @@ -89,17 +89,17 @@ function Graphs.add_edge!(pg::AbstractPartitionedGraph, edge::AbstractEdge) add_edge!(unpartitioned_graph(pg), edge) pg_edge = parent(superedge(pg, edge)) if src(pg_edge) != dst(pg_edge) - add_edge!(quotient_graph(pg), pg_edge) + add_edge!(QuotientGraph(pg), pg_edge) end return pg end function Graphs.rem_edge!(pg::AbstractPartitionedGraph, edge::AbstractEdge) pg_edge = superedge(pg, edge) - if has_edge(quotient_graph(pg), pg_edge) + if has_edge(QuotientGraph(pg), pg_edge) g_edges = edges(pg, pg_edge) if length(g_edges) == 1 - rem_edge!(quotient_graph(pg), pg_edge) + rem_edge!(QuotientGraph(pg), pg_edge) end end return rem_edge!(unpartitioned_graph(pg), edge) @@ -116,7 +116,7 @@ function Graphs.add_vertex!( pg::AbstractPartitionedGraph, vertex, supervertex::AbstractSuperVertex ) add_vertex!(unpartitioned_graph(pg), vertex) - add_vertex!(quotient_graph(pg), parent(supervertex)) + add_vertex!(QuotientGraph(pg), parent(supervertex)) insert_to_vertex_map!(pg, vertex, supervertex) return pg end @@ -146,7 +146,7 @@ function Graphs.rem_vertex!(pg::AbstractPartitionedGraph, vertex) delete_from_vertex_map!(pg, sv, vertex) rem_vertex!(unpartitioned_graph(pg), vertex) if !haskey(partitioned_vertices(pg), parent(sv)) - rem_vertex!(quotient_graph(pg), parent(sv)) + rem_vertex!(QuotientGraph(pg), parent(sv)) end return pg end @@ -172,7 +172,7 @@ end function Base.:(==)(pg1::AbstractPartitionedGraph, pg2::AbstractPartitionedGraph) if unpartitioned_graph(pg1) != unpartitioned_graph(pg2) || - quotient_graph(pg1) != quotient_graph(pg2) + QuotientGraph(pg1) != QuotientGraph(pg2) return false end for v in vertices(pg1) diff --git a/src/lib/PartitionedGraphs/src/partitionedgraph.jl b/src/lib/PartitionedGraphs/src/partitionedgraph.jl index cbd0fce..a24349e 100644 --- a/src/lib/PartitionedGraphs/src/partitionedgraph.jl +++ b/src/lib/PartitionedGraphs/src/partitionedgraph.jl @@ -46,7 +46,6 @@ function PartitionedGraph(g::AbstractGraph; kwargs...) end #Needed for interface -quotient_graph(pg::PartitionedGraph) = QuotientGraph(pg) unpartitioned_graph(pg::PartitionedGraph) = getfield(pg, :graph) function unpartitioned_graph_type(graph_type::Type{<:PartitionedGraph}) return fieldtype(graph_type, :graph) diff --git a/src/lib/PartitionedGraphs/src/quotientgraph.jl b/src/lib/PartitionedGraphs/src/quotientgraph.jl index f319633..6e287e8 100644 --- a/src/lib/PartitionedGraphs/src/quotientgraph.jl +++ b/src/lib/PartitionedGraphs/src/quotientgraph.jl @@ -1,11 +1,12 @@ +using Graphs: AbstractGraph + struct QuotientGraph{V, G <: AbstractGraph{V}} <: AbstractNamedGraph{V} graph::G + QuotientGraph(g::G) where {V, G<:AbstractPartitionedGraph{V}} = new{V,G}(g) end Base.copy(g::QuotientGraph) = QuotientGraph(copy(g.graph)) - -using Graphs: AbstractGraph -quotient_graph(g::AbstractGraph) = QuotientGraph(PartitionedGraph(g, [vertices(g)])) +QuotientGraph(g::AbstractGraph) = QuotientGraph(PartitionedGraph(g, [vertices(g)])) # Graphs.jl and NamedGraphs.jl interface overloads for `PartitionsGraphView` wrapping # a `PartitionedGraph`. diff --git a/test/test_partitionedgraph.jl b/test/test_partitionedgraph.jl index ecf5b63..9124c98 100644 --- a/test/test_partitionedgraph.jl +++ b/test/test_partitionedgraph.jl @@ -35,12 +35,11 @@ using NamedGraphs.NamedGraphGenerators: named_comb_tree, named_grid, named_triangular_lattice_graph using NamedGraphs.OrderedDictionaries: OrderedDictionary using NamedGraphs.PartitionedGraphs: - SuperEdge, - SuperVertex, PartitionedGraph, QuotientGraph, + SuperEdge, + SuperVertex, boundary_superedges, - quotient_graph, superedge, superedges, supervertex, @@ -57,13 +56,13 @@ using Test: @test, @testset #Partition it column-wise (into a 1D chain) partitions = [[(i, j) for j in 1:ny] for i in 1:nx] pg = PartitionedGraph(g, partitions) - @test vertextype(quotient_graph(pg)) == Int64 + @test vertextype(QuotientGraph(pg)) == Int64 @test vertextype(unpartitioned_graph(pg)) == vertextype(g) @test isa(supervertices(pg), OrderedDictionary{Int64, SuperVertex{Int64}}) @test isa(superedges(pg), Vector{SuperEdge{Int64, NamedEdge{Int64}}}) - @test is_tree(quotient_graph(pg)) + @test is_tree(QuotientGraph(pg)) @test nv(pg) == nx * ny - @test nv(quotient_graph(pg)) == nx + @test nv(QuotientGraph(pg)) == nx pg_c = copy(pg) @test pg_c == pg @@ -79,7 +78,7 @@ using Test: @test, @testset #Same partitioning but with a dictionary constructor partition_dict = Dictionary([first(partition) for partition in partitions], partitions) pg = PartitionedGraph(g, partition_dict) - @test vertextype(quotient_graph(pg)) == vertextype(g) + @test vertextype(QuotientGraph(pg)) == vertextype(g) @test vertextype(unpartitioned_graph(pg)) == vertextype(g) @test isa( supervertices(pg), @@ -89,19 +88,19 @@ using Test: @test, @testset superedges(pg), Vector{SuperEdge{Tuple{Int64, Int64}, NamedEdge{Tuple{Int64, Int64}}}}, ) - @test is_tree(quotient_graph(pg)) + @test is_tree(QuotientGraph(pg)) @test nv(pg) == nx * ny - @test nv(quotient_graph(pg)) == nx + @test nv(QuotientGraph(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]) - @test unpartitioned_graph(pg) == quotient_graph(pg) + @test unpartitioned_graph(pg) == QuotientGraph(pg) @test nv(pg) == nx - @test nv(quotient_graph(pg)) == nx + @test nv(QuotientGraph(pg)) == nx @test ne(pg) == 0 - @test ne(quotient_graph(pg)) == 0 + @test ne(QuotientGraph(pg)) == 0 pg_c = copy(pg) @test pg_c == pg end @@ -147,22 +146,22 @@ end #Strip the middle column from pg via the partitioned graph vertex, and make a new pg rem_vertex!(pg, pv) - @test !is_connected(unpartitioned_graph(pg)) && !is_connected(quotient_graph(pg)) - @test parent(pv) ∉ vertices(quotient_graph(pg)) + @test !is_connected(unpartitioned_graph(pg)) && !is_connected(QuotientGraph(pg)) + @test parent(pv) ∉ vertices(QuotientGraph(pg)) @test !has_vertex(pg, pv) @test nv(pg) == (nx - 1) * ny - @test nv(quotient_graph(pg)) == nx - 1 - @test !is_tree(quotient_graph(pg)) + @test nv(QuotientGraph(pg)) == nx - 1 + @test !is_tree(QuotientGraph(pg)) #Add the column back to the in place graph add_vertices!(pg, v_set, pv) add_edges!(pg, edges_involving_v_set) - @test is_connected(pg.graph) && is_path_graph(quotient_graph(pg)) - @test parent(pv) ∈ vertices(quotient_graph(pg)) + @test is_connected(pg.graph) && is_path_graph(QuotientGraph(pg)) + @test parent(pv) ∈ vertices(QuotientGraph(pg)) @test has_vertex(pg, pv) - @test is_tree(quotient_graph(pg)) + @test is_tree(QuotientGraph(pg)) @test nv(pg) == nx * ny - @test nv(quotient_graph(pg)) == nx + @test nv(QuotientGraph(pg)) == nx end @testset "Test Partitioned Graph Subgraph Functionality" begin @@ -184,7 +183,7 @@ end pg_2 = subgraph(pg, subgraph_vertices) @test pg_1 == pg_2 @test nv(pg_1) == length(subgraph_vertices) - @test nv(quotient_graph(pg_1)) == length(subgraph_partitioned_vertices) + @test nv(QuotientGraph(pg_1)) == length(subgraph_partitioned_vertices) subgraph_partitioned_vertex = 3 subgraph_vertices = partitions[subgraph_partitioned_vertex] @@ -207,9 +206,9 @@ end pg = PartitionedGraph(g, [vertices(g)]) @test f(pg) == f(unpartitioned_graph(pg)) @test nv(pg) == nv(g) - @test nv(quotient_graph(pg)) == 1 + @test nv(QuotientGraph(pg)) == 1 @test ne(pg) == ne(g) - @test ne(quotient_graph(pg)) == 0 + @test ne(QuotientGraph(pg)) == 0 end end end @@ -226,7 +225,7 @@ end for backend in backends pg = PartitionedGraph(g; npartitions, backend = "metis") @test pg isa PartitionedGraph - @test nv(quotient_graph(pg)) == npartitions + @test nv(QuotientGraph(pg)) == npartitions end end end From 2791da436c9c71ffe5bf64cd4637f0ef7d9f8766 Mon Sep 17 00:00:00 2001 From: Jack Dunham Date: Tue, 4 Nov 2025 09:57:43 -0500 Subject: [PATCH 6/6] Runic formatting --- src/lib/PartitionedGraphs/src/quotientgraph.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/PartitionedGraphs/src/quotientgraph.jl b/src/lib/PartitionedGraphs/src/quotientgraph.jl index 6e287e8..e8a0198 100644 --- a/src/lib/PartitionedGraphs/src/quotientgraph.jl +++ b/src/lib/PartitionedGraphs/src/quotientgraph.jl @@ -1,8 +1,8 @@ using Graphs: AbstractGraph -struct QuotientGraph{V, G <: AbstractGraph{V}} <: AbstractNamedGraph{V} +struct QuotientGraph{V, G <: AbstractPartitionedGraph{V}} <: AbstractNamedGraph{V} graph::G - QuotientGraph(g::G) where {V, G<:AbstractPartitionedGraph{V}} = new{V,G}(g) + QuotientGraph(g::G) where {V, G <: AbstractPartitionedGraph{V}} = new{V, G}(g) end Base.copy(g::QuotientGraph) = QuotientGraph(copy(g.graph))