Computing the Minimum Cut and Maximum Flow of ... - CiteSeerX

4 downloads 0 Views 170KB Size Report
Keywords: Graph Theory, Maximum Flow, Minimum Cut. 1 Introduction. This work presents an algorithm for computing the maximum flow of undirected graphs.
Universidade Federal do Paran´a Departamento de Inform´atica

Jonatan Schroeder Andr´e Pires Guedes Elias P. Duarte Jr.

Computing the Minimum Cut and Maximum Flow of Undirected Graphs

Relat´orio T´ecnico RT-DINF 003/2004

Curitiba, PR 2004

Computing the Minimum Cut and Maximum Flow of Undirected Graphs Jonatan Schroeder Andr´e Pires Guedes Elias P. Duarte Jr. Federal University of Paran´ a - Dept. of Informatics P.O. Box 19081 CEP 81531-990 Curitiba PR Brazil {jonatan,andre,elias}@inf.ufpr.br

Abstract This work presents an algorithm for computing the maximum flow and minimum cut of undirected graphs, based on the well-known algorithm presented by Ford and Fulkerson for directed graphs. The new algorithm is equivalent to just applying Ford and Fulkerson algorithm to the directed graph obtained from original graph but with two directed arcs for each edge in the graph, one in each way. We present a proof of correctness and experimental results. Keywords: Graph Theory, Maximum Flow, Minimum Cut

1

Introduction

This work presents an algorithm for computing the maximum flow of undirected graphs. This algorithm differs from those applied to directed graphs (or digraphs), since in undirected graphs an edge can be used in both ways, and if it’s used in a way, it cannot be used in the other way. One of the applications of the new algorithm is the computation routes between two hosts in a computer network, as presented by [6]. The algorithm is based in the same concept used by Ford and Fulkerson in [4], which is based on the computation of flow augmenting paths. These paths take an existing flow and construct a new flow that is greater than the original flow. The new algorithm is equivalent to just applying Ford and Fulkerson algorithm to the directed graph obtained from original graph but with two directed arcs for each edge in the graph, one in each way, as shown in figure 1. This figure contains an example of undirected graph (A) and its corresponding directed graph (B). The reason that the original algorithm by Ford and Fulkerson can be applied is that, considering the two arcs between a given pair of vertices, when an arc is used in a flow, the other arc cannot be used, otherwise it would not satisfy the skew simmetry, which is described in section 2.

1

a

b

a

b

c

c

d

d

f

f

e

e

(A)

(B)

Figure 1: Example of an undirected graph and its corresponding directed graph. As the proposed algorithm is based on Ford and Fulkerson’s algorithm, we make a brief description of that algorithm in section 2. In section 3 we present the new algorithm considering undirected edge-weighted graphs. In section 4 we present the proof of correctness of the proposed algorithms. In section 5, we briefly describe a Java implementation of the algorithm, and finally section 6 contains our conclusions.

2

A Brief Description of Ford & Fulkerson Algorithm

One of the most well known algorithms for computing the maximum flow of a digraph is the algorithm presented by Ford and Fulkerson [4]. This algorithm uses flow-augmenting paths to increase existing flows in the digraph, so that in each iteration the flow is greater. We give a brief description of the problem and the algorithm below.

2.1

Algorithm Specification

Definition: Given a connected digraph G = (V, E), and a pair of nodes s, t ∈ V , called respectivelly source and sink, let c : E → R∗+ be the capacity of the edges in G. A flow in G is a function f : V × V → R such that: ∀u, v ∈ V, f (u, v) ≤ c(u, v) ∀u, v ∈ V, f (u, v) = −f (v, u) X ∀u ∈ V − {s, t}, f (u, v) = 0

(1) (2) (3)

v∈V

In other words, equation 1, known as the capacity constraint property, indicates that the resources used by a flow in an edge cannot be greater than the capacity of that edge. Equation 2, known as the skew simmetry property, says that the net flow from node u to node v is the negative of the net flow in the reverse direction. Thus, the net flow from a node to itself is 0, since for all nodes, f (u, u) = −f (u, u) implies that f (u, u) = 0. Equation 3, known as the flow conservation property, says that the sum of all flows that enter in a node (negative flows) plus the sum of all flows that leave that node (positive flows) is 0. Definition: Given a connected digraph G = (V, E). Let f be a flow in G. The value of the flow f is defined as: X X |f | = f (s, v) = f (v, t) v∈V

