Network maximum flow and minimum cost flow

Source: Internet
Author: User


from:http://richardxx.yo2.cn/articles/Network maximum flow and minimum cost flow. html

This period of time reviewed the network flow model, feeling than before the understanding has made great progress, although I know this thing is difficult to build on the model, and its algorithm itself is not very difficult, but I decided to say some of my understanding, after all, understand the essence of the use of things will be more flexible.


There are generally two kinds of algorithms for solving the maximum flow (which are not considered by the cost stream), that is, the augmented path (FF) series and the pre-flow propulsion (PF) series. In many places see the recommended use of the latter, because more efficient, but it is not, today I am this article is to focus on the former, I believe you will like it after watching.


First of all, those a lot of the definition of the network I do not say, do not understand the first to read the book well, we agreed that S is the source, T is sinks, g to represent the residual figure. Augmented path algorithm is quite good to understand, because as long as there is a path from S to T in G, that along this road, the flow must also be increased, so when the maximum flow must not exist s-t path. Does that turn out to be true? Obviously, because we have the minimum cut maximum flow theorem, so we get the basic method of FF algorithm:

Constantly find a s-t path in G and then expand it until it is not found.


As for the way to find a road, then casually, Bfs,dfs, or even a *, you can think of the way you can try to see which one with the appetite of which to use it.

Note that with the BFS method, its official name is Edmonds-karp (EK), it and we have to say that the cost of the flow has a great relationship, here is a simple hint.

The complexity of the method. If it is an integer stream (in fact, the fractional stream can construct the data so that FF cannot stop, the PF method must be used at this time, and it is clear that at least 1 of the flow is augmented each time, looking for the O (E) edge, augmenting the time of O (V), so the complexity is O ((m+n) *u), and U is the maximum flow.

It sounds scary, actually, a slightly more precise upper bound of the EK algorithm is O (ve^2), or rather exaggerated.

So, how can you run faster? Think, every time with BFS shortest Path tree (SPT), we only care about the shortest way s-t, in fact, there is a lot of information is not used, so if we ask for SPT, we can expand many times, is not better.

So, we introduce the concept of hierarchy graph, saying that the popular point is to find the SPT of G, to find out the label D of each vertex in G, and to keep all the edges of the s->t d[s]+1=d[t] (note that it can not be an edge in SPT), Finally, use multiple BFS in the hierarchy diagram to find the augmented path.

This looks faster, actually not, because the analysis complexity is still O (ve^2), there is no improvement, and we have to write more code. Where is the bottleneck? By the way, that's the step in the hierarchy diagram using BFS to find the augmented path. In fact, a better way is to use DFS, once you can find all the augmented path, as follows:

Starting with S DFS, once an augmented path is found, it is augmented, and DFS is rolled back to the beginning of a full stream that is closest to S, and the end of the edge is removed from the diagram to continue the search.

The above algorithm is the famous Dinic algorithm, its complexity is O (ev^2) (note, see the position of 2), for the secret map there is no small improvement.

In fact, I highly recommend using the dinic algorithm in all kinds of competitions, because it's simple to implement and actually runs faster than the PF algorithm writes too much.

That simple say or not, to come up with the basis. The theory of PF algorithm is not described in detail in this article, and may be introduced later. The general PF implementation is O (v^4), while the Relable-to-front is O (v^3), and the high standard propulsion is said to be O (v^2*sqrt (E)), although it is actually relatively fast, the PF algorithm has the disadvantage of having to add heuristic optimizations, at least to gap optimization, Otherwise it will be slower in practice. As a result, the code to write a PF is naturally much more.


The above basically the maximum flow of the algorithm inventory, below or to say the minimum cost flow problem.

If the edge of a network not only has capacity, but also the unit flow costs, then we naturally want to maximize the flow at the same time, so that the total cost lower. Therefore, the minimum cost flow is actually a more general model, so its application is also wider.

Surprisingly, the problem can be solved without first finding the maximum flow (and of course there are methods needed), so if you don't want to remember so many algorithms, it's OK to just know the algorithm. Because the cost of the flow of the algorithm if the complexity of the word can be called linear programming, so first list the next few basic methods, and then introduce the simplest one, other if you are interested in the article you can look for:

1, Continuous shortest circuit algorithm (successive shortest Path);

2, the Elimination circle algorithm (Cycle canceling);

3, the original dual algorithm (Primal Dual);

4, net simplex (network Simplex).


The next two are the top two advanced optimization versions, and the basic optimization idea is similar to the optimization we discussed above, that is, we hope to do several operations each time, do not use the discarded. The best use is the first method, method two in the algorithm in C graph theory section has elaborated, I did not say.

Do you remember the EK I said just now? In fact, if we use Dijkstra in G to find s-t shortest way, rather than BFS words, is not to solve the problem. Yes, absolutely right, I leave the proof to everyone to think, in fact very simple.

However, there is a problem, in G, there is a negative right side, with Dijkstra is not the death of it. Do you have to use Bellman-ford? In fact, as long as there is no negative loop in the original image (some words do not have the minimum cost), then we can use the Johnson algorithm of the weight-weighted technology to turn all the edges into a positive right, and then after each augmentation after the maintenance can not be used efficient Dijkstra. The algorithm is as follows:

Using Bellman-ford to find the height of the d[from the point to S;

After each seek the shortest circuit, set the label for Pi[], then the implementation:

For I=1 to V do

D[V]+=PI[V]

In this way, the label has been legal (specific proof or leave it to everyone).


----------------------------------------------------------------------------------------

Simple introduction of network flow ISAP algorithm

From:http://www.zlinkin.com/?p=34

These days due to a variety of reasons often contact the topic of network flow, this type of problem to people's feeling, is to very hard yy can come out point more normal model. In particular, saw the amber minimum cut application of the article, inside the topic of ideas is really full of endless yd thought. But in the game, when you yd to this level, you have to spend more time to tangle in a lot of details of the implementation, and the lengthy code will inevitably make the wrong version of debugging after the abnormal sad, so some clever short and efficient network flow algorithm at this time it seems to be important. This paper tries to make a summary of the popular network flow algorithm with the shortest description, and recommends an algorithm which is suitable for efficiency and programming complexity.

As we all know, in the world of network flow, there are 2 different kinds of solving ideas, that is, the more famous advance flow and augmented path, both need to reverse the edge of the small technique.

The idea of the pre-flow propulsion algorithm is to carry out the push-flow operation with the edge as the unit. The specific process is as follows: The initial point adjacent to the full flow and a reverse BFS for each node to calculate the reverse distance, defined in addition to the exchange point is larger than the amount of the node is the active node, each of the active node on the allowed Edge (u->v:d[u]=d[v]+1) for the push operation, Until the flow can not be pushed or the amount of the point is 0, if the U-point is still active node, then the heavy label, make it equal to the original in the original image of the adjacent node after the operation of the minimum marking +1, and the U-point team. When the queue is empty, the algorithm ends, only S-point and T-point stock are not 0, the nodes in the network have no stock and the augmented path can not be found, then the T-point stock is the maximum flow.

The idea of the augmented path is to search for an augmented path to the meeting point each time from the source, and change the Benquan of the road until it is no longer augmented, at which point the augmented amount of the meeting point is the maximum flow. The final theoretical basis of the two is still the augmented path theorem, and in the theoretical complexity of the advance flow forward to appear more excellent. The theoretical complexity of the HLPP high standard advance has reached the heinous O (sqrt (m) *n*n), but the complexity of the programming is equally appalling-

So if we can find a balance in programming complexity and algorithmic complexity, the answer is yes. We use the idea of augmented paths and must be optimized. Since the original augmented path algorithm (for example EK) is very tragic. Then someone noticed the labeling method in the advance flow, introduced the concept of allowable arcs into the augmented path algorithm, and each time the residual network was labeled with nodes, and the recursion was continuously augmented in the forward augmentation, then the Dinic algorithm based on the layered graph was produced. Some people are less satisfied with the ascension brought about by conventional dinic, and then add the concept of multiplexing, that is, the flow of the same vertex, the simultaneous advancement of multiple routes, coupled with more complex manual recursion, so that Dinic has met the needs of most of the topics.

But this is the limit of the Augmented Path algorithm optimization. The answer is always no. People in the Dinic only analogy with the advance of the label technology, and the heavy label operation has not played incisively and vividly. So people on the basis of dinic to reintroduce the concept of heavy label, so that the algorithm does not need to bfs each vertex after each of the distance label, the active labeling technology to improve the speed of the algorithm has improved a lot. But this increase is not commendable, people also found that when the value of a certain label does not correspond to the vertex, that is, the augmented path is truncated, so the algorithm can be terminated ahead of time, this heuristic optimization called gap optimization. Finally, people combined with continuous augmentation, layered map, multi-channel augmentation, gap optimization, active labeling and other heinous optimization, but also on this above a manual recursion, resulting in the augmented path algorithm efficient algorithm –ISAP algorithm.

Although the theoretical complexity of the ISAP algorithm is still not beyond the high standard of pre-flow propulsion, but its programming complexity has been simplified to heinous, so optimized, coupled with the dinic rate (in the efficiency of manual dinic sometimes not even as recursive ISAP), we have no reason not to choose it.

Therefore, this paper strongly recommends ISAP as the network flow preferred algorithm.

The implementation method is shown below, except for routine add-edge operations, no more than 50 lines of code, why not, the following implementation still has room for optimization (in the calculation of the initial label, in order to reduce the amount of code directly ignored, its complexity unchanged, but after the implementation of the efficiency of about 5% decline, if willing to amend the words can be improved, Of course, no correction does not affect the correctness of the algorithm.

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.