Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DataGraphs"
uuid = "b5a273c3-7e6c-41f6-98bd-8d7f1525a36a"
version = "0.2.12"
authors = ["Matthew Fishman <mfishman@flatironinstitute.org> and contributors"]
version = "0.2.13"

[deps]
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
Expand All @@ -19,7 +19,7 @@ DataGraphsGraphsFlowsExt = "GraphsFlows"
Dictionaries = "0.4"
Graphs = "1"
GraphsFlows = "0.1.1"
NamedGraphs = "0.6.9, 0.7, 0.8"
NamedGraphs = "0.8.2"
SimpleTraits = "0.9"
julia = "1.7"

Expand Down
17 changes: 15 additions & 2 deletions src/abstractdatagraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ edge_data_eltype(graph::AbstractDataGraph) = eltype(edge_data(graph))

Base.zero(graph_type::Type{<:AbstractDataGraph}) = graph_type()

# Graphs overloads
function Graphs.vertices(graph::AbstractDataGraph)
return Graphs.vertices(underlying_graph(graph))
end

# Graphs overloads
for f in [
:(Graphs.a_star),
Expand Down Expand Up @@ -92,7 +97,6 @@ for f in [
:(Graphs.steiner_tree),
:(Graphs.topological_sort_by_dfs),
:(Graphs.tree),
:(Graphs.vertices),
:(GraphsExtensions.boundary_edges),
:(GraphsExtensions.boundary_vertices),
:(GraphsExtensions.eccentricities),
Expand Down Expand Up @@ -402,7 +406,7 @@ function Base.setindex!(graph::AbstractDataGraph, x, i1, i2, i...)
return graph
end

function Graphs.induced_subgraph(graph::AbstractDataGraph, subvertices)
function induced_subgraph_datagraph(graph::AbstractDataGraph, subvertices)
underlying_subgraph, vlist = Graphs.induced_subgraph(underlying_graph(graph), subvertices)
subgraph = similar_type(graph)(underlying_subgraph)
for v in vertices(subgraph)
Expand All @@ -417,6 +421,15 @@ function Graphs.induced_subgraph(graph::AbstractDataGraph, subvertices)
end
return subgraph, vlist
end
function Graphs.induced_subgraph(graph::AbstractDataGraph, subvertices)
return induced_subgraph_datagraph(graph, subvertices)
end
# Fix ambiguity with Graphs.jl for integer `subvertices`.
function Graphs.induced_subgraph(
graph::AbstractDataGraph, subvertices::AbstractVector{<:Integer}
)
return induced_subgraph_datagraph(graph, subvertices)
end

#
# Printing
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DataGraphs = "0.2.6"
Dictionaries = "0.4.4"
Graphs = "1.12"
GraphsFlows = "0.1.1"
NamedGraphs = "0.6.6, 0.7, 0.8"
NamedGraphs = "0.8.2"
SafeTestsets = "0.1"
Suppressor = "0.2.8"
Test = "1.10"
36 changes: 35 additions & 1 deletion test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using Graphs:
using Graphs.SimpleGraphs: SimpleDiGraph, SimpleEdge, SimpleGraph
using GraphsFlows: GraphsFlows
using NamedGraphs: NamedDiGraph, NamedEdge, NamedGraph
using NamedGraphs.GraphsExtensions: ⊔, rename_vertices, vertextype
using NamedGraphs.GraphsExtensions: ⊔, rename_vertices, subgraph, vertextype
using NamedGraphs.NamedGraphGenerators: named_grid, named_path_graph
using NamedGraphs.OrdinalIndexing: nd, st, rd, th
using Test: @test, @test_broken, @testset
Expand Down Expand Up @@ -193,6 +193,40 @@ using Test: @test, @test_broken, @testset
@test dg[1 => 2] == :default
end

@testset "subgraph" begin
dg = DataGraph(named_path_graph(4))
dg[1] = "V1"
dg[2] = "V2"
dg[3] = "V3"
dg[4] = "V4"
dg[1 => 2] = "E12"
dg[2 => 3] = "E23"
dg[3 => 4] = "E34"
sg = subgraph(dg, [2, 3, 4])
@test nv(sg) == 3
@test ne(sg) == 2
@test !has_vertex(sg, 1)
@test has_vertex(sg, 2)
@test has_vertex(sg, 3)
@test has_vertex(sg, 4)
@test !has_edge(sg, 1 => 2)
@test !has_edge(sg, 2 => 1)
@test has_edge(sg, 2 => 3)
@test has_edge(sg, 3 => 2)
@test has_edge(sg, 3 => 4)
@test has_edge(sg, 4 => 3)
@test isnothing(get(sg, 1, nothing))
@test sg[2] == "V2"
@test sg[3] == "V3"
@test sg[4] == "V4"
@test isnothing(get(sg, 1 => 2, nothing))
@test isnothing(get(sg, 2 => 1, nothing))
@test sg[2 => 3] == "E23"
@test sg[3 => 2] == "E23"
@test sg[3 => 4] == "E34"
@test sg[4 => 3] == "E34"
end

@testset "Constructors specifying vertex type" begin
dg = DataGraph{Float64}(
named_path_graph(4); vertex_data_eltype = String, edge_data_eltype = Symbol
Expand Down
Loading