0
votes

I am trying to use the following script to get the shortest path:

g.V.filter{it.name == 'station1'}.out.dedup().loop(2){it.object.name != "station5" & it.loops < 30}.path{it.name}

If there are more than 1 shortest path in the graph, how do I modify the script to list all of them?

1
When you say that there is "more than 1 shortest path", I assume that you mean that there are multiple paths of length 2 between station1 and station5 and you want all such paths. Is that correct?stephen mallette
Oh, I mean that the number of edge of alternative shortest path is the same.Harold Chan

1 Answers

4
votes

I updated GremlinDocs Shortest Path Recipe to perhaps better address the topic:

http://gremlindocs.com/#recipes/shortest-path

The example basically culminates in doing a path distribution:

gremlin> g.v(1).out.loop(1){it.object.id!="5" && it.loops< 6 }.path{it.name}.groupBy{it.size()}{it}.cap.next()
==>2=[[marko, ripple]]
==>3=[[marko, josh, ripple], [marko, lop, ripple]]
==>4=[[marko, josh, lop, ripple]]

Note that two paths of length 3 are shown.