The Ford - Fulkerson algorithm solves the problem of finding the maximum flow in the transport network .
The idea of the algorithm is as follows. Initially, the value of the stream is assigned the value 0: for all . Then the flow magnitude iteratively increases by searching for an increasing path (path from source s to drain t , along which a larger flow can be sent). The process repeats until a magnifying path can be found.
Content
Algorithm
Informal Description
- Zero all threads. The residual network initially coincides with the original network.
- In the residual network, we find any path from the source to the drain. If there is no such way, stop.
- We run through the found path (it is called the increasing path or the increasing chain ) the maximum possible flow:
- On the found path in the residual network, we are looking for an edge with minimal throughput .
- For each edge on the found path, increase the flow by , and in the opposite - we reduce by .
- Modify the residual network. For all edges on the found path, as well as for edges opposite to them, we calculate a new throughput. If it became nonzero, add an edge to the residual network, and if it is zero, we erase it.
- We return to step 2.
It is important that the algorithm does not specify which path we are looking for in step 2 or how we do it. For this reason, the algorithm is guaranteed to converge only for whole bandwidths, but even for them, with large values of bandwidths, it can work for a very long time. If the throughputs are real, the algorithm can work indefinitely without converging to the optimal solution (see the example below ).
If you search not for any path, but for the shortest, you get the Edmonds – Karp algorithm or the Dinits algorithm . These algorithms converge for any real weights in time and respectively.
Formal Description
Dan Earl with bandwidth and flow for edges from u to v . It is necessary to find the maximum flow from source s to sink t . At each step of the algorithm, the same conditions apply as for all flows:
- . Stream out at does not exceed bandwidth.
- .
- for all nodes , Besides and . The flow does not change when passing through the node.
Residual network - network with bandwidth and without flow.
Entry Count with bandwidth , a source and stock
Output Max Flow of at
- for all the edges
- As long as there is a way of at at such that for all ribs :
- To find
- For each rib
A path can be found, for example, by a breadth-first search ( Edmonds-Karp algorithm ) or depth-deep search in .
Difficulty
At each step, the algorithm adds the incremental path stream to the existing stream. If the capacities of all the edges are integers, it is easy to prove by induction that the flows through all the edges will always be integer. Therefore, at each step, the algorithm increases the flow by at least one, therefore, it converges in no more than O ( f ) steps, where f is the maximum flow in the graph. You can complete each step in time O ( E ), where E is the number of edges in the graph, then the total time of the algorithm is limited to O ( Ef ).
If the throughput of at least one of the edges is an irrational number, then the algorithm can work infinitely, without even necessarily converging to the correct solution. An example is given below.
Example of a non-convergent algorithm
Consider the network on the right, with the source by stock bandwidth = , = , = and the throughput of all other edges equal to an integer . Constant chosen so that . We use the paths from the residual graph given in the table, and , and .
| Step | Path found | Added stream | Residual bandwidth | ||
|---|---|---|---|---|---|
| 0 | |||||
| one | |||||
| 2 | |||||
| 3 | |||||
| four | |||||
| five | |||||
Note that after step 1, as well as after step 5, the residual ability of the edges , and are shaped , and , respectively, for some kind of natural . This means that we can use magnifying paths. , , and infinitely many times, and the residual throughput of these edges will always be in the same form. The total flow after step 5 is . For infinite time, the full flow will converge to , while the maximum flow is . Thus, the algorithm not only works infinitely long, but does not even converge to the optimal solution. [one]
Example
The following example shows the first steps of the Ford-Fulkerson algorithm in a transport network with four nodes, source A and drain D. This example shows the worst case. When using a breadth-first search, the algorithm only needs 2 steps.
| Way | Throughput | Result |
|---|---|---|
| Initial transport network | ||
| | ||
| | ||
| After the 1998 steps ... | ||
| End network |
See also
- Ford-Fulkerson Theorem
Links
- YouTube task solution example
- Algorithm Visualizer
- Implementing Ford-Fulkerson Max Stream Search in Java
- Wikimedia Commons has media related to the Ford-Fulkerson Algorithm
Literature
- Thomas H. Cormen et al. Algorithms: Construction and Analysis = INTRODUCTION TO ALGORITHMS. - 2nd ed. - M .: "Williams", 2006. - S. 1296. - ISBN 0-07-013151-1 .
Notes
- ↑ Zwick, Uri. The smallest networks on which the Ford-Fulkerson maximum flow procedure may fail to terminate (English) // Theoretical Computer Science : journal. - 1995 .-- 21 August ( vol. 148 , no. 1 ). - P. 165-170 . - DOI : 10.1016 / 0304-3975 (95) 00022-O .