Search code examples
neo4jgraph-algorithm

Neo4j shortestPath does not work in reverse


I follow the sample documentation of neo4j on how to calculate the shortestPath given my own network. In my network, for example, from point "P1" to point "P13", I got the result path. But when I set the source as "P13" and target as "P1", I got no result.

I tried using the exact example from neo4j website as follows: When the sourceNode is "A" and targetNode is "F", it returns the shortest path result. But when the sourceNode is "F" and targetNode is "A", the shortest path return empty array.

enter image description here

enter image description here


Solution

  • When you create the gds graph you should configure it using the appropriate orientation property, in your case UNDIRECTED.

    CALL gds.graph.create(
        'myGraph',
        'Location',
        {
            UNDIRECTED_ROAD: {
                type: 'ROAD',
                orientation: 'UNDIRECTED'
            }
        },
        {
            relationshipProperties: 'cost'
        }
    )