Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NamedGraphs"
uuid = "678767b0-92e7-4007-89e4-4527a8725b19"
authors = ["Matthew Fishman <[email protected]>, Joseph Tindall <[email protected]> and contributors"]
version = "0.7.4"
version = "0.8.0"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19"
[compat]
Documenter = "1.10"
Literate = "2.20.1"
NamedGraphs = "0.7"
NamedGraphs = "0.8"
2 changes: 1 addition & 1 deletion examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19"

[compat]
Graphs = "1.12.0"
NamedGraphs = "0.7.0"
NamedGraphs = "0.8.0"
10 changes: 5 additions & 5 deletions src/lib/PartitionedGraphs/src/PartitionedGraphs.jl
Original file line number Diff line number Diff line change
@@ -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
11 changes: 0 additions & 11 deletions src/lib/PartitionedGraphs/src/abstractpartitionedge.jl

This file was deleted.

94 changes: 46 additions & 48 deletions src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,31 @@ 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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a slight nitpick, but could you rename this to quotientgraph? My reasoning is that generally this will construct a QuotientGraph, so we can think of it as the lowercase function version of QuotientGraph.

In fact to simplify things right now maybe we could just use QuotientGraph directly and get rid of the function version... I think we introduced that function since PartitionsGraphView was a long name to write out, but QuotientGraph is easy to write. @jack-dunham @JoeyT1994 curious to hear your thoughts on that (best to decide now while we are making a breaking change...).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the function is unnecessary especially as QuotientGraph is intended a wrapper type. I also think using the constructor directly is clearer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's go with that, we can always add a function back if needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add a (very simple) inner constructor to avoid recursion, so now QuotientGraph must wrap an AbstractPartitionedGraph. Passing an AbstractGraph that does not subtype AbstractPartitionedGraph still passes the trivial partition of this graph to QuotientGraph, as before.

All tests pass on my end.

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) = 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) = 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})
Expand All @@ -69,102 +67,102 @@ 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(partitions_graph(pg), parent(partitionvertex))
return has_vertex(quotient_graph(pg), parent(supervertex))
end

function Graphs.has_edge(pg::AbstractPartitionedGraph, partitionedge::AbstractPartitionEdge)
return has_edge(partitions_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!(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)
pg_edge = superedge(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)
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!(partitions_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!(partitions_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

Expand All @@ -174,25 +172,25 @@ 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)
if partitionvertex(pg1, v) != partitionvertex(pg2, v)
if supervertex(pg1, v) != supervertex(pg2, v)
return false
end
end
return true
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
4 changes: 0 additions & 4 deletions src/lib/PartitionedGraphs/src/abstractpartitionvertex.jl

This file was deleted.

11 changes: 11 additions & 0 deletions src/lib/PartitionedGraphs/src/abstractsuperedge.jl
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions src/lib/PartitionedGraphs/src/abstractsupervertex.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
abstract type AbstractSuperVertex{V} <: Any where {V} end

#Parent, wrap, unwrap, vertex?
Base.parent(sv::AbstractSuperVertex) = not_implemented()
12 changes: 0 additions & 12 deletions src/lib/PartitionedGraphs/src/partitionedge.jl

This file was deleted.

Loading
Loading