Path between two vertex with max n number of hops

184 views
Skip to first unread message

AMIYA KUMAR SAHOO

unread,
Feb 19, 2020, 11:57:44 AM2/19/20
to Gremlin-users
Hi, 

I want to find all the paths between 2 vertices with max n number of hops.
I found 3 options
 repeat with until, times or timeLimit.

So I try to use below query.

g.V(fromVertexId).
  repeat
(both()).
   
until(and(hasId(toVertexId),
              loops
().is(lte(maxHops)))).
  path
().dedup()

It worked fine if the sub graph is small.

Then I try for 2 for vertex which are 2 hops apart with maxhop =  2, but Query gets time out after 30 mins. 

Strange because when I try to find out total number of distinct paths from the vertex, I can get result < 1s as 90

g.V(fromVertexId).
  repeat
(both()).times(2).
  path
().dedup().count()

==>90

Please suggest what am I doing wrong? Can the query be optimized?

I also want to apply timeLimit to the above query as well to find out paths in 1 or 2 minute max.
What is the scope of timeLimit ? 

What's the difference between below queries?

g.V(fromVertexId).
  repeat
(both()).
  timeLimit
(60000).
  path
()

----------------

g
.V(fromVertexId).
  repeat
(timeLimit(60000).both()).
  path()




TIA, Amiya
Message has been deleted

AMIYA KUMAR SAHOO

unread,
Feb 19, 2020, 1:20:42 PM2/19/20
to Gremlin-users
I am using simplePath() as well.

g.V(fromVertexId).
  repeat
(both().simplePath()).
    until(and(hasId(toVertexId),
              loops
().is(lte(maxHops)))).
  path
().dedup()

AMIYA KUMAR SAHOO

unread,
Feb 19, 2020, 1:35:29 PM2/19/20
to Gremlin-users
Got below query from https://kelvinlawrence.net/book/Gremlin-Graph-Guide.html#sp 

But he mentions this is shorter version of the query what I am using currently. Let me give it a try. 

g.V(3).repeat(out().simplePath()).emit().times(3).has('code','MIA').
       limit(5).path().by('code')

Amiya

unread,
Feb 20, 2020, 8:27:30 PM2/20/20
to Gremlin-users
This one runs smoothly. Thanks @Kelvin.

Can someone let me know how to use timeLimit step in the query if I want to apply it globally.

Reply all
Reply to author
Forward
0 new messages