v∈V

2

for each edge (u, v) ∈ E do f [u, v] ← 0 f [v, u] ← 0 while there exists a path p from s to t with no cycles in the residual network Gf do ∆ ← min{cf (u, v) : (u, v) ∈ p} for each edge (u, v) in p do f [u, v] ← f [u, v] + ∆ f [v, u] ← −f [u, v] Figure 2: The algorithm proposed by Ford and Fulkerson. The value of a flow is the total flow that leaves s and, as proved in [2], is equal to the total flow that enters t. Definition: Given a connected digraph G = (V, E), and considering a pair of nodes u, v ∈ V . Let f be a flow in G. The residual capacity of the pair (u, v), or cf (u, v), is given by: cf (u, v) = c(u, v) − f (u, v) The residual capacity is used by the algorithm to determine how much flow can pass through a pair of nodes. It is used basically in the definition of the so called residual network, given below. Definition: Given a connected digraph G = (V, E). Let f be a flow in G. The residual network of G induced by f is graph Gf = (V, Ef ), where: Ef = {(u, v) ∈ V × V : cf (u, v) > 0} The residual network is an auxiliar graph used by the algorithm descripted below. Problem: Given a connected digraph G = (V, E), where V is a set of nodes and E is a set of edges between these nodes (E ⊆ V × V ), a capacity c : E → R∗+ and two nodes s and t, find a maximum flow (a flow whose value is maximal) from source s to sink t in G. Let f be this flow1 . Initially, the algorithm presented in figure 2 creates an initial flow that is empty, i.e., there is no flow between any pair of nodes. Next, a randomly chosen path is obtained from the residual network. Since the residual network contains edges only where the residual capacity is positive, the path obtained will be composed by nodes that can increase the flow. In this path, the minimum residual capacity of all pairs corresponds to the amount that can be increased in all node pairs so that the capacity is not overrun. Finally, the flow amount in the edges is increased, and the algorithm searches a new path in the residual network. When no path is found, than the flow cannot be increased, so it is the maximum flow.

3

a 12

8

s

4

6

5

9

b

a

e

7

9

f

12

3

t

9

b

4 15 11

8

d 6

13

2

11

6 g

5/12

8

s

2

11

5/9

5

3 9

f

5

7 t

8

s

8

12

g

12

c

8

s

5

6

4

2

5/11

8

8

s

6

10/11

13

2

c

5

2 g

a 5

8

s

t

10 8

d

5

b

13

2

1

10/10

4

6

4

15

e

7 5

7

3 5/9

f

t

4

15 8

d

10

5 1

5

2

c

g

3 5

f

4

5

5/7

5/12

10

(F)

4

5/6

8

7

e

4

t

5

g

5/9

b

5

d

c

6

5/5

9

f 10

5/7

7

3

4

4

13

6

(E)

5/12

e

2

10/10

5/12

a

g

5

b 4

5

d 6

5

6

t

5/15

13

c

8

s

9

f

5

7

3

4

5/9

b

5

2

7

e

7 5/5

8

(D) a

5/12

5

t

5

6

(C) a

10 d

5/7

9

f

4

13

3

4 5

b

2

11

5/10

e

6

4

d 6

g

7

5/15

13

c

a

4

4

10

7

12

c

e

6

b

t

(B)

7 5/5

8

d

(A) a

9

f

15 10

7

12

c

3

4

13

2

4

6

5 8

s

e

7

g 7

(G)

(H)

Figure 3: Example execution of the algorithm by Ford and Fulkerson.

4

a 5/12

4/8

s

5

6

5/5

4

2

10/11

9/9

f

4

s

t

8

9 4

10

d

1

5

5/12

g 7

4/8

s

4

11/11

5 1/3 9/9

f

7

9 4

11

1

5/12

6/8

s

4

11/11

2

1/13

g

c

a 5 3/3 9/9

f

7

12

t

15 8

d

10

5 1

5

2

c

g

3 9

f

5

5/7

5/12

9 4

11

10/10

4

6

b

2

3

8

d

2

3

6

s

t

e

3 4

15

5/6

2

7

4

9/9

b

10

(L)

6

2/5

5

c

e

3/7

t

5

(K) a

8

5

g

5/12

1

9

f

d

5/7

5/6

2

15

12

3 10/10

4

6

b

4

8

d

4

1

4

s

t

e

1 6

15

1/13

c

a

4

9/9

b

2

(J)

6

4/5

10

2

c

e

1/7

t

5

(I) a

8

5

g

5/12

9

f

d

5/7

5/6

3

15

13

2

1

10/10

4

6

b

4

e

7 5

7

15

13

c

3

4

9/9

b

a

e

7

g 7

(M)

(N)

Figure 3: (cont.) Example execution of the algorithm by Ford and Fulkerson.

5

a 3/12

8/8

s

4

6

5

6/9

b 4

13

2/2

11/11

8/12

3/3 9/9

f

t

1/9

b

15 3/8 10/10 5/7

5/6 8/12

c

a 8/12

4/8

s

1/9

b 1/4

10/11

6/13

2

9/9

f

5/12

3/3

g

t

6/8

s

e

3/7

4

6

2/5

9/9

b 4

15

10/10

11/11

1/13

2

6/12

(C)

8

d

10/10 5/7

5/6 c

t

15

7/7 g

3/3 9/9

f

3/8

d

6/6 c

a

4/4

1/6

5

10/10 6/7

(B) e

7/7

t

3/8

7/12

(A)

9/9

f

d

6/6 g

3/3

15

3/13

2

6/11

4/4

1/6

5

8/8

s

e

7/7

4

d

c

a

e

3/7

5/12

g

(D)

Figure 4: Feasible maximum flows for graph shown in figure 3.

2.2

Example Execution

An example showing the execution of this algorithm is shown in figure 3. This figure contains a sequence of graphs that represent the obtained flow step by step. In these graphs, the labels of the arcs contain, in this order, the flow used in that arc and its capacity. When only one number is found, than there is no flow passing through the arc. The initial graph is presented in (A), and its corresponding residual network is the graph shown in (B). The first augmenting path found is the path (s, a, b, f, d, g, t), also shown in (B). In this path, the smallest capacity is the capacity of arc (a, b), which is equal to 5. So, the flow used in pairs (s, a), (a, b), (b, f ), (f, d), (d, g) and (g, t) increases in 5 units, as shown in (C), and in the new residual network in (D). Next the same procedure is repeated for path (s, c, g, t). The result is shown in (E), and the new residual network in (F). In the residual network, shown in (F), path (s, c, d, f, t) is found. In this case, the flow used between pair (d, f ), equal to -5 (by the skew simmetry), is increased in 5 units, becoming equal to 0. So, the new flow formed by this augmenting path does not use pair (f, d), that had been used before. The new flow is presented in (G), and the corresponding residual network is shown in (H). The same process runs with path (s, b, f, t), resulting in the flow shown in (I). Its corresponding residual network is shown in (J). Next, path (s, c, b, a, e, t) is considered, resulting in the flow in (K). Note that, in this case, the flow of the pair (c, b) is +1, and, by skew simmetry, the flow of the pair (b, c) is -1. Consequently, the residual capacity cf (c, b) is equal to 1 We use brackets when we treat an identifier – such as f – as a mutable field, and we use parenthesis when we treat it as a function.

6

edge path

a

s

t

b Figure 5: Example of the use of algorithm. 13 − (+1) = 12, and the residual capacity cf (b, c) is equal to 2 − (−1) = 3. These results in the residual network shown in (L). Finally, path (s, b, a, e, t) is taken, resulting in the flow shown in (M), whose residual network is shown in (N). This residual network contains no path between s and t, so that the flow shown in (M) is the maximum flow. The maximum flow is not always unique. Some graphs can contain more than one flow that has a maximal value. As an example, for the graph shown in figure 3(A), all flows shown in figure 4 are feasible maximum flows, among other possible for that graph. The result will depend on the augmenting paths used, since there are, in many cases, more than one possible augmenting path for each step of the algorithm.

3

Finding the Maximum Flow of Undirected Graphs

The main concept behind the algorithm is to obtain individual augmenting paths that can be used to increment an existing flow. Augmenting paths are paths from the source to the sink of the flow that increase the existing flow. Using edges not used in the flow, or edges partially used, we can obtain paths that increase the flow. But we can also decrease the used capacity for a used edge, so that it can be re-used in another augmenting path. Consider as an example the graph shown in figure 5. In order to simplify the example, only a portion of the graph is represented. The dashed edges can contain more nodes not visible in the figure. There is a path between nodes s and a, and between nodes s and b. There is also a path between nodes a and t, and between nodes b and t. On the other hand, there is only an edge between nodes a and b. Consider initially an empty flow between s and t. We can use the path formed by the path between s and a, the edge between a and b and the path between b and t. This way, we will obtain an augmenting path, since none of the edges in the path is already used in the flow. The flow is then formed uniquely by this path. Next, we consider the path formed by the path between s and b, the edge between b and a and the path between a and t. The edge between b and a has been already used but in the other direction (from a to b). In the algorithm, this edge is marked as unused, since we can find a flow that combines both paths. In the example, the resulting flow will be composed by the path between s and a, the path between a and t, the path between s and b and the path 7

between b and t. The edge between a and b can then be used again by the algorithm to compose a new flow augmenting path, considering the nodes and edges not shown in figure. In other words, consider, as an example, that node s is a water producer and node t is a water consumer. The other nodes of the graph, say a and b, are the connection points, and the edges are the connections. Suppose that initially s sends water to a, who sends it to b, who finally sends it to t. But someone deduces that s can also start sending water to b, and then a stops to send water to b and starts sending to t. With this modification, the volume of water that is sent increases, as water is flowing from s to t both through a and b. The connection between a and b can be used again by another path.

3.1

Algorithm Specification

These definitions are similar to the corresponding definitions shown in section 2 for digraphs, but are adapted to undirected graphs. Definition: Given a connected undirected graph G = (V, E), and a pair of nodes s, t ∈ V , called respectivelly source and sink, let c : E → R∗+ be the capacity of the edges in G. A flow in G is a function f : V × V → R such that: ∀u, v ∈ V, f (u, v) ≤ c({u, v}) ∀u, v ∈ V, f (u, v) = −f (v, u) X ∀u ∈ V − {s, t}, f (u, v) = 0

(4) (5) (6)

v∈V

Definition: Given a connected undirected graph G = (V, E). Let f be a flow in G. The value of the flow f is defined as: X X |f | = f (s, v) = f (v, t) v∈V

v∈V

Definition: Given a connected undirected graph G = (V, E), and considering a pair of nodes u, v ∈ V . Let f be a flow in G. The residual capacity of the pair (u, v), or cf (u, v), is given by: cf (u, v) = c({u, v}) − f (u, v) Definition: Given a connected undirected graph G = (V, E). Let f be a flow in G. The residual network of G induced by f is digraph Gf = (V, Ef ), where: Ef = {(u, v) ∈ V × V : cf (u, v) > 0} The residual network is always directed, either for directed or undirected graphs. Problem: Given a connected undirected graph G = (V, E), where V is a set of nodes and E is a set of edges between these nodes (E ⊆ {{u, v} : u, v ∈ V }), a capacity c : E → R∗+ and two nodes s and t, find a maximum flow (a flow whose value is maximal) from source s to sink t in G. Let f be this flow. The algorithm presented in figure 6 is similar to the algorithm by Ford and Fulkerson, but considering undirected graphs, i.e., the order of nodes connected by an edge does not matter, as well as the associated capacity.

8

for each edge {u, v} ∈ E do f [u, v] ← 0 f [v, u] ← 0 while there exists a path p from s to t with no cycles in the residual network Gf do ∆ ← min{cf (u, v) : (u, v) ∈ p} for each edge (u, v) in p do f [u, v] ← f [u, v] + ∆ f [v, u] ← −f [u, v] Figure 6: The proposed algorithm.

3.2

Example Execution

