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
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.1.3"
[deps]
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
GraphsFlows = "06909019-6f44-4949-96fc-b9d9aaa02889"
NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19"
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"

Expand Down
50 changes: 34 additions & 16 deletions src/DataGraphs.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module DataGraphs
using Dictionaries
using Graphs
using GraphsFlows
using NamedGraphs
using SimpleTraits

Expand All @@ -24,21 +25,32 @@ import Base:
vcat,
union,
zero

import Graphs:
a_star,
adjacency_matrix,
add_edge!,
add_vertex!,
bellman_ford_shortest_paths,
bfs_parents,
bfs_tree,
boruvka_mst,
center,
common_neighbors,
connected_components,
connected_components!,
degree,
degree_histogram,
desopo_pape_shortest_paths,
dfs_parents,
dfs_tree,
diameter,
dijkstra_shortest_paths,
eccentricity,
edges,
edgetype,
enumerate_paths,
floyd_warshall_shortest_paths,
has_edge,
has_path,
has_vertex,
Expand All @@ -49,41 +61,48 @@ import Graphs:
is_directed,
is_strongly_connected,
is_weakly_connected,
johnson_shortest_paths,
kruskal_mst,
merge_vertices,
merge_vertices!,
mincut,
ne,
neighbors,
neighborhood,
neighborhood_dists,
a_star,
bellman_ford_shortest_paths,
enumerate_paths,
desopo_pape_shortest_paths,
dijkstra_shortest_paths,
floyd_warshall_shortest_paths,
johnson_shortest_paths,
spfa_shortest_paths,
yen_k_shortest_paths,
boruvka_mst,
kruskal_mst,
prim_mst,
nv,
outneighbors,
periphery,
prim_mst,
radius,
rem_edge!,
rem_vertex!,
reverse,
vertices
spfa_shortest_paths,
steiner_tree,
topological_sort_by_dfs,
tree,
vertices,
yen_k_shortest_paths

# TODO: Can we remove the dependency on `NamedGraphs`?
# Maybe need a `GraphExtensions.jl` or
# `GraphInterfaces.jl` package.
import NamedGraphs:
⊔,
boundary_edges,
boundary_vertices,
convert_vertextype,
directed_graph,
disjoint_union,
eccentricities,
incident_edges,
inner_boundary_vertices,
outer_boundary_vertices,
mincut_partitions,
rename_vertices,
symrcm,
symrcm_permute,
vertextype

# General functions
Expand All @@ -98,13 +117,12 @@ include("datagraph.jl")
#

export DataGraph,
vertex_type,
directed_graph,
AbstractDataGraph,
directed_graph,
disjoint_union,
map_vertex_data,
map_edge_data,
map_data,
disjoint_union,

end # module DataGraphs
51 changes: 43 additions & 8 deletions src/abstractdatagraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,64 @@ zero(G::Type{<:AbstractDataGraph}) = G()

# Graphs overloads
for f in [
:a_star,
:add_edge!,
:add_vertex!,
:adjacency_matrix,
:bellman_ford_shortest_paths,
:bfs_parents,
:bfs_tree,
:boundary_edges,
:boundary_vertices,
:boruvka_mst,
:center,
:common_neighbors,
:degree,
:degree_histogram,
:desopo_pape_shortest_paths,
:dfs_parents,
:dfs_tree,
:diameter,
:dijkstra_shortest_paths,
:eccentricity,
:eccentricities,
:edges,
:edgetype,
:eltype,
:enumerate_paths,
:floyd_warshall_shortest_paths,
:has_edge,
:has_path,
:has_vertex,
:inneighbors,
:inner_boundary_vertices,
:is_connected,
:is_cyclic,
:is_directed,
:is_strongly_connected,
:is_weakly_connected,
:mincut,
:(GraphsFlows.mincut),
:mincut_partitions,
:ne,
:neighbors,
:neighborhood,
:neighborhood_dists,
:a_star,
:bellman_ford_shortest_paths,
:enumerate_paths,
:desopo_pape_shortest_paths,
:dijkstra_shortest_paths,
:floyd_warshall_shortest_paths,
:outer_boundary_vertices,
:johnson_shortest_paths,
:spfa_shortest_paths,
:yen_k_shortest_paths,
:boruvka_mst,
:kruskal_mst,
:prim_mst,
:nv,
:outneighbors,
:periphery,
:radius,
:symrcm,
:symrcm_permute,
:steiner_tree,
:topological_sort_by_dfs,
:tree,
:vertices,
]
@eval begin
Expand All @@ -72,6 +90,11 @@ for f in [
end
end

# Fix for ambiguity error with `AbstractGraph` version
function eccentricity(graph::AbstractDataGraph, distmx::AbstractMatrix)
return eccentricity(underlying_graph(graph), distmx)
end

@traitfn directed_graph(graph::AbstractDataGraph::IsDirected) = graph

@traitfn function directed_graph(graph::AbstractDataGraph::(!IsDirected))
Expand Down Expand Up @@ -151,6 +174,16 @@ function union(
return DataGraph(underlying_graph_union, vertex_data_merge, edge_data_merge)
end

function union(
graph1::AbstractDataGraph,
graph2::AbstractDataGraph,
graph3::AbstractDataGraph,
graphs_tail::AbstractDataGraph...;
kwargs...,
)
return union(union(graph1, graph2; kwargs...), graph3, graphs_tail...; kwargs...)
end

function rename_vertices(f::Function, graph::AbstractDataGraph)
renamed_underlying_graph = rename_vertices(f, underlying_graph(graph))
# TODO: Base the ouput type on `typeof(graph)`, for example:
Expand Down Expand Up @@ -215,7 +248,9 @@ function map_edge_data(f, graph::AbstractDataGraph; edges=nothing)
graph′ = copy(graph)
es = isnothing(edges) ? Graphs.edges(graph) : edges
for e in es
graph′[e] = f(graph[e])
if isassigned(graph, e)
graph′[e] = f(graph[e])
end
end
return graph′
end
Expand Down