[GO] Network stream algorithm--ford-fulkerson method and its multiple implementations

Source: Internet
Author: User
Tags dashed line new set

Network flow

Reprinted from: http://www.cnblogs.com/luweiseu/archive/2012/07/14/2591573.html

The topic we discussed in the previous chapter is the shortest path between vertices in the graph, such as the shortest path between two locations on a road map, so we abstracted the road map as a weighted graph. In this chapter we will further extend the model based on the weighted graph.

In many systems, traffic problems are involved, such as the traffic flow in the road system, the data flow in the network, and the oil supply pipeline. We can further understand the graph as a "flow network" and use such an abstract model to solve the problem of traffic.

Diagram schematic diagram can be abstracted as network flow

Each channel in a flow network can be thought of as a transport material, and each pipe has a fixed capacity, which can be seen as the maximum speed at which a substance can flow through the pipe. Vertices are cross-join points between pipelines, except sinks, where matter flows through only these points, without any further vertex retention or consumption. That is, the velocity at which a substance enters a vertex must be equal to the speed at which the vertex is left. This feature is referred to as "stream conservation" (flow conservation). The circuit schematic diagram in the example, according to the Kirchhoff current law, at each cross connection point out, the current flow into the current equal to the outflow. The current is defined as the amount of charge in a section of a wire per unit of time, that is, the flow velocity of the charge. Therefore, the concept of flow conservation can be understood as: the speed at which the charge flows into a crossing vertex equals the speed at which the vertex is left.

In this chapter we will discuss the maximum flow problem, which is the simplest problem in the flow network: The maximum rate at which a substance is transferred from the source to the sink point is solved without violating the capacity constraints. This chapter mainly introduces the basic concepts and properties of streaming networks and streams, and provides the data structure description and implementation of flow network, and a classical method to solve the maximal flow and its algorithm implementation, namely Ford-fulkerson method.

1 Stream Network

The network stream g= (V, E) is a forward graph where each edge (U, v) has a non-negative capacity value, recorded as C (U, v) ≧0. if (U, v) ∉e can specify C (U, v) = 0. There are two special vertices in the network stream, namely the source point S and the meeting point T.

One concept associated with network flow is the flow. Set G is a stream network with a capacity of C. Set S to the source point of the network, T is the sink point, then the stream of G is a function f:vxv→r, satisfies the nature:

L Capacity limit: to all vertex pairs u,v∈v, satisfies f (U, v) ≦c (U, v);

L Anti-symmetry: to all vertices to u,v∈v, satisfies f (u, v) =-F (v, u);

L Flow Conservation: to all vertices to u∈v-{s, t}, satisfies ΣV∈VF (u,v) = 0.

F (U, v) is called a stream from vertex u to vertex v, and the value of the stream is defined as:

|f| =ΣV∈VF (S,V),

That is, the total flow from the source point S.

In the maximum flow problem, we need to solve the maximum flow f (s, t) between the source point S and the meeting point T, and we also want to know the flow that reaches that value. For a specified source point s and the net of the specified sink point T, we call it the st-net.

is a flow network in which the thickness of the edges between vertices corresponds to the capacity size of the wildest.

Graph-to-graph representation of network flow

The following is an example of an attempt to find the maximum flow in a graph under three properties of a stream (a~c).

From (A~C), it can be found that the flow network from the source point s outflow of the amount of 2,3,5, and the flow into the sink point T 2,3,5. In fact, any flow from the s outflow should always be equal to the inflow of the sink point T, the following is a simple proof of this proposition.

Construct: (a), extend the original stream network, increase the vertex s ' and an edge (s ', s), the flow and capacity of the edge are equal to the value of the stream flowing from S; increase the vertex T ' and an edge (T, T '), the Edge's flow and capacity are equal to the value of the stream to T.

We want to prove that the outflow of s ' is equal to the inflow of T ', as long as it proves to the arbitrary vertex set, the outflow is equal to the inflow amount. Use inductive proof.

Proof: For a vertex set composed of a single vertex, its outflow is necessarily equal to the outflow; Assuming that this property is true for a given vertex collection A, it is necessary to verify that the new set a ' =a∪{v} that is obtained after adding a vertex v also satisfies this property.

, for set A, stream from V to F3, the other inflow is F1, flow to V is recorded as F4, and the other outgoing traffic is total F6. Note that the flow here refers to the value of the stream and is non-negative.

The inflow of A is fin (a) = F1 + F3, with an outflow of fout (a) = F2 + F4;

F1 + F3 = f2 + F4;

For Vertex V, the relationship is derived according to the second property of the stream:

F6 + F3 = f5 + F4.

Depending on the two equations above, you can get the relationship:

F1–f6 = F2–f5,

That

F1 + f5 = F2 + F6.

