Getting the Vertices numbers from an Edge

229 Views Asked by At

I am using the shortest path algorithm from LightGraphs.jl. In the end I want to collect some information about the nodes along the path. In order to do that I need to be able to extract the vertices from the edges that the function gives back.

Using LightGraphs
g = cycle_graph(4)
path = a_star(g, 1, 3)
edge1 = path[1]

Using this I get: Edge 1 => 2 How would I automatically get the vertices 1, 2 without having to look at the Edge manually? I thinking about some thing like edge1[1] or edge1.From which both does not work.
Thanks in advance!

1

There are 1 best solutions below

1
PaSTE On BEST ANSWER

The accessors for AbstractEdge classes are src and dst, used like this:

using LightGraphs
g = cycle_graph(4)
path = a_star(g, 1, 3)
edge1 = path[1]

s = src(edge1)
d = dst(edge1)

println("source: $s")       # prints "source: 1"
println("destination: $d")  # prints "destination: 2"