dgleich / matlab-bgl

A graph library for Matlab based on the boost graph library
http://dgleich.github.com/matlab-bgl
110 stars 70 forks source link

bellman_ford shortest paths returns incorrect results #1

Open dgleich opened 13 years ago

dgleich commented 13 years ago

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 commented 2 years ago

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 commented 2 years ago

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