A ' inflow of fin (a ') = F1 + F5, outflow Fout (a ') = F2 + F6, so set A ' satisfies the attribute.

Applying this attribute to all vertices in the original stream network before the extension, you can conclude that the flow on the edge (s ', s) equals the flow on the edge (t ', t), i.e. the inflow from the s outflow equal to the sink point T.

2 Ford-fulkerson method

This section begins with a discussion of the Ford-fulkerson method for solving the maximum flow problem, which is also known as the "Extended path method", which is the basis of a large number of algorithms and has many implementation methods. In later chapters we will introduce and analyze a particular algorithm.

The Ford-fulkerson algorithm is an iterative algorithm that first zeros the flow size of all vertex pairs in the graph, at which point the network flow size is also 0. In each iteration, the value of the stream is increased by looking for an "augmented path" (augument path). The augmented path can be thought of as a path from the source point S to the meeting point T, and along this path can add more streams. Iterations until the augmented path position can no longer be found, at which point there must be at least one edge full edge in all paths from the source point to the sink point (i.e. the size of the edge stream is equal to the capacity size of the edge).

A new concept, the "augmented path", is mentioned here. We will further introduce the "Residue Network" (residual networks) to discuss the algorithm of finding the augmented path, and introduce the "Maximum flow Minimum cut" (Max-flow min cut) theorem to prove the correctness of the Ford-fulkerson algorithm.

2.1 Residue Net

Given a stream network G and a stream, the residue net of the stream GF has the same vertex as the original. Each edge of the original stream network will correspond to one or two edges in the residual net, for any edge in the original stream network (U, v), the flow is f (U, v), the capacity is C (U, v):

L if f (U, v) > 0, it contains an edge (V, u) with a capacity of f (U, v) in the residue net;

L if f (U, v) < C (U, v), the residual net contains a capacity of C (U, v)-F (U, v) of The Edge (U, v).

The residue nets allow us to use any generalized graph search algorithm to find an augmented path, since the path from the source point S to the sink T in the residue network directly corresponds to an augmented path. In this paper, the augmented path and its corresponding residue network (A~D) are analyzed with the example of graph.

(a) the original graph stream network with 0 flows on each edge. Since f (U, v) = 0 < C (U, v) contains edges (U, v) with a capacity of C (U, v) in the residue net, the vertices in the residue graph are the same as the original flow network, and the edges are the same as the original flow network.

In the residue network can find an augmented path <v0, v1, v3, V5>, each edge of the flow of 2, the original flow network and the corresponding edge of the residual network will be changed, such as.

(b) After operation (a), the path <v0, V1, v3, and v5> have a stream of size 2, at which point the corresponding edges in the residual graph need to be adjusted:

F (0, 1) > 0, with a 2-capacity edge (1, 0) in the residue diagram;

C (1, 3) > F (1, 3) > 0, with an edge (1, 1) and a capacity of 3 (2, 3) with a capacity of 1 in the residue map;

F (3, 5) > 0, with a 2-capacity edge (5, 3) in the residue diagram.

In the residue network can find an augmented path <v0, v2, v4, V5>, each edge of the flow of 1, the original flow network and the residual network will change, such as.

(c) after operation (b), the path <v0, V2, V4, and v5> have a stream of size 1, at which point the corresponding edges in the residual graph need to be adjusted:

C (0, 2) > F (0, 2) > 0, with an edge (2, 0) and a capacity of 2 (1, 2) with a capacity of 0 in the residue map;

F (2, 4) > 0, with a 1-capacity edge (4, 2) in the residue diagram;

C (4, 5) > F (4, 5) > 0, with an edge (2, 4) and a capacity of 5 (1, 5) in the residue diagram.

Further in the residue network can find an augmented path <v0, v2, v3, v1, v4, V5>, each side of the flow of 1, the original flow network and the residual network will be changed, such as.

(d) after operation (c), the path <v0, V2, v3, V1, V4, and v5> have a stream of size 1, at which point the corresponding edges in the residual diagram need to be adjusted:

C (0, 2) > F (0, 2) > 0, with an edge (1, 0) and a capacity of 2 (2, 2) with a capacity of 0 in the residue map;

F (2, 3) > 0, with a 1-capacity edge (3, 2) in the residue diagram;

C (3, 1) > F (3, 1) > 0, with an edge (1, 3) and a capacity of 1 (2, 1) with a capacity of 3 in the residue map;

F (1, 4) > 0, with a 1-capacity edge (4, 1) in the residue diagram;

C (4, 5) > F (4, 5) > 0, with an edge (1, 4) and a capacity of 5 (2, 5) with a capacity of 4 in the residue map;

At this point, the path to vertex 0 to vertex 5 cannot be found in the residue diagram, then the iteration ends and we think that figure D is the maximum flow to find.

2.2 Maximum Flow min cut

We have just discussed the method of finding the augmented path based on the residue network, where we will prove that the flow that the Ford-fulkerson algorithm iterates over is the maximum flow, that is, a stream is the maximum flow, when and only if there is no augmented path in the residue net. The proof of the proposition needs to be aided by an important theorem in the flow network, that is, the maximum flow minimum cut theorem.

The cut (S, T) of the Stream network g= (V, E) divides the V into two parts of S and t=v-s, making the source point S∈s, the sink point t∈t. If f is a flow, then the flow through the cut (s, T) is represented by F (S, T) =σu∈sσv∈t f (U, v), the capacity of the cut (s, T) with C (S, T) =σu∈sσv∈t C (U, v). , a cut for the stream network ({s, v1, v2},{v3, v4, t})

Figure (a) flow network on each edge is the capacity size (b) a cut of the stream network, the edge is the size of the stream

The flow through the cut is:

F (S, T) =σu∈{s, v1, V2}σv∈{v3, v4, T} f (U, v)

= f (v1, V3) + F (v2, V3) + F (v2, v4)

= 12 + (-4) + 11 = 19

Capacity is:

C (S, T) =σu∈{s, v1, V2}σv∈{v3, v4, T} c (U, v)

= C (v1, V3) + C (v2, v4)

= 12 + 14 = 26

The cut stream may be positive or negative, and capacity must be non-negative. In a streaming network, each cut stream is the same, and its value equals the value of the stream of the stream network, and each cut is not much larger than the cut capacity.

, S ' is the extended vertex, where the flow and capacity of the edge (s ', s) equals the outflow of the vertex s, recorded as F1. The dashed line divides the flow network into two sets of S and T, forming a cut (s, t). The flow from S flows to F2, and the flow into S is F3. In the first section we prove that the inflow of the vertex collection in the flow network is equal to the outflow, so f1 + F2 = F3.

That is, F1 = F3–f2, where F1 equals the flow value of the stream network, f3-f2 the traffic for the cut (S, T), so the cut stream equals the stream value of the streaming network.

In, the calculation of the cut (S, T) of the flow of F3 provide positive flow value, and F2 provides a negative flow value, and in the calculation of the cut capacity only the capacity of the side to provide traffic F3 to participate in the addition, according to the first nature of the flow, the value of F3 will not be greater than the cut capacity, so:

F (s, t) = F3–f2≦f3≦c (S, t).

Because all the cut streams in the streaming network are equal and equal to the stream of the network, the value of any stream of any network is not larger than the capacity of any one cut.

According to the concept of the middle cut of the convection network above, the maximum flow minimum cut theorem is introduced, and the theorem is used to illustrate the correctness of the Ford-fulkerson algorithm.

Maximum flow minimum cut theorem: The maximum value in all flows in a network equals the minimum capacity in all cuts. And you can prove that three conditions are equivalent:

L f is a maximum flow of the stream network G;

L Residue Net GF does not include an augmented path;

A certain cut of L g (s, t), satisfies F (s, t) = C (S, t).

Prove:

1. (disprove) assumes that f is the maximum flow of G, but GF contains the augmented path p. Obviously at this time along the augmented path can continue to increase the flow of the network, then f is not the maximum flow of G, and the condition contradiction;

2. Assume that GF does not include an augmented path, that is, GF does not contain paths from S to T. Defined:

s = {V∈V:GF contains s to v path},

Make T = V–s, because there is no path from S to T in GF, then t∉s, so get a cut of g (S, T). For each pair of vertex u∈s,v∈t, F (u, v) = C (U, v) must be met, otherwise the edge (U, v) will be present in the edge set of GF, then v should belong to S (and in fact v∈t). So, f (s, t) = C (S, t);

3. We have shown that the value of any stream of the network is not greater than the capacity of any one cut, if a certain cut of G (S, t), satisfies F (s, t) = C (S, t), then the flow of cut (s, t) reaches the upper bound of the network stream, it must be the maximum flow.

The iterative termination condition of the Ford-fulkerson algorithm is that the residual network does not include the augmented path, and the resulting flow is the maximum flow of the network according to the equivalence condition above.

3 implementation of the Ford-fulkerson method

In the previous section, we discussed several concepts that were applied to the Ford-fulkerson method and the important attributes that ensured the correctness of the method. This section discusses the implementation of the Ford-fulkerson method, including the updating of the residue network and the acquisition of the augmented path.

The augmented path is actually the path from the source point S to the sink point T in the residual net, and can be obtained by using any of the algorithms in the graph algorithm, such as Bfs,dfs. The BFS-based algorithm is often called the EDMONDS-KARP algorithm, which is the "shortest" expansion path, where the "shortest" is measured by the number of edges on the path, not by traffic or capacity.

The path lookup method chosen here will directly affect the algorithm's run time, for example, to search for an augmented path in a residual network using a DFS approach to the graph. Figure (b) is the first search to obtain an augmented path of <s, V1, v2, t> The stream size of the path is 1, and the flow size of the augmented path found in figure (c) and (d) is also 1. As you can see, in this example, using the DFS algorithm will require 2 million searches to get the maximum flow.

If a different method is used to traverse the residual net, the maximum flow of the flow network will be obtained. , the first time you search for the next edge in Vertex 1, instead of selecting the Edge (1, 2) instead of choosing a larger edge (1, T), and the second time searching for the next edge at Vertex 2, select the Edge (2, T). This allows the maximum flow to be solved with only two traversal. It can be seen that the algorithm of searching the augmented path in the residue network directly influences the efficiency of the Ford-fulkerson method.

[GO] Network stream algorithm--ford-fulkerson method and its multiple implementations

Related Article

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.