An example showing the execution of this algorithm in shown in figure 7. In this figure, the representation of the flow is the same used in directed graphs, but there is also a half head showing the direction of the flow. The execution is based on the original graph shown in (A). The residual network of the original graph is shown in (B). The first path that is found is path (s, b, d, c, g, f, t), also shown in (B). In this path, the minimum capacity is the capacity of edge (b, d), that is equal to 3. The use of the path as an augmenting path results in the flow shown in (C). The corresponding residual network is shown in (D). The next augmenting path considered is path (s, c, d, f, e, t), also shown in (D). The minimum capacity in this case is equal to 6, from edge (d, f ). The new flow is shown in (E). Note the edge (c, d), that had been already used in previous path, but in the other direction. In this node, 3 units are removed from the direction (d → c), so that the node is not more used in the flow. The remaining 3 units are than used in the direction (c → d), and the node is now used in a new direction. The new residual network is shown in (F). The execution proceeds with path (s, b, f, d, c, g, t), resulting in the flow shown in (G) and in the residual network shown in (H). Note that, in this step, the process for node (c, d) is repeated in the other direction. In the sequence, the path (s, b, a, e, f, g, t) is taken, resulting in the flow shown in (I) and in the residual network shown in (J). Next, the path (s, c, d, f, t) is considered, resulting in the flow shown in (K) and in the residual network shown in (L). The next path that is considered is path (s, c, d, g, f, t), and the new flow is shown in (M), with the residual network shown in (N). In the sequence, path (s, b, f, t) is considered, resulting in flow shown in (O), whose residual network is shown in (P). Finally, The path (s, a, f, t) is the last path found, resulting in the final flow shown in (Q). As shown in the residual network in (R), there is no feasible augmenting path, so the found flow is a maximum flow.

4

Proofs

To show that this algorithm constructs a maximum flow from s to t, we must show that:

9

5

5

a

a

e

12 15

s

2

5

9

6

b

18

5

3

t

15

s

b

20

7

d

6

10 7

d 4

g

1

c

5

a

e

2

3/15

9

6

b

18

3/13

f

e

5

12

s

g

8

(B)

5

5

10

8

(A)

12

7

1 4

8

a

t

6

3 11

1

c

13

11

10

18 13

3

20

4

9

f

6

6

11

9

2

5

15

20

18

2

12

6

13

f

e

5

12

18

2

12

5

9

2

5

9

6

t

18

s

b

18 16

f

6

10

t

12

3/3

6

6 20

20

11

3/7

d

10 11

10

10

d 1

1

1

g

c

(D) 5

5

a

e

s

3/15

6/18

2

5 6

3/13

f

5

18

s

b

15

16

6 26

d

12 10

d 7

g

1

c

(F) 5

5

a

e 6/18

2

5/6

b

3/13

f

5

2

5

23

s

b

7

d

5

g

c

(G)

4

5

1 6

c

10

d 2

1 8/8

10

15

14

2/4

16

11 11

5/10

12

7

6 26

3/7

3

f

1

3/3 11

15 11

t

1/6 6/20

24

2

12

6/9

e

5

12

8/15

g

5

(E)

s

10

11

3/8

5

4

1 1

12

t

10 11

10 14

a

10

11

1

c

12

12

3/7

3/4

3

f

6

3/3 11

24

2

5

6

t

6/6 6/20

e

5 2

12

6/9

b

g

5

12

12

10

11

(C) a

4

1 7

3/8

c

6

11

20

3/4

6

1 16

g

(H)

Figure 7: Example execution of the algorithm proposed by this paper.

10

t

5/5

a

10

a

e 12

12

s

13/15

6/18

2

5/5

5/6

b

12

1/9 3/13

f

28

s

b

10

2

d

16

11

10/10

5

d

g

1 16

c

(I)

10

a

e 12

12

s

13/15

6/18

2

5/5

8/13

f

28

s

b

10

21

d

11 11

10/10 9

5

d 7

1

g

1 16

c

(K)

10

a

e 12

12

s

13/15

6/18

2

5/5

9/13

f

28

s

b

10

8

12 22

f

1

t

4

2

3/3

12

6 32

11

24

2

10

11

t

6/6 12/20

e 2

12

1/9 5/6

b

g

(L)

5/5

a

20

9

1 1

8/8

t

5

12

6 31

c

12

2

2/7

3/4

8

f

1

3/3 11

24

2

10

11

t

6/6 11/20

e 2

12

