Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 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()
QuotientGraph(pg::AbstractPartitionedGraph) = not_implemented()
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(QuotientGraph(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(QuotientGraph(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!(QuotientGraph(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(QuotientGraph(pg), pg_edge)
g_edges = edges(pg, pg_edge)
if length(g_edges) == 1
rem_edge!(partitions_graph(pg), pg_edge)
rem_edge!(QuotientGraph(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!(QuotientGraph(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!(QuotientGraph(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)
QuotientGraph(pg1) != QuotientGraph(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