Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bellman_ford shortest paths returns incorrect results #1

Open
dgleich opened this issue Jan 23, 2011 · 2 comments
Open

bellman_ford shortest paths returns incorrect results #1

dgleich opened this issue Jan 23, 2011 · 2 comments

Comments

@dgleich
Copy link
Owner

dgleich commented Jan 23, 2011

The bellman_ford shortest path function doesn't return an error when called with a negative weight cycle even though this means the output is incorrect.

It should throw an error in this case.

@sehe
Copy link

sehe commented May 5, 2022

I fear the general answer here is: it's a precondition and adding explicit checks would penalizing all usage of the algorithm.

Does the return value satisfy your expectations?

If there is a negative cycle, then there will be edges in the graph that were not properly minimized. That is, there will be edges (u,v) such that w(u,v) + d[u] < d[v]. The algorithm loops over the edges in the graph one final time to check if all the edges were minimized, returning true if they were and returning false otherwise?

Perhaps a concrete example would help if not.

@dgleich
Copy link
Owner Author

dgleich commented May 6, 2022

I'm not really doing much on this library anymore. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants