How can I create a Static Directed Graph from an array of tuples in Julia without having to create a Simple Directed Graph first. An example edge list I have is [(1,2),(2,3),(3,4)]
. The documentation of StaticGraphs.jl is limited.
Asked
Active
Viewed 383 times
1

decardinb
- 160
- 9
1 Answers
1
There's a way to do this but it requires you to have the edges and their reverses already sorted into two vectors. Assume you have a directed path graph 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
testing:
julia> h = StaticDiGraph(path_digraph(4))
{4, 3} directed simple static {UInt8, UInt8} graph
julia> g == h
true

sbromberger
- 1,026
- 6
- 12
-
1Also, for future reference, posting in the Julia discourse or in the `#graphs` channel in the Julia slack will likely get you more timely answers. – sbromberger Feb 13 '20 at 15:45