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
On Neo4j 4.4 there is an option to use
shortestPath
, in which you can define the direction or use both directions like this: