Is there a LightGraph function in Julia which is equivalent to ancestors function in Networkx?
Asked
Active
Viewed 303 times
2 Answers
2
A possibly faster way:
function ancestors(g::SimpleDiGraph{T}, src) where T <: Integer
reverse!(g)
a = Vector{T}()
for (v, d) in enumerate(gdistances(g, src))
if d < typemax(T)
push!(a, v)
end
end
reverse!(g)
return a
end

sbromberger
- 1,026
- 6
- 12
0
Not natively, but it should be easy to approximate:
function ancestors(g, src)
reverse!(g)
a = reduce(union, enumerate_paths(dijkstra_shortest_paths(g, src))
reverse!(g)
return a
end
This will need verification and it's a bit risky in the event the function exits before the second reverse!
but it's much more efficient than the non-mutating reverse()
.

sbromberger
- 1,026
- 6
- 12