1/9 5/6

b

g

(J)

5/5

a

20

9

1 6

c

t

5

2

1 8/8

10

11

14

2/4

12

7

6 26

2/7

8

f

1

3/3 11

24

2

10

11

t

1/6 6/20

e 2

3/7

d

11 11

10/10

6

d

20

8

8

4/4

1/1 8/8

c

8

g

2

16

c

(M)

(N)

5/5

a

10

a

e 12

12

s

14/15

6/18

2

5/5

10/13

f

29

s

10

12

b

8

12

f

3

t

1

3/3

12

6 32

11

24

2

10

23

t

6/6 12/20

e 2

12

1/9 6/6

b

g

3/7

d

11 11

10/10

6

d

8

20

8

4/4

c

1/1 8/8

8

g

c

(O)

2

16

g

(P)

Figure 7: (cont.) Example execution of the algorithm proposed by this paper.

11

5/5

a

10

a

e

e

14

2/12

s

14/15

2/2

5/5

6/18

6/6

b

12/13

f

24

10

1/9

4

29

s

12

b

12

f

1

t

1

3/3

12

6 32

11

8 24

t

6/6 12/20

10

10

3/7

d

11 11

10/10

6

d

8

20

8

4/4

c

1/1 8/8

8

g

c

(Q)

2

16

g

(R)

Figure 7: (cont.) Example execution of the algorithm proposed by this paper. 1. The algorithm constructs a flow; 2. This flow is a maximum flow; 3. The algorithm terminates after a finite number of steps. The proofs of each one of these items will be discussed in this section.

4.1

The Algorithm Constructs a Flow

As presented in section 3.1, a flow must satisfy some properties. The proof consists in demonstrating each one of the properties in the resulting flow. In each iteration of the algorithm, the result is a flow, so the final result is also a flow. In the following, we call fi the flow in step i. Capacity constraint property: For nodes that compound the augmenting path, we have fi (u, v) = fi−1 (u, v)+∆. But ∆ is the minimum value of all residual capacities in the augmenting path. So, ∆ ≤ cfi−1 (u, v) = c({u, v}) − fi−1 (u, v). Applying this property to the equation above, we have fi (u, v) ≤ fi−1 (u, v) + c({u, v}) − fi−1 (u, v), and fi (u, v) ≤ c({u, v}), satisfying the capacity constraint.  For nodes in the opposite direction, we have fi (u, v) = −fi (v, u) = − fi−1 (v, u) + ∆ = fi−1 (u, v)−∆. As ∆ > 0 (by the definition of residual network), fi (u, v) < fi−1 (u, v) ≤ c({u, v}), satisfying the capacity constraint. For the other nodes, the flow is not modified, so fi (u, v) = fi−1 (u, v) ≤ c({u, v}), satisfying the capacity constraint. Skew simmetry property: In all cases in which the flow is updated, the flow in the reverse direction is also updated, and always with the opposite value. Since the augmenting path has no cycles, each pair is updated only once in each step, so the skew simmetry will always be mantained. Flow conservation property: The augmenting path can be defined as (a0 , a1 , a2 , . . . an ), with a0 = s, an = t and aj ∈ V − {s, t} for each 1 ≤ j ≤ n − 1. Consider ∆ as the minimum capacity of this augmenting path. For each node of the path, except for the source and the sink, the

12

sum of all incident flows of node aj is: X fi (aj , v) = fi (aj , aj+1) + fi (aj , aj−1 ) + v∈V

X

fi (aj , v)

v∈V −{aj+1 ,aj−1 }

  = fi−1 (aj , aj+1 ) + ∆ + fi−1 (aj , aj−1 ) − ∆ +

X

fi−1 (aj , v)

v∈V −{aj+1 ,aj−1 }

= fi−1 (aj , aj+1) + fi−1 (aj , aj−1) +

X

fi−1 (aj , v)

v∈V −{aj+1 ,aj−1 }

=

X

fi−1 (aj , v)

v∈V

=0 resulting that the flow conservation property is preserved.

4.2

The Flow is a Maximum Flow

