From db6112945ce1c0664d7f121047e28c9b50d53285 Mon Sep 17 00:00:00 2001 From: Yue Ren Date: Fri, 10 Jan 2025 11:37:37 +0000 Subject: [PATCH] Combinatorics: fix neighbors(::Graph,::Int64) changed to take both out- and in-neighbours into account when graph is directed --- src/Combinatorics/Graphs/functions.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Combinatorics/Graphs/functions.jl b/src/Combinatorics/Graphs/functions.jl index 352f810dd721..17f1e0545faa 100644 --- a/src/Combinatorics/Graphs/functions.jl +++ b/src/Combinatorics/Graphs/functions.jl @@ -502,11 +502,18 @@ julia> neighbors(g, 3) 4 ``` """ -function neighbors(g::Graph{T}, v::Int64) where {T <: Union{Directed, Undirected}} +function neighbors(g::Graph{Undirected}, v::Int64) pmg = pm_object(g); result = Polymake._outneighbors(pmg, v-1) return [x+1 for x in result] end +function neighbors(g::Graph{Directed}, v::Int64) + pmg = pm_object(g); + result1 = Polymake._outneighbors(pmg, v-1) + result2 = Polymake._inneighbors(pmg, v-1) + return unique(vcat([x+1 for x in result1],[x+1 for x in result2])) +end + @doc raw""" degree(g::Graph{T} [, v::Int64]) where {T <: Union{Directed, Undirected}}