Ford-fulkerson solution of maximum flow problem. But 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, augmented paths and cuts. This is covered in detail in this article, and we provide a Java implementation of the method in the next article.
Before introducing three concepts, we briefly introduce the basic idea of the Ford-fulkerson method. The first thing to understand is that Ford-fulkerson is an iterative approach. At the beginning, all u,v belong to the V,f (u,v) =0 (where F (u,v) represents the current flow of the side of U to v), i.e. the value of the initial state Shireu is 0. In each iteration, you can increase the flow value by looking for an "augmented path." The augmented path can be viewed as a path from the source point S to the meeting point T, which can be pressed into more streams, thereby increasing the value of the stream. Repeat this process until the augmented path is found.
For example, as shown in the figure, each red line represents an augmented path, and the current flow of S to T is 3.
Of course, this is not the maximum flow of the network, according to the search for augmented path algorithm we can actually continue to look for augmented path, the ultimate maximum flow network as shown in the following figure, the maximum flow is 4.
Next we'll explain how to find an augmented path. Before we introduce the augmented path, we first need to introduce the concept of a residual network.
First, the residual network
As the name suggests, a residual network is a network of a given network and a stream that corresponds to a stream that can be accommodated. Specifically, it is assumed that a network g= (v,e), its source point S, the meeting point T. Set a stream in F to G, corresponding to the flow of vertex u to vertex v. In the case of C (U,V) (c for Side capacity), the additional network traffic that can be pressed between U and V is the residual capacity (residual capacity) of the Edge (U,V) as follows:
R (u,v) =c (U,v)-F (u,v)
For example, suppose (u,v) that the current flow is 3/4, then the C (u,v) =4,f (u,v) = 3, then r (u,v) = 1.
We know that there is such a rule in the network stream. There are 3 units of traffic from U to V, so from the opposite direction, that is, from V to u there are 3 units of residual network, then R (v,u) = 3. It can be understood that from U to v there are 3 units of flow, then from V to u have the ability to the 3 units of the flow of pressure back.
Let's take a specific look at an example of a streaming network as shown in the following figure
Its corresponding residual network is:
Ii. augmented path
After understanding the residual network, let's introduce the augmented path. Given a stream network g and flow F, augmented path p is a simple path from S to T in its residual network GF. Image of the understanding from S to t there is a path that does not violate the capacity of the side, to this path into the flow, you can increase the flow value of the entire network. In the residual network above, there is an augmented path:
It can be pressed into 4 units of traffic, press into, we get a new stream network, its flow than the original network of 4 more. At this point we continue to find the augmented path in the same way on the new streaming network until we find it. Then we get one of the largest network streams.
Third, the Flow network cut
The above only introduces the method, but how to prove that when no longer find the augmented path, it is proved that the current network is the maximum flow network. This requires the maximum flow minimum cut theorem.
Firstly, the concept of cutting is introduced. The Cut (s,t) of the Stream network G (v,e) divides V into S and t=v-s, making s belong to the T of S,t. The capacity of a cut (s,t) is the sum of the capacity of all the sides (with direction) from the set S to the set T (in the opposite direction, must be s-àt). If f is a stream, the net flow through the cut (S,T) is defined as F (s,t) (including the reverse, sàt positive, and t->s negative). Take the example above and draw a cut, as shown in the following picture:
The capacity of the Cut is C (u,w) +c (v,x) =26
The net flow through cut of current stream network is f (u,w) +f (v,x)-F (w,v) =12+11-4=19
Obviously, we have a cut on any one, the upper bound of the net flow through the cut is the capacity of the cut, that is, it is impossible to exceed the cut capacity. So the maximum flow of the network must not exceed the minimum cut of the network.
But what does this have to do with the augmented path on the residual network?
First of all, we must understand a feature, according to the last article in the maximum flow problem of linear programming, mentioned, flow network of the principle of the conservation of flow, according to this principle we can know that the network of arbitrary cut, the net flow is equal. Concrete proof is not difficult, can be understood by the image below,
Compared with the above cut, the set S has less u and V, the net flow from the source point S to the set T flows to both U and V, whereas in the last cut, the flow of set S to the set T is equal to the net flow of U and V to the set T. Where W also flows to the U and V, and this shunt cannot flow to the source point S, because there is no path, the last part of the flow, along with the flow of S to u and V, flows between U and V at any rate, and eventually flows to the set T, so the flow value is equal to the value of s flowing to u and v. Comparing S to a faucet, the flow of U and V to the other is from S, and it is impossible to create the current. So the net flow of any cut is equal.
Everything is ready now to prove that f is the maximum flow of G when the residual network GF does not contain an augmented path.
Assuming that GF does not contain an augmented path, that is, GF does not contain a path from S to V, defines a pathway from S to V in S={V:GF, which is the set of points in GF where s can have access, apparently this set does not include T, because s to T has no path. At this time, we make t=v-s. Then (S,T) is a cut. As shown in the following illustration:
Then, for vertex u belong to s,v belong T, there is f (u,v) =c (u,v). Otherwise (U,V) there is residual flow, so s to u plus u to v constitutes a path of S to V, so v must belong to S, contradiction. So this indicates that the current flow f is equal to the current cut capacity, so f is the maximum flow.
Three. Java implementation
To familiarize yourself with the following process with pseudo code first
Ford-fulkerson (G,t,s)
1 for each edge (U,V) belongs to E (G)
2 Do f[u,v]=0
3 f[v,u]=0
4 While there exists a path p from s to T in the residual network Gf
5 do CF (P) =min{cf (U,V):(u,v) was in P}
6 for each edge (U,V) in P
7 do F[U,V]=F[U,V]+CF (p)
8 F[v,u]=-f[u,v]
If we use breadth-first search in 4 lines to compute the augmented path p, that is to find the shortest augmented path of s to T, we can improve the bounds of Ford-fulerson, which is the edmonds-karp algorithm of Ford-fulkerson method.
It is proved that the running time of the algorithm is O (ve*e), and it is easy to know, the upper bound of all times of increasing convection is O (VE), each iteration time O (E)
Class Fordfulkerson {private Double residualnetwork[][]=null;
Private double flownetwork[][]=null;
public final int N;
int parent[]; Public Fordfulkerson (int N) {this.
p = =;
Parent=new Int[n]; /** * An algorithm for implementing the Fordfulkerson Method--edmondskarp algorithm * @param graph * @param s * @param t * @return/Publ
IC Double Edmondskarpmaxflow (double graph[][],int s,int t) {int length=graph.length;
Double F[][]=new Double[length][length];
for (int i=0;i<length;i++) {Arrays.fill (F[i], 0);
Double R[][]=residualnetwork (graph,f);
Double Result=augmentpath (r,s,t);
Double sum=0;
while (result!=-1) {int cur=t;
while (cur!=s) {f[parent[cur]][cur]+=result;
F[cur][parent[cur]]=-f[parent[cur]][cur];
R[parent[cur]][cur]-=result;
R[cur][parent[cur]]+=result;
Cur=parent[cur];
} Sum+=result;
Result=augmentpath (r,s,t);
} residualnetwork=r;
Flownetwork=f; RetUrn sum; /** * deepcopy * @param c * @param f * @return/private double[][] Residualnetwork (double c[][],do
Uble f[][]) {int length=c.length;
Double R[][]=new Double[length][length];
for (int i=0;i<length;i++) {for (int j=0;j<length;j++) {r[i][j]=c[i][j]-f[i][j];
} return R; /** * Breadth-first traversal, looking for the path of Grace, is also the shortest augmented path * @param graph * @param s * @param t * @return/public double AUGM
Entpath (double graph[][],int s,int t) {double maxflow=integer.max_value;
Arrays.fill (parent,-1);
Queue<integer> queue=new linkedlist<integer> ();
Queue.add (s);
Parent[s]=s;
while (!queue.isempty ()) {int p=queue.poll ();
if (p==t) {while (p!=s) {if (maxflow>graph[parent[p]][p)) maxflow=graph[parent[p]][p];
P=PARENT[P];
} break; for (int i=0;i<graph.length;i++) {if (i!=p&&parent[i]==-1&&graph[p][i]>0) {//flow[i]=math.min (flow[p], graph[p][i]);
Parent[i]=p;
Queue.add (i);
}} if (Parent[t]==-1) return-1;
return maxflow;
Double[][] Getresidualnetwork () {return residualnetwork;
Double[][] Getflownetwork () {return flownetwork; }
}
Reprint Link: http://blog.csdn.net/smartxxyx/article/details/9293805