How to ignore directions in dijkstra algorithm

https://neo4j.com/docs/graph-data-science/current/algorithms/dijkstra-source-target/?_gl=11ubbr7m_gaMTE2MTY2MDkzLjE2MDYwNjA1NjQ._ga_DL38Q8KGQC*MTYxNjE0NTIxOS4zMy4xLjE2MTYxNDY1ODkuMA..&_ga=2.21011640.2073803404.1616145220-116166093.1606060564#algorithms-dijkstra-source-target-examples
In this example, all the relationships are unidirectional. How can i tell the algorithm to ignore the directions.
I tried to find the shortest path between 'F' to 'A'.
It is showing no changes, no records.
How can i ignore the directions of relationships?
thanks in advance.

Can you share the code that you've tried so far?

The above figure is the graph of the data.
The code used to create the graph is

CREATE (a:Location {name: 'A'}),
       (b:Location {name: 'B'}),
       (c:Location {name: 'C'}),
       (d:Location {name: 'D'}),
       (e:Location {name: 'E'}),
       (f:Location {name: 'F'}),
       (a)-[:ROAD {cost: 50}]->(b),
       (a)-[:ROAD {cost: 50}]->(c),
       (a)-[:ROAD {cost: 100}]->(d),
       (b)-[:ROAD {cost: 40}]->(d),
       (c)-[:ROAD {cost: 40}]->(d),
       (c)-[:ROAD {cost: 80}]->(e),
       (d)-[:ROAD {cost: 30}]->(e),
       (d)-[:ROAD {cost: 80}]->(f),
       (e)-[:ROAD {cost: 40}]->(f);

To find shortest path between "A" and "F" nodes using dijkstra algorithm, the code is as follows.

MATCH (source:Location {name: 'A'}), (target:Location {name: 'F'})
CALL gds.beta.shortestPath.dijkstra.stream('myGraph', {
    sourceNode: id(source),
    targetNode: id(target),
    relationshipWeightProperty: 'cost'
})
YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs
RETURN
    index,
    gds.util.asNode(sourceNode).name AS sourceNodeName,
    gds.util.asNode(targetNode).name AS targetNodeName,
    totalCost,
    [nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS nodeNames,
    costs
ORDER BY index

I got the output like below.

This is fine. But when I find shortest path from "F" to "A" by using the same code just reversing the nodes as below,

MATCH (source:Location {name: 'F'}), (target:Location {name: 'A'})
CALL gds.beta.shortestPath.dijkstra.stream('myGraph', {
    sourceNode: id(source),
    targetNode: id(target),
    relationshipWeightProperty: 'cost'
})
YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs
RETURN
    index,
    gds.util.asNode(sourceNode).name AS sourceNodeName,
    gds.util.asNode(targetNode).name AS targetNodeName,
    totalCost,
    [nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS nodeNames,
    costs
ORDER BY index

the output is as below.

I think the reason for this is, there are no directed edges from "F" to "A".
Actually i want create bidirectional edges. But it is not possible in Neo4j.
what should be the code to ignore the directions and find dijkstra shortest path between "F" to "A".

Could you share the code you used to create myGraph. You should be able to create a birectional graph when constructing that.

I have shared the code in above reply.

I think you haven't pasted the bit of code that calls the gds.graph.create procedure.

Yes sir. Actually I used below code to call the graph. But i forget to mention in the above question.

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

Please help me.

Can you try this:

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

This is saying unexpected configuration key : orientation


I also tried the word "direction" instead of "orientation". This is also not working sir.

Ah wait sorry, I've put it in the wrong place in my reply:

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

Thank you sir. This works for me.
Thank you so much for helping. :heart: