graphlib
graphlib copied to clipboard
Add Bellman-Ford algorithm
Fixes #87 . As requested in issue #87, I implemented the bellman-ford algorithm, respecting the coding style of the repository. I included the bellmanFord function in the module exported by lib/alg and added some tests in tests/alg/bellman-ford-tests.js
@dionyziz can you help reviewing and testing this change?
Thanks for the feedback @dionyziz @lutzroeder . Im working on the changes
@dionyziz @lutzroeder
- I fixed the code format in all files
- I changed the edge traversal as requested and added the relaxAllEdges() function in bellman-ford.js
- I also corrected the behavior of bellman-ford regarding the reversed edges ( lines 37-40 )
- I merged the common test cases of bellman-ford and dijkstra in shortest-paths-tests.js
@pkakelas could also help with this review
LGTM, good job :)
This pull request now fixes #87 . Summary:
- Implemented the bellman-ford algorithm
- Created
shortestPaths()which in Θ(E) checks whether the graph contains a negative weight edge and chooses to use dijkstra or bellman-ford accordingly - Added the
shortest-paths-test.jsfile, which tests theshortestPathsfunction and also exports a test function for shortest paths algorithms that is used in bellman-ford and dijkstra tests to avoid code duplication
PTAL
Hi @mstou
Thanks for the work!
I'm trying to review the open PR in order to reduce the amount of issues and PRs. In case you want to continue your work, I will appreciate if you can rebase and create a new iteration. I will review it and try to make sure it will be pushed as I think this is a nice algorithm to support.
If not, I will try to continue it.
Hi @assafsun, I'll be glad to rebase this to master and squash the commits
@mstou Thanks for the update, I will follow this PR.
Hi @assafsun, sorry for the delay, I rebased to master and squashed the fixup commits. Take a look whenever you have time :)
@mstou Thank you for the new iteration. I ran your code and the tests passed. I left some small comments.