Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Expect disruption to service on Thursday, Feb. 9!

Does allshortestpath in gds can not outcome the links and nodes for each path?

Node Link

Hi, I have a question about allshortestpath algorithm in gds.

When I run the query like this:

nodeQuery: 'MATCH (n:Loc) RETURN id(n) AS id',
relationshipQuery: 'MATCH (n:Loc)-[r:ROAD]-(p:Loc) RETURN id(n) AS source, id(p) AS target, r.cost AS cost',
relationshipWeightProperty: 'cost'
YIELD sourceNodeId, targetNodeId, distance
WITH sourceNodeId, targetNodeId, distance
WHERE gds.util.isFinite(distance) = true

MATCH (source:Loc) WHERE id(source) = sourceNodeId
MATCH (target:Loc) WHERE id(target) = targetNodeId
WITH source, target, distance WHERE source <> target

RETURN AS source, AS target, distance
ORDER BY distance DESC, source ASC, target ASC

I find that when I call the gds.alpha.allShortestPaths, the output is only sourceNodeId, targetNodeId and distance. Is it true? I want get the information of links and nodes for each path. Can I get them by calling gds?

Many thanks for your help.


Node Clone

It is not possible with that algorithm.
It all depends on your usecase.

Do you surely need all shortest paths for all pair of nodes?

Thanks for your reply.
Yes, I think so. Since I need to calculate some complex network indicators according to the information of links between each two node

I don't need all shortest paths for all pair of nodes, but for each node pair, I need the detail path of the shortest path, like which nodes this path across.

Node Clone

I think you can find some different solutions here:

Node Link

Thank you for your help.
Yes, according to this post, I have similar scenario with tenkaleakshay94, but in the case first. That is, I need the shortest path to every label2 node.
So now, I have a large network and I need to get the shortest path information for all node pairs.
But it is too much time consuming.
So I am looking for methods can improve the performance.
Do you have any ideas about how to improve the query performance?

Node Clone

Without knowing you real usecase I'm not sure I can help you with the performance problem.

When running an algorithm to get all nodepairs shortest paths will take alot of time to perform. Because it will traverse all nodes multiple times.

You mentioned earlier that you need to calculate on nodes that is crossed. Perhaps a centrality algorithm would help you.