[TinkerPop3] Find the path between two nodes in Java

398 views
Skip to first unread message

Vega Rodrigálvarez

unread,
May 29, 2015, 6:54:50 AM5/29/15
to gremli...@googlegroups.com
Hello,

I want to fin the path between two nodes in a graph using Tinkerpop3 in Java. I found several documentation about this functionality in Groovy and in Java using Java2 (GremlingPipeLine), but I don't find anything about TinkerPop3. 

I think that I should use LoopTraversal but I don't know how to use it. I have two vertex but I don't know how to continue.

Can someone give me a clue?

Best Regards 

Vega

Vega Rodrigálvarez

unread,
Jun 1, 2015, 9:52:35 AM6/1/15
to gremli...@googlegroups.com
At last, I have seen a way to find a path between two nodes in Java with Tinkerpop3

GraphTraversal<Vertex, Path> realPath = graph.traversal().V(IdInitialNode).emit(has(T.id,IdFinalNode)).repeat(out()).path(); 

I don't know if there are a better way.

Now, I want to know how to get the Edge between different vertex of the path

Daniel Kuppitz

unread,
Jun 1, 2015, 12:16:38 PM6/1/15
to gremli...@googlegroups.com
Hi Vega,

you only need to replace .out() with .outE().inV(). Furthermore I would a) use .until() instead of .emit(): and b) add a .limit(1) (assuming that you're only looking for the shortest path):

GraphTraversal<Vertex, Path> realPath = graph.traversal().V(IdInitialNode).until(hasId(IdFinalNode)).repeat(outE().inV()).limit(1).path(); 

Cheers,
Daniel


--
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/ca359af1-8707-41dd-a295-a6bcf608d220%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages