Skip to content

Commit

Permalink
Removed implementation of directed(partitioned)graph). Better has_ver…
Browse files Browse the repository at this point in the history
…tex(pg) functionality
  • Loading branch information
JoeyT1994 committed Jan 3, 2024
1 parent 3c996dd commit 4d627cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
13 changes: 7 additions & 6 deletions src/Graphs/partitionedgraphs/abstractpartitionedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ abstract type AbstractPartitionedGraph{V,PV} <: AbstractNamedGraph{V} end
partitioned_graph(pg::AbstractPartitionedGraph) = not_implemented()
unpartitioned_graph(pg::AbstractPartitionedGraph) = not_implemented()
which_partition(pg::AbstractPartitionedGraph, vertex) = not_implemented()
partitioned_vertices(pg::AbstractPartitionedGraph) = not_implemented()
copy(pg::AbstractPartitionedGraph) = not_implemented()
delete_from_vertex_map!(pg::AbstractPartitionedGraph, vertex) = not_implemented()
insert_to_vertex_map!(pg::AbstractPartitionedGraph, vertex) = not_implemented()
Expand All @@ -17,9 +18,9 @@ function vertices(
) where {V<:AbstractPartitionVertex}
return not_implemented()
end
parent_graph_type(G::Type{<:AbstractPartitionedGraph}) = not_implemented()
directed_graph_type(G::Type{<:AbstractPartitionedGraph}) = not_implemented()
undirected_graph_type(G::Type{<:AbstractPartitionedGraph}) = not_implemented()
parent_graph_type(PG::Type{<:AbstractPartitionedGraph}) = not_implemented()
directed_graph_type(PG::Type{<:AbstractPartitionedGraph}) = not_implemented()
undirected_graph_type(PG::Type{<:AbstractPartitionedGraph}) = not_implemented()

#Functions for the abstract type
vertices(pg::AbstractPartitionedGraph) = vertices(unpartitioned_graph(pg))
Expand All @@ -30,9 +31,9 @@ end
edgetype(pg::AbstractPartitionedGraph) = edgetype(unpartitioned_graph(pg))
parent_graph_type(pg::AbstractPartitionedGraph) = parent_graph_type(unpartitioned_graph(pg))
nv(pg::AbstractPartitionedGraph, pv::AbstractPartitionVertex) = length(vertices(pg, pv))

function has_vertex(pg::AbstractPartitionedGraph, partition_vertex::AbstractPartitionVertex)
return has_vertex(partitioned_graph(pg), parent(partition_vertex))
return haskey(partitioned_vertices(pg), parent(partition_vertex)) &&
has_vertex(partitioned_graph(pg), parent(partition_vertex))
end
function has_edge(pg::AbstractPartitionedGraph, edge::AbstractPartitionEdge)
return has_edge(partitioned_graph(pg), parent(partition_edge))
Expand Down Expand Up @@ -126,7 +127,7 @@ function rem_vertex!(pg::AbstractPartitionedGraph, vertex)
pv = which_partition(pg, vertex)
delete_from_vertex_map!(pg, pv, vertex)
rem_vertex!(unpartitioned_graph(pg), vertex)
if iszero(nv(pg, pv))
if !haskey(partitioned_vertices(pg), parent(pv))
rem_vertex!(partitioned_graph(pg), parent(pv))
end
return pg
Expand Down
12 changes: 1 addition & 11 deletions src/Graphs/partitionedgraphs/partitionedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,8 @@ unpartitioned_graph(pg::PartitionedGraph) = getfield(pg, :graph)
partitioned_vertices(pg::PartitionedGraph) = getfield(pg, :partitioned_vertices)
which_partition(pg::PartitionedGraph) = getfield(pg, :which_partition)
parent_graph_type(PG::Type{<:PartitionedGraph}) = fieldtype(PG, :graph)
function directed_graph_type(PG::Type{<:PartitionedGraph})
return directed_graph_type(fieldtype(PG, :graph))
end
function undirected_graph_type(PG::Type{<:PartitionedGraph})
return undirected_graph_type(fieldtype(PG, :graph))
end
function vertices(pg::PartitionedGraph, partition_vert::PartitionVertex)
if haskey(partitioned_vertices(pg), parent(partition_vert))
return partitioned_vertices(pg)[parent(partition_vert)]
else
return []
end
return partitioned_vertices(pg)[parent(partition_vert)]
end
function vertices(pg::PartitionedGraph, partition_verts::Vector{<:PartitionVertex})
return unique(reduce(vcat, [vertices(pg, pv) for pv in partition_verts]))
Expand Down
10 changes: 1 addition & 9 deletions test/test_partitionedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,7 @@ end
end

@testset "Test NamedGraphs Functions on Partitioned Graph" begin
functions = [
is_tree,
NamedGraphs.default_root_vertex,
spanning_tree,
spanning_forest,
center,
diameter,
radius,
]
functions = [is_tree, NamedGraphs.default_root_vertex, center, diameter, radius]
gs = [
named_comb_tree((4, 4)),
named_grid((2, 2, 2)),
Expand Down

0 comments on commit 4d627cd

Please sign in to comment.