Matthew Smillie
2/2/2006 12:10:00 AM
On Feb 1, 2006, at 21:49, meruby@gmail.com wrote:
> How can get list of vertices from start node to end node in rgl?
>
> For example:
>
> require 'rgl/adjacency'
> dg=RGL::DirectedAdjacencyGraph[1,2 ,2,3 ,2,4, 4,5, 6,4, 1,6]
>
> How to do following?
> get_path(1,5) should give [1,2,4,5] or [1,6,4,5] or both
>
> Thanks in advance
If you just to find one or two paths per graph, you can use breadth-
first search, keeping track of visited nodes at each step.
There's a breadth-first iterator in rgl which might help with this,
combined with a graph visitor to track the visited nodes. Remember
that not all directed graphs have paths between all nodes.
If you know something about the structure of the graphs you're
expecting, you might be able to come up with something slightly
better, but the breadth-first search will work.
matthew smillie.