From f479612346761ccc7946216f254c100446d8e650 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Tue, 13 Dec 2022 20:16:12 -0500 Subject: [PATCH 1/5] Add mincut --- Project.toml | 1 + src/DataGraphs.jl | 3 +++ src/abstractdatagraph.jl | 3 +++ 3 files changed, 7 insertions(+) diff --git a/Project.toml b/Project.toml index b14ce75..e5d622b 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/DataGraphs.jl b/src/DataGraphs.jl index c280c4f..3f8824c 100644 --- a/src/DataGraphs.jl +++ b/src/DataGraphs.jl @@ -1,6 +1,7 @@ module DataGraphs using Dictionaries using Graphs +using GraphsFlows using NamedGraphs using SimpleTraits @@ -51,6 +52,7 @@ import Graphs: is_weakly_connected, merge_vertices, merge_vertices!, + mincut, ne, neighbors, neighborhood, @@ -83,6 +85,7 @@ import NamedGraphs: directed_graph, disjoint_union, incident_edges, + mincut_partitions, rename_vertices, vertextype diff --git a/src/abstractdatagraph.jl b/src/abstractdatagraph.jl index 45768e9..ea35eea 100644 --- a/src/abstractdatagraph.jl +++ b/src/abstractdatagraph.jl @@ -45,6 +45,9 @@ for f in [ :is_directed, :is_strongly_connected, :is_weakly_connected, + :mincut, + :(GraphsFlows.mincut), + :mincut_partitions, :ne, :neighbors, :neighborhood, From c01128b8102ae4af478f7fa1c087ee262ef7cb05 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 15 Dec 2022 22:22:43 -0500 Subject: [PATCH 2/5] Dijkstra, center, radius, etc. --- src/DataGraphs.jl | 30 +++++++++++++++++++----------- src/abstractdatagraph.jl | 26 +++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/DataGraphs.jl b/src/DataGraphs.jl index 3f8824c..43d496b 100644 --- a/src/DataGraphs.jl +++ b/src/DataGraphs.jl @@ -25,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, @@ -50,6 +61,7 @@ import Graphs: is_directed, is_strongly_connected, is_weakly_connected, + johnson_shortest_paths, merge_vertices, merge_vertices!, mincut, @@ -57,23 +69,19 @@ import Graphs: 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, + periphery, + radius, spfa_shortest_paths, yen_k_shortest_paths, - boruvka_mst, kruskal_mst, prim_mst, nv, outneighbors, + periphery, rem_edge!, rem_vertex!, reverse, + tree, vertices # TODO: Can we remove the dependency on `NamedGraphs`? @@ -84,6 +92,7 @@ import NamedGraphs: convert_vertextype, directed_graph, disjoint_union, + eccentricities, incident_edges, mincut_partitions, rename_vertices, @@ -101,13 +110,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 diff --git a/src/abstractdatagraph.jl b/src/abstractdatagraph.jl index ea35eea..b42876f 100644 --- a/src/abstractdatagraph.jl +++ b/src/abstractdatagraph.jl @@ -28,11 +28,15 @@ for f in [ :adjacency_matrix, :bfs_parents, :bfs_tree, + :center, :common_neighbors, :degree, :degree_histogram, :dfs_parents, :dfs_tree, + :diameter, + :eccentricity, + :eccentricities, :edges, :edgetype, :eltype, @@ -66,6 +70,9 @@ for f in [ :prim_mst, :nv, :outneighbors, + :periphery, + :radius, + :tree, :vertices, ] @eval begin @@ -75,6 +82,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)) @@ -154,6 +166,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: @@ -218,7 +240,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 From ffb886fbaa9546c2cb751582eb3f648460bf7efa Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 19 Dec 2022 17:22:24 -0500 Subject: [PATCH 3/5] Add symrcm and boundary vertex and edge methods --- src/DataGraphs.jl | 6 ++++++ src/abstractdatagraph.jl | 20 +++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/DataGraphs.jl b/src/DataGraphs.jl index 43d496b..96c9104 100644 --- a/src/DataGraphs.jl +++ b/src/DataGraphs.jl @@ -89,13 +89,19 @@ import Graphs: # `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 diff --git a/src/abstractdatagraph.jl b/src/abstractdatagraph.jl index b42876f..564efff 100644 --- a/src/abstractdatagraph.jl +++ b/src/abstractdatagraph.jl @@ -23,27 +23,37 @@ 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, @@ -56,22 +66,18 @@ for f in [ :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, :tree, :vertices, ] From 18a8b3869323c0949439362821eb1a85f08dd149 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Tue, 20 Dec 2022 18:01:07 -0500 Subject: [PATCH 4/5] Wrapper for steiner_tree --- src/DataGraphs.jl | 1 + src/abstractdatagraph.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/src/DataGraphs.jl b/src/DataGraphs.jl index 96c9104..fad2712 100644 --- a/src/DataGraphs.jl +++ b/src/DataGraphs.jl @@ -81,6 +81,7 @@ import Graphs: rem_edge!, rem_vertex!, reverse, + steiner_tree, tree, vertices diff --git a/src/abstractdatagraph.jl b/src/abstractdatagraph.jl index 564efff..2bb1fdd 100644 --- a/src/abstractdatagraph.jl +++ b/src/abstractdatagraph.jl @@ -78,6 +78,7 @@ for f in [ :radius, :symrcm, :symrcm_permute, + :steiner_tree, :tree, :vertices, ] From 0c42802da9861784012027da9cae8852d18489bf Mon Sep 17 00:00:00 2001 From: mtfishman Date: Tue, 20 Dec 2022 19:05:13 -0500 Subject: [PATCH 5/5] Add topological_sort_by_dfs --- src/DataGraphs.jl | 14 +++++++------- src/abstractdatagraph.jl | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/DataGraphs.jl b/src/DataGraphs.jl index fad2712..2ea115d 100644 --- a/src/DataGraphs.jl +++ b/src/DataGraphs.jl @@ -62,6 +62,7 @@ import Graphs: is_strongly_connected, is_weakly_connected, johnson_shortest_paths, + kruskal_mst, merge_vertices, merge_vertices!, mincut, @@ -69,21 +70,20 @@ import Graphs: neighbors, neighborhood, neighborhood_dists, - periphery, - radius, - spfa_shortest_paths, - yen_k_shortest_paths, - kruskal_mst, - prim_mst, nv, outneighbors, periphery, + prim_mst, + radius, rem_edge!, rem_vertex!, reverse, + spfa_shortest_paths, steiner_tree, + topological_sort_by_dfs, tree, - vertices + vertices, + yen_k_shortest_paths # TODO: Can we remove the dependency on `NamedGraphs`? # Maybe need a `GraphExtensions.jl` or diff --git a/src/abstractdatagraph.jl b/src/abstractdatagraph.jl index 2bb1fdd..de30117 100644 --- a/src/abstractdatagraph.jl +++ b/src/abstractdatagraph.jl @@ -79,6 +79,7 @@ for f in [ :symrcm, :symrcm_permute, :steiner_tree, + :topological_sort_by_dfs, :tree, :vertices, ]