100 Practical Application Cases of Machine Learning (26) - Application Cases of Shortest Path Algorithms

Bellman Ford Algorithm (Single Source Shortest Path)

1 Introduction to the algorithm

Bellman Ford's algorithm helps us find the shortest path from one vertex to all other vertices in a weighted graph .

It is similar to Dijkstra's algorithm, but it can be used for graphs with negative weight edges .

Why are there negative power edges in real life?

Negative weighted edges may seem useless at first, but they can explain many phenomena like cash flow, heat released/absorbed in chemical reactions, etc.

For example, if there are different methods from one chemical A to another chemical B, each method will have sub-reactions involving heat dissipation and absorption.

If you want to find the set of reactions that require the least energy, then you need to be able to weight heat absorption as a negative weight and heat dissipation as a positive weight.

Why be careful with negative weights?

Negative weight edges can create negative weight loops , i.e. loops that reduce the total path distance by returning to the same point.

Shortest path algorithms, such as Dijkstra's Algorithm, cannot detect such cycles and may give a false result, since they can cycle through a negative weight, reducing the path length .

Bellman Ford's algorithm works by overestimating the path length from the starting vertex to all other vertices. These estimates are then relaxed iteratively by finding new paths that are shorter than previously overestimated paths .

Guess you like

Origin blog.csdn.net/wenyusuran/article/details/123680068