Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Nov 7, 2024
2 parents 47598e3 + 9cb7190 commit 8da3920
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 7 deletions.
3 changes: 1 addition & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NamedGraphs"
uuid = "678767b0-92e7-4007-89e4-4527a8725b19"
authors = ["Matthew Fishman <[email protected]> and contributors"]
version = "0.6.0"
version = "0.6.2"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down Expand Up @@ -36,7 +36,6 @@ KaHyPar = "0.3.1"
LinearAlgebra = "1.7"
Metis = "1.4"
PackageExtensionCompat = "1"
Random = "1.7"
SimpleTraits = "0.9"
SparseArrays = "1.7"
SplitApplyCombine = "1.2.2"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ julia> ] add NamedGraphs



This packages introduces graph types with named edges, which are built on top of the `Graph`/`SimpleGraph` type in the [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl) package that only have contiguous integer edges (i.e. linear indexing).
This packages introduces graph types with named vertices, which are built on top of the `Graph`/`SimpleGraph` type in the [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl) package that only have contiguous integer vertices (i.e. linear indexing). The vertex names can be strings, tuples of integers, or other unique identifiers (anything that is hashable).



Expand Down
2 changes: 1 addition & 1 deletion examples/README.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#' ## Introduction

#' This packages introduces graph types with named edges, which are built on top of the `Graph`/`SimpleGraph` type in the [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl) package that only have contiguous integer edges (i.e. linear indexing).
#' This packages introduces graph types with named vertices, which are built on top of the `Graph`/`SimpleGraph` type in the [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl) package that only have contiguous integer vertices (i.e. linear indexing). The vertex names can be strings, tuples of integers, or other unique identifiers (anything that is hashable).

#' There is a supertype `AbstractNamedGraph` that defines an interface and fallback implementations of standard
#' Graphs.jl operations, and two implementations: `NamedGraph` and `NamedDiGraph`.
Expand Down
1 change: 1 addition & 0 deletions src/lib/GraphsExtensions/src/GraphsExtensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module GraphsExtensions
include("abstractgraph.jl")
include("abstracttrees.jl")
include("boundary.jl")
include("neighbors.jl")
include("shortestpaths.jl")
include("symrcm.jl")
include("partitioning.jl")
Expand Down
8 changes: 8 additions & 0 deletions src/lib/GraphsExtensions/src/neighbors.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Graphs: AbstractGraph, neighborhood_dists

function vertices_at_distance(g::AbstractGraph, vertex, distance::Int)
vertices_and_distances = neighborhood_dists(g, vertex, distance)
return map(first, filter(==(distance) last, vertices_and_distances))
end

next_nearest_neighbors(g::AbstractGraph, v) = vertices_at_distance(g, v, 2)
11 changes: 10 additions & 1 deletion src/lib/GraphsExtensions/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ using NamedGraphs.GraphsExtensions:
is_self_loop,
leaf_vertices,
minimum_distance_to_leaves,
next_nearest_neighbors,
non_leaf_edges,
outdegrees,
permute_vertices,
Expand All @@ -81,7 +82,8 @@ using NamedGraphs.GraphsExtensions:
tree_graph_node,
undirected_graph,
undirected_graph_type,
vertextype
vertextype,
vertices_at_distance
using Test: @test, @test_broken, @test_throws, @testset

# TODO: Still need to test:
Expand Down Expand Up @@ -579,5 +581,12 @@ using Test: @test, @test_broken, @test_throws, @testset
g′ = path_graph(4)
rem_edges!(g′, [2 => 3, 3 => 4])
@test g′ == g

#vertices at distance
L = 10
g = path_graph(L)
@test only(vertices_at_distance(g, 1, L - 1)) == L
@test only(next_nearest_neighbors(g, 1)) == 3
@test issetequal(vertices_at_distance(g, 5, 3), [2, 8])
end
end
6 changes: 5 additions & 1 deletion src/steiner_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ using SimpleTraits: SimpleTraits, Not, @traitfn
map(v -> vertex_positions(g)[v], term_vert),
dist_matrix_to_position_dist_matrix(g, distmx),
)
return typeof(g)(position_tree, map(v -> ordered_vertices(g)[v], vertices(position_tree)))
tree = typeof(g)(position_tree, map(v -> ordered_vertices(g)[v], vertices(position_tree)))
for v in copy(vertices(tree))
iszero(degree(tree, v)) && rem_vertex!(tree, v)
end
return tree
end

@traitfn function Graphs.steiner_tree(
Expand Down
3 changes: 2 additions & 1 deletion test/test_namedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ end
st = steiner_tree(g, terminal_vertices)
es = [(1, 2) => (1, 3), (1, 3) => (1, 4), (1, 4) => (2, 4), (2, 4) => (3, 4)]
@test ne(st) == 4
@test nv(st) == 12
@test nv(st) == 5
@test !any(v -> iszero(degree(st, v)), vertices(st))
for e in es
@test has_edge(st, e)
end
Expand Down

0 comments on commit 8da3920

Please sign in to comment.