maximum flow

maximum flow

network flow problem

Given a specified directed graph with two special point sources S (Sources) and sinks T (Sinks), each edge has a specified capacity (Capacity), find the maximum flow from S to T that satisfies the condition (MaxFlow).

Obviously there are three properties of a flow network: 1. Capacity limitation: the flow will not be greater than the capacity. 2. Anti-symmetry: The flow from u to v must be the opposite of the flow from v to u. 3. Conservation of flow: Inflow is the same as outflow. Here we should pay special attention to the second point, the traffic v on one edge will bring the reverse traffic cv, which is embodied in the code, that is, each edge in the residual network has a reverse edge. When the traffic of one edge increases, its The traffic on the opposite side is reduced by the corresponding value. The algorithm of network flow is based on the residual network instead of the original network.

Residual Networks, Augmenting Paths and Cuts

An augmentation path is a flow through the residual network, and its role is to "return". The cut C[A, B] is to divide the graph G into two point sets, A and B, so that S is in A and T is in B. Note that the size of the cut is the sum of the edge weights from S to T.

How to find the maximum flow of a network? There is the simplest EK algorithm. The idea is to find an augmenting path each time, and continuously adjust the residual network until there is no augmenting path. This proof can be emotionally pleasing. The following is a proof of rational unpleasantness .

For a network flow graph G=(V, E) with source s and sink t, then the following three conditions are equivalent:

  1. The flow f is the maximum flow of the graph G
  2. There is no augmentation path in the residual network Gf
  3. For a certain cut (S, T) of G, then f = C(S, T)

First prove that 1 => 2:

We use counter-evidence to assume that flow f is the maximum flow of graph G, but there is also an augmenting path p in the residual network whose flow is fp. Then we have flow f'=f+fp>f. This contradicts that f is the maximum flow.

Then prove that 2 => 3:

Suppose there is no augmenting path in the residual network Gf, so there is no path from s to t in the residual network Gf. We define the S set as: the points that s can reach in the current residual network. Also define T=VS.

At this point (S, T) constitutes a cut (S, T). And for any u∈S, v∈T, there is f(u,v)=c(u,v). If f(u,v) 0, s can reach v, which contradicts that v belongs to T.

So there is f(S,T)=Σf(u,v)=Σc(u,v)=C(S,T).

Finally prove that 3 => 1:

Since the upper bound of f is the minimum cut, when f reaches the capacity of the cut, it will obviously reach the maximum value, so f is the maximum flow.

This explains why when the augmenting path cannot be found, the maximum flow must be obtained. The general idea is to use the cut as a springboard to prove it.

Dinic (to be explained with a hierarchy diagram)

Let's calculate the complexity of EK. First, in the residual network, the minimum number of steps from s to t is defined as the number of layers of the residual network. We call a residual network with the same number of layers a stage.

Let the number of layers of the original residual network be k. It is easy to find that with an increase, k is either unchanged or increased. The reason for the increase in k is that augmentation will not increase the traffic of the forward edge, but will only increase the traffic of the backward edge, so the augmentation path will take more backtracking. (Sensual pleasure here, see the paper for details )

So the number of layers is strictly increasing. Since the length of the shortest path is at least 1 and at most n-1, there are at most n-1 layers, which is approximately n layers. In each layer, each augmentation reduces at least one useful edge. So reduce at most m edges. The EK algorithm finds the bfs used for the augmentation path, so the time complexity is O(n*m^2).

The only thing Dinic did was change bfs to dfs. In each stage, first use a bfs to determine the level of all points, and then force the dfs to only run from shallow to deep points. This way you can use dfs instead of bfs. The time complexity is optimized to O(n^2*m), which is generally written in the examination room.

As for sap. . Anyway, I'm not ready to learn (I won't use .jpg)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324978303&siteId=291194637