Is loop DFT or BFT ?

7 views
Skip to first unread message

张轩

unread,
Sep 6, 2015, 1:56:20 AM9/6/15
to pacer-users
Hi!

So I'm working on the following code 

from_v.loop do |v|
      v.out_e.in_v
    end.while do |element, depth, path|
      if path != path.uniq
        nil
      elsif depth > 3
        nil
      else
        if element = to_v
          :emit
        else
          :loop
        end
      end
    end.paths.to_a

its a very simple finding path from from_v to to_v, the only problem i have is its seems its doing Breadth-First Traversal, is there a way for it to do Depth-First Traversal in loop?

Thanks a lot!!

Darrick Wiebe

unread,
Sep 6, 2015, 10:41:44 AM9/6/15
to Pacer Group
Hi,

The loop function does actually traverse depth-first! :)

Cheers,
Darrick

--
You received this message because you are subscribed to the Google Groups "pacer-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pacer-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

张轩

unread,
Sep 6, 2015, 4:07:51 PM9/6/15
to pacer-users
Thanks for the reply! now this is interesting cause if i do this 

count = []

from_v.loop do |v|
      v.out_e.in_v
    end.while do |element, depth, path|
      if path != path.uniq
        nil
      elsif depth > 3
        nil
      else
        count << path.count
        if element = to_v
          :emit
        else
          :loop
        end
      end
    end.paths.to_a

the count i got seems to be something like this [1,3,3,3,3,5,5,5,5,5,5,5,5,7,7,7 ......], wasn't this Breadth-First Traversal?

Thanks again for ur help!!

在 2015年9月6日星期日 UTC-5上午9:41:44,Darrick Wiebe写道:
Reply all
Reply to author
Forward
0 new messages