cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

Bellman-Ford algorithm

John8
Node

Is it possible to use the Bellman Ford algorithm to calculate the shortest path?

I looked into the shortest path algorithms and saw that Bellman Ford supports negative distances, which is what I would like to use.

I guess Neo4j uses Dijkstra's as default, but Dijkstra's doesn't support negative distances so I wonder if there is a way to use Bellman instead of Dijkstra's .

I saw this post on github from 2016 saying it would add the Bellman-Ford algorithm, but I don't know if it was implemented.
I searched the apoc documentation but there is nothing about Bellman-Ford.

Thanks,

1 REPLY 1

david_allen
Neo4j
Neo4j

Unfortunately Bellman-Ford isn't available. The GDS package supports A* and Yen, but disclosure, they both only support positive weights.

In your situation, I would consider normalizing your negative weights to positive numbers and then using your choice of the available options in the link above.