3

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!

fermion4
  • 65
  • 3

1 Answers1

3

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"
PaSTE
  • 4,050
  • 18
  • 26