Skip to content

Commit

Permalink
Combinatorics: fix neighbors(::Graph,::Int64)
Browse files Browse the repository at this point in the history
changed to take both out- and in-neighbours into account when graph is directed
  • Loading branch information
YueRen committed Jan 10, 2025
1 parent 43499a7 commit db61129
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Combinatorics/Graphs/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down

0 comments on commit db61129

Please sign in to comment.