BFS using gremlin-Java API

384 views
Skip to first unread message

budwhite

unread,
Oct 29, 2014, 9:53:24 AM10/29/14
to gremli...@googlegroups.com
Hi,
   I have to traverse 100K nodes in BFS fashion.I cant find a proper Gremlin Java code for implementing this.Also,I need to specify the maximum depth for the traversal.How to proceed on?

Stephen Mallette

unread,
Oct 31, 2014, 4:21:47 PM10/31/14
to gremli...@googlegroups.com

On Wed, Oct 29, 2014 at 9:53 AM, budwhite <tushar...@gmail.com> wrote:
Hi,
   I have to traverse 100K nodes in BFS fashion.I cant find a proper Gremlin Java code for implementing this.Also,I need to specify the maximum depth for the traversal.How to proceed on?

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/d2a41173-a940-46c3-85b2-d55d0ef31e2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Abhilash Sharma

unread,
Jun 23, 2017, 9:01:57 AM6/23/17
to Gremlin-users
Hey,
Did you found a solution to this? i also want to traverse in BFS fashion without revisiting any node(no cycles and and the set of paths form a tree from a root vertex)

parav...@gmail.com

unread,
Aug 19, 2017, 11:24:22 AM8/19/17
to Gremlin-users
Hey It would be great if someone could post a code snippet for BFS.

Stephen Mallette

unread,
Aug 22, 2017, 7:22:05 AM8/22/17
to Gremlin-users
A code snippet for BFS begs some explanation. Let's see how I do. First, let's assume a Gremlin language without optimization - doing:

g.V().out().out()

will result in a depth first search. You can force BFS with barrier():

g.V().out().barrier().out()

which basically will force the step prior to drain before moving on to the next step. You can read more about barrier() here:


What you will read though is that Gremlin is not without optimizations as we first assumed and that LazyBarrierStrategy will automatically inject "small" barriers where it thinks it can optimize with bulking, so even simple:

g.V().out().out()

will actually compile to:

g.V().out().barrier(2500).out()

so depending on how large your graph is, you really get a mixed form of processing. 


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/0dfc4222-d7e3-4517-9c01-c9a0350a3bd0%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages