Skip to content

Commit

Permalink
Add more wrappers for Graphs.jl functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Dec 9, 2022
2 parents 04a3442 + 091cb7d commit 9c65e39
Show file tree
Hide file tree
Showing 5 changed files with 498 additions and 69 deletions.
12 changes: 12 additions & 0 deletions src/Graphs/abstractgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ function subgraph(f::Function, graph::AbstractGraph)
return induced_subgraph(graph, filter(f, vertices(graph)))[1]
end

function degrees(graph::AbstractGraph, vertices=vertices(graph))
return map(vertex -> degree(graph, vertex), vertices)
end

function indegrees(graph::AbstractGraph, vertices=vertices(graph))
return map(vertex -> indegree(graph, vertex), vertices)
end

function outdegrees(graph::AbstractGraph, vertices=vertices(graph))
return map(vertex -> outdegree(graph, vertex), vertices)
end

# Used for tree iteration.
# Assumes the graph is a [rooted directed tree](https://en.wikipedia.org/wiki/Tree_(graph_theory)#Rooted_tree).
struct TreeGraph{G,V}
Expand Down
30 changes: 28 additions & 2 deletions src/NamedGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ import Graphs:
bfs_parents,
bfs_tree,
blockdiag,
common_neighbors,
degree,
degree_histogram,
dst,
dfs_parents,
dfs_tree,
edges,
edgetype,
has_edge,
has_path,
has_vertex,
indegree,
induced_subgraph,
inneighbors,
is_connected,
Expand All @@ -35,6 +40,21 @@ import Graphs:
is_weakly_connected,
ne,
neighbors,
neighborhood,
neighborhood_dists,
outdegree,
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,
rem_vertex!,
Expand All @@ -43,11 +63,11 @@ import Graphs:
tree,
vertices

import Base: show, eltype, copy, getindex, convert, hcat, vcat, hvncat, union
import Base: show, eltype, copy, getindex, convert, hcat, vcat, hvncat, union, zero

# abstractnamededge.jl
import Base: Pair, Tuple, show, ==, hash, eltype, convert
import Graphs: AbstractEdge, src, dst, reverse
import Graphs: AbstractEdge, src, dst, reverse, reverse!

include(joinpath("Dictionaries", "dictionary.jl"))
include(joinpath("Graphs", "abstractgraph.jl"))
Expand Down Expand Up @@ -75,6 +95,12 @@ export NamedGraph,
post_order_dfs_vertices,
post_order_dfs_edges,
rename_vertices,
degree,
degrees,
indegree,
indegrees,
outdegree,
outdegrees,
# Operations for tree-like graphs
is_leaf,
is_tree,
Expand Down
Loading

0 comments on commit 9c65e39

Please sign in to comment.