Angelo Immediata
Angelo Immediata

Reputation: 6944

Neo4j Gremlin: all shortest weigthed path

We are using Neo4J 2.0 embedded; we have a Graph with around 1 Million of Nodes, and 50 Million of relationships; we have to find N shortestPath but with a well known cost property We saw that there is no such method in GraphAlgo class of neo4j and we were thinking to use Gremlin (or any other utility) in order to find these paths. Our wish is to specify which relationship property to consider for the shortest paths finding

Did anybody find a solution to this problem? How could we implement such functionality?

Any suggestion is really apreciated... Thank you Angelo

Upvotes: 0

Views: 134

Answers (1)

stephen mallette
stephen mallette

Reputation: 46216

You can use Gremlin to calculate shortest paths. Here's an example in GremlinDocs:

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

The following snippet from that section discusses the use of a "weight" property to calculate the cost of the path:

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.v(1).outE.inV.loop(2){it.object.id!="3" && it.loops < 6}.path.filter{it.last().id=="3"}.transform{[it.findAll{it instanceof Edge}.sum{it.weight}, it]}
==>[0.4, [v[1], e[9][1-created->3], v[3]]]
==>[1.4000000059604645, [v[1], e[8][1-knows->4], v[4], e[11][4-created->3], v[3]]]

I'm not sure if this is exactly what you're after, but perhaps it will inspire you to a solution.

Upvotes: 1

Related Questions