enter image description here

Please take a look at the picture.

I wanted to use Yen's Algorithm Shortest Path from Neo4j Graph Data Science to dig the Shortest Path between A and F, but nothing came back.

The following code:

MATCH (source:Location{name: ‘A’}), (target:Location{name: ‘F’})
CALL gds.shortestPath.dijkstra.stream(‘myGraph’, {
sourceNode: source,
targetNode: target
})
YIELD index, sourceNode, targetNode,nodeIds,path
RETURN
index,
gds.util.asNode(sourceNode).name AS sourceNodeName,
gds.util.asNode(targetNode).name AS targetNodeName,
[nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS nodeNames,
nodes(path) as path
ORDER BY index

Does the relation between A and F need to be in the same direction.

If I just want to look at the shortest distance between A and F, regardless of the direction and weight of relation, what should I do.

Thank you for any help

1

There are 1 best solutions below

2
On

On Neo4j 4.4 there is an option to use shortestPath, in which you can define the direction or use both directions like this:

MATCH (source:Location{name: ‘A’}), (target:Location{name: ‘F’})
p = shortestPath((source)-[*]-(target))
RETURN p