Dijkstra + Ford-fulksonff Algorithm for the implementation of the maximum flow with minimum cost

Source: Internet
Author: User

 

The article is very detailed and has a great inspiration for the algorithm for learning the maximum flow of the minimum cost.

Attachment to original post address

Dijkstra + Ford-fulksonff algorithm modified by the maximum flow at minimum cost
The modified Dijkstra is actually the same as the Johnson algorithm.
 
A Simple Algorithm for maximizing the minimum cost is as follows:
1. Increase the traffic at the minimum cost.
2. Determine whether there is an augmented path. If not, the algorithm is terminated.
3. Increase the traffic on the zengguang Road
4. Add necessary inverse negative weight edge on the augmented path
5 GOTO 1
 
Because of the existence of the negative weight edge, the Dijkstra algorithm cannot be used to increase the minimum cost. Of course, we can use the Bellman-Ford algorithm. However, in this case, the time cost for a short circuit is O (E * n), e is the number of edges, and N is the number of vertices. The cost is a little higher, and it would be nice to use the Dijkstra algorithm. Using the Johnson algorithm, this can be done.
 
The Dijkstra algorithm can be used to find the shortest path for the first time (if there is a negative weight edge at the beginning, it is okay to use the Bellman-Ford algorithm) to find the distance from the source vertex to all vertices, well, the distance I am talking about refers to the minimum value of the sum of the fee above the path. Note that the distance to all vertices is required, instead of finding the distance to the sink point.
Assume that there is an edge U-> V, the distance from the source point to U is d [u], the distance from the source point to V is d [v], and the edge fee (weight) W (u, v ). Obviously, d [u] + W (u, v)> = d [v]. Otherwise, you will find a better path from the source point to v. The question is, when can I perform the same operation? When u-> V is on the Optimal Path of V, the range is smaller. When U-> V is on the optimal path from the source point to the sink point, that is, the least cost augmented path.
Okay. If U-> V is added to your instance, you need to add the negative weight Edge V-> U. If the weight value is negative, it is-W (u, v ). Negative weight is annoying. If it is positive, the Dijkstra algorithm can be used again. What should we do? Add a weight value to the negative weight edge to make it non-negative. D [v]-d [u]. Of course, you cannot add only one edge to all edges. No matter the original or newly added edges, add them according to this rule to construct a new graph:
Edge a-> B, New Edge Weight W' (a, B) = W (a, B) + d [a]-d [B]
Now let's take a look at your masterpiece:
For the original edge U-> V, W' (u, v) = W (u, v) + d [u]-d [v]: remember d [u] + W (u, v)> = d [v], so W' (u, v)> = 0
Negative weight Edge V-> U, W' (v, u) = W (v, U) + d [v]-d [u] =-W (u, v) + d [v]-d [u]: Remember d [u] + W (u, v) = d [v], but here it is equal, so W' (v, u) = 0
Haha, now all sides are not negative.
However, the problem is, why not add a positive number that is big enough for each side? Isn't it true for all sides. Think about it. Why is Edge Weight positive? Isn't it convenient to find the shortest path from the source point to the sink point? But if we increase the positive value, can the shortest path you have obtained be the same as the shortest path of the original graph? No, why? Draw a triangle and think about it. But can my methods be the same. I will prove it to you.
 
Assume that there is a path S-> A-> B-> C-> D.-> T from The Source Vertex s to the sink vertex t, and the path length in the source image is
W (s, A) + W (a, B) + W (B, c) + + W (x, t)
The path in the new graph is
W' (s, A) + W' (a, B) + W' (B, c) + W' (x, t)
Expand
W (s, A) + d [a]-d [s] + W (a, B) + d [B]-d [a] + W (c, d) + d [d]-d [B] +. + W (x, t) + d [T]-d [x]
For example, what are the remaining values: d [a] and-d [a], d [B] And-d [B] d [X] and-d [x:
W (s, A) + W (a, B) + W (B, c) + + W (x, t) + d [T]-d [s]
Oh, isn't d [T]-d [s] More than the original image (in fact, d [s] = 0 ). This is true for all S-to-t PATHS. Since all paths have higher weights than D [T] in the source image, the shortest path of the new graph corresponds to the shortest path of the source image, but the path length is greater than D [T]. This is not only true for T, but also true for all node u, however, the shortest path length to u in the new graph is longer than that in the source image d [u].
 
Well, use the Dijkstra algorithm to find the shortest path for the second time. Then find the new d' [u], add the new edge, and then prepare the third Dijkstra algorithm... Why can this be done for the second time and the third time? The third source image may have many negative edges? I have not mentioned the limitation of w (u, v)> = 0. Therefore, even if the source image has a negative weight edge, this can still be done.
 
Well, the first Dijkstra algorithm (or the Bellman-Ford algorithm, if there is a negative weight edge, it will only be used once and will not become a bottleneck ), then, the Dijkstra algorithm modified once is used to find the minimum augmented path. This algorithm calculates the minimum cost, and the maximum stream complexity is O (M * n), M is the maximum traffic, or the upper limit of the number of augmented channels. Finally, if we use this algorithm to find the optimal matching problem, the complexity is O (n ^ 3.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.