The following proof is based on a similar proof presented in [3]. Definition: Given a connected graph G = (V, E), directed or undirected, and a pair of nodes s, t ∈ V . A (s − t) cut is a partition of V into S and T = V − S, such that s ∈ S and t ∈ T . The capacity of the cut, represented as c(S, T ), is given by: XX c(u, v) u∈S v∈T

Definition: A minimum cut is a cut whose capacity is minimal. Consider a cut (S, T ) in graph G = (V, E). Any flow in this graph must be smaller than or equal to the capacity of this cut, since every flow unit must cross the cut. Since this predication is valid for all cuts and for all flows, we deduce that the value of the maximum flow is never greater than the capacity of the minimum cut. In order to demonstrate that the maximum-flow algorithm has indeed produced a maximum flow, we need only produce a cut separating s from t whose capacity equals the value of the terminal flow produced by the algorithm. This is done as follows. The algorithm terminates when no augmenting path can be found. After the final application of the algorithm, there is a set of nodes that is reachable from s in the resulting residual network. Let R be this set of nodes, and let R′ be the set of the unreachable nodes. Clearly, R′ = V − R, so pair (R, R′ ) is a cut. Upon termination of the algorithm, each edge formed by a given node u ∈ R and a given node v ∈ R′ carries a flow equal to its capacity, in the direction u → v; otherwise the residual capacity of the pair of nodes would be positive, and v would be reachable in the residual network. Clearly, every flow unit must traverse an arc of this cut at least once. Since all these edges carry the flow in the direction u → v, there is no flow unit being carried from R′ to R, and no flow unit can traverse this cut more than once. Thus, the total flow from s to t equals the capacity of this cut, because every edge from the source side to the sink side carries a flow equal to its capacity.

13

4.3

The Algorithm Terminates After a Finite Number of Steps

Let’s initially accept that all edge capacities are integers. In this case, in each step of the algorithm, the flow is increased at least by one unit. Since the graph is a finite graph, the maximum flow is also finite, so the algorithm will take no more steps than the maximum flow. A similar idea can be used to prove that the algorithm is finite for rational numbers. For irrational numbers, it’s proved that, in some cases, the algorithm will not finish. Further documentation about this cases can be found in [4]. This work is restricted to cases where edge capacities are rational.

5

Implementation

The algorithm has been implemented, specifically for undirected graphs with no capacity (i.e., unitary capacity). The implementation is used specifically to find the minimum cut, that is a related concept, as presented in section 4.2. The implementation is developed in Java language [8], using the library JDigraph, available in [7]. The algorithm is used as a part of the implementation of a connectivity simulator, and the complete source code is available in [6].

6

Conclusion

In this paper we present an algorithm for computing the maximum flow of undirected graphs based on augmenting paths. We also present the proof of correctness in terms of that the algorithm construct a flow, this flow is a maximum flow and the algorithm terminates after a finite number of steps. Future work will use the proposed algorithm for applications related to edge connectivity in computer networks, specifically problems related to network routing.

References [1] J. COHEN, E. P. DUARTE JR., Fault-Tolerant Routing Based on Network Connectivity, IEEE DRCN, Budapest, 2001. [2] T. H. CORMEN, C. E. LEISERSON, R. L. RIVEST, Introduction to Algorithms, The Massachusetts Institute of Technology Press, 1990. [3] J. EVANS, E. MINIEKA, Optimization Algorithms for Networks and Graphs, 2nd edition, Dekker, Monticello, 1992. [4] L. R. FORD JR., D. R. FULKERSON, Flows in Networks, Princeton University Press, 1962. [5] D. R. KARGER, M. S. LEVINE, Finding Maximum Flows in Undirected Graphs Seems Easier than Bipartite Matching, Proc. 30th Annual ACM Symp. on Theory of Computing, 69-78, 1998. [6] J. SCHROEDER, P. R. TORRES JR., N. P. MOLINA JR., Busca de desvios em redes baseada nos crit´erios de conectividade #C(v) e MCC(v), Trabalho de 14

conclus˜ao de curso, Bacharelado em Ciˆencia da Computa¸ca˜o, Universidade Federal do Paran´a, 2003. [7] D. WALEND, JDigraph, http://jdigraph.sourceforge.net, accessed in Feb’2004. [8] Java Technology, http://java.sun.com, accessed in Feb’2004.

15

Suggest Documents