Julia 中是否有与 Networkx 中的祖先函数等效的 LightGraph 函数?
问问题
259 次
2 回答
2
一种可能更快的方法:
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
于 2019-03-19T14:34:43.747 回答
0
不是原生的,但应该很容易近似:
function ancestors(g, src)
reverse!(g)
a = reduce(union, enumerate_paths(dijkstra_shortest_paths(g, src))
reverse!(g)
return a
end
这将需要验证,如果函数在第二个之前退出,它会有点风险,reverse!
但它比 non-mutating 更有效reverse()
。
于 2019-03-19T00:56:44.497 回答