FORD-FULKERSON algorithm

Table of contents

  • streaming network
  • residual network
  • augmenting path
  • flow network cut
  • Ford-Fulkerson method
  • Code

text

  This article mainly explains the Ford-Fulkerson solution of the maximum flow problem. It can be said that this is a method, not an algorithm, because it contains several implementations with different running times. The method relies on three important ideas: residual networks, augmenting paths, and cuts.

  Before introducing the three concepts, let's briefly introduce the basic idea of ​​the Ford-Fulkerson method. The first thing to understand is that Ford-Fulkerson is an iterative method. At the beginning, for all u, v belong to V, f(u, v)=0 (where f(u, v) represents the current flow of the edge from u to v), that is, the value of the flow in the initial state is 0. In each iteration, the flow value can be increased by finding an "augmenting path". An augmentation path can be seen as a path from a source s to a sink t, along which more flows can be pushed to increase the value of the flow. This process is repeated until all the augmenting paths are found, that is, the maximum network flow is obtained.

Take an example to illustrate, as shown in the figure, each line represents an augmented path, and the current flow from s to t is 3.
insert image description here
Of course, this is not the maximum flow of the network. According to the algorithm for finding augmenting paths, we can actually continue to search for augmenting paths. The final maximum flow network is shown in the figure below, and the maximum flow is 4.
insert image description here
Next, we will introduce how to find the augmentation path. Before introducing augmenting paths, we first need to introduce the concept of residual networks.

streaming network

Let's first look at the definition of a streaming network. For flow networks, Chapter 26 of "Introduction to Algorithms" defines it as follows:

The flow network G = (V, E) is a directed graph, and each edge (u, v) ∈ E in the graph has a non-negative capacity value c(u, v) >=0. Moreover, if the edge set E contains an edge (u, v), there is no opposite edge (v, u) in the graph. If (u, v) ∉ E, define c(u, v) = 0 for convenience. And no self-loops are allowed in the graph. Among all the nodes in the flow network, we distinguish two special nodes in particular: the source node s and the sink node t.

  Let me explain this definition with an example. Take a look at the directed graph below. In the figure, s is the source node (source), and t is the sink point (sink). That is to say, for vertex s, there can only be edges starting from it; and for t, there can only be edges ending at it. The number above each side in the figure is the capacity value c of this side. For example, c(s, v) = 6. There is no edge (s, z) in the graph , so c(s, z) = 0 . There cannot be self-loop edges in the graph , that is, edges like (s, s). We denote the actual flow value between two points by f(u, v).
insert image description here
insert image description here
insert image description here

residual network

insert image description here

As the name implies, a residual network refers to a network composed of a given network and a flow, which corresponds to a flow that can still be accommodated. Specifically, it is assumed that a network G = (V, E), its source point s, sink point t. Let f be a flow in G corresponding to the flow from vertex u to vertex v. Under the condition of not exceeding C(u, v) (C represents the edge capacity), the additional network traffic that can be pushed from u to v is the residual capacity (residual capacity) of the edge (u, v), which is defined as follows :

r(u,v)=c(u,v)-f(u,v)

For example, assuming (u, v) current traffic is 3/4, then c(u, v)=4, f(u, v)=3, then r(u, v)=1.

We know that there is such a rule in network flow. There are already 3 units of flow from u to v, so from the opposite direction, there is a residual network of 3 units from v to u, and r(v, u)=3. It can be understood in this way that there are 3 unit flows from u to v, then from v to u has the ability to push back these 3 unit flows.

Let's look at an example in detail. As shown in the figure below, a flow network
insert image description here
and its corresponding residual network are:
insert image description here

augmenting path

  After understanding the residual network, let's introduce the augmentation path. Given a flow network G and a flow f, the **augmenting path p is a simple path from s to t in its residual network Gf. **Visual understanding is that there is a path from s to t that does not violate the edge capacity. Pushing traffic to this path can increase the flow value of the entire network. In the above residual network, there is such an augmentation path:
insert image description here
it can push 4 units of flow, after pushing, we get a new flow network with 4 more flows than the original flow network. At this time, we continue to use the same method to find the augmentation path on the new flow network until we cannot find it. At this point we get a maximum network flow.

flow network cut

The above is just an introduction to the method, but how to prove that the current network is the maximum flow network when no augmentation path can be found? This requires the use of the max-flow min-cut theorem.

First, let me introduce the concept of cutting. The cut (S, T) of the flow network G(V, E) divides V into two parts, S and T=VS, so that s belongs to S and t belongs to T. The capacity of cut (S, T) refers to the sum of the capacity of all edges (with direction) from the set S to the set T (not counting the opposite direction, it must be S-àT). If f is a flow, the net flow through cut(S,T) is defined as f(S,T) (including reverse, positive values ​​for S à T, negative values ​​for T—>S). Continuing to take the above example, draw a random cut, as shown in the following figure:
insert image description here

Obviously, we have for any cut, the upper bound of the net flow through the cut is the capacity of the cut, that is, it is impossible to exceed the capacity of the cut. Therefore, the maximum flow of the network must not exceed the minimum cut of the network. The minimum cut refers to the smallest cut capacity, and the maximum flow refers to the largest net flow in the network. A simple example s is that the faucet continuously discharges water. These sides are equivalent to pipes, and the capacity of each pipe cannot be tolerated. In fact, it is expressed by practical cut. The minimum cut is the narrowest point we find in the overall pipeline system, that is, the minimum flow rate of a certain section of the pipeline, and the total amount of all water flows through a certain stage is expressed by flow rate. The maximum flow rate It is the maximum amount of water we pass through the pipeline at a certain stage. If it exceeds this maximum flow rate, it will cause the pipeline to exceed the capacity of a certain stage, and it will explode. Therefore, if we want to ensure that the water flow can flow from s to t , it is necessary to ensure that the water flow rate, that is, the maximum flow is less than or equal to the minimum cut, but in order to let the water flow through as soon as possible, we need to make the maximum flow equal to the minimum cut, so in the process of optimization, finding the maximum flow is equivalent to finding Minimum cut, the two are essentially the same problem.

But what does this have to do with augmenting paths on residual networks?

First of all, we must understand a feature. According to the linear programming representation of the maximum flow problem mentioned in the previous article, the principle of flow conservation of the flow network is mentioned. According to this principle, we can know that any cut of the network, Their net flows are all equal. The specific proof is not difficult. You can understand it graphically in the figure below.
insert image description here
Compared with the cut above, there are less u and v in the set S, and the net flow from the source point s to the set T flows to u and v, while In the previous cut graph, the flow from set S to set T is equal to the net flow from u and v to set T. Among them, w also flows to u and v, but this part of the flow cannot flow to the source point s, because there is no path, so this part of the flow adds the flow from s to u and v, and the flow between u and v is transferred to each other no matter what , will eventually flow to the set T, so this flow value is equal to the value of s flowing to u and v. Comparing s to a faucet, the water flows from u and v to other places all come from s, and it is impossible for itself to create water flow. Therefore, the net flow of any cut is equal, and the net flow of the cut is the flow. When the maximum is obtained, it is the maximum flow and equal to the minimum cut, which is the nature of flow conservation, and the flow everywhere is equal.

Ford-Fulkerson method (calculate maximum flow and minimum cut with FORD-FULKERSON algorithm)

Let's look at the Ford-Fulkerson algorithm. The algorithm also uses a greedy strategy. First look at the pseudocode of the algorithm.
insert image description here
The pseudocode is understood as follows:
insert image description hereinsert image description here
insert image description here

reference

https://www.freesion.com/article/67541250323/
https://www.cnblogs.com/DarrenChan/p/9563511.html

Guess you like

Origin blog.csdn.net/lockhou/article/details/129910834