1

如何在 Julia 中从元组数组创建静态有向图,而无需先创建简单有向图。我拥有的一个示例边缘列表是[(1,2),(2,3),(3,4)]. StaticGraphs.jl 的文档是有限的。

4

1 回答 1

1

有一种方法可以做到这一点,但它要求您将边缘及其反向已经分类为两个向量。假设你有一个有向路径图 1 -> 2 -> 3 -> 4:

fwd = [(1, 2), (2, 3), (3, 4)]  # these are your forward edges, sorted
rev = [(2, 1), (3, 2), (4, 3)]  # these are the reverse of the forward edges, sorted
# also, sort(reverse.(fwd)) will do this easily.

g = StaticDiGraph(4, fwd, rev)  # number of vertices is the first argument

测试:

julia> h = StaticDiGraph(path_digraph(4))
{4, 3} directed simple static {UInt8, UInt8} graph

julia> g == h
true
于 2020-02-13T15:43:20.737 回答