Sandeep Gudibanda
2008-Mar-07 05:18 UTC
Stopping BFS traversal after reachin a certain depth in RGL
Hi, I am using RGL for some of the graph implementations. My requirements is such that I need to find out all nodes that are at distance less than 3 from root. For this, I thought of traversing the graph using BFS and stop the traversal when i reach 4th level. But how do I do this? regards, Sandeep G -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
monora
2008-Mar-11 23:15 UTC
Re: Stopping BFS traversal after reachin a certain depth in RGL
On 7 Mrz., 06:18, Sandeep Gudibanda <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > I am usingRGLfor some of the graph implementations. My requirements is > such that I need to find out all nodes that are at distance less than > 3 from root. > > For this, I thought of traversing the graph using BFS and stop the > traversal when i reach 4th level. But how do I do this? >Take the example graph from the README http://rgl.rubyforge.org/rgl/index.html: require ''rgl/adjacency'' require ''rgl/traversal'' dg = RGL::DirectedAdjacencyGraph[1,2 ,2,3 ,2,4, 4,5, 6,4, 1,6] bfs = dg.bfs_iterator(1) bfs.attach_distance_map bfs.each do |v| dist = bfs.distance_to_root(v) break if dist > 3 print v, '': '', dist, "\n" end Should produce this result: 1: 1 6: 2 2: 2 4: 3 3: 3 Regards Horst --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---