Department of Management Engineering / Operations Research Department of Management Engineering / Operations Research The Max Flow Problem The Max Flow Problem Jesper Larsen & Jens Clausen jla,[email protected] Department of Management Engineering Technical University of Denmark Jesper Larsen & Jens Clausen 1 Department of Management Engineering / Operations Research Example We consider a digraph G = (V, E) which for each e has a capacity ue ∈ R+ . Furthermore two “special” vertices r and s are given; these are called resp. the source and the sink. Aim is to find the maximum flow from the source to the sink in the graph while respecting the capacities of the edges. Jesper Larsen & Jens Clausen 2 Department of Management Engineering / Operations Research Flow A flow in G is a function x : E → R+ satisfying: X X (1) ∀i ∈ V \ {r, s} : xji − xij = 0 (j,i)∈E (2) (i,j)∈E ∀(i, j) ∈ E : 0 ≤ xij ≤ uij For a flow P we define: P fx (i) = (j,i)∈E xji − (i,j)∈E xij fx (i) is the net flow into i or the excess for x in i, and is called the value of x. Jesper Larsen & Jens Clausen 3 Jesper Larsen & Jens Clausen 4 Department of Management Engineering / Operations Research Example with a flow Math. Programming Model of Max Flow Here we have added a flow of value 4 to our graph. Jesper Larsen & Jens Clausen Department of Management Engineering / Operations Research 5 Department of Management Engineering / Operations Research Max Flow and Cuts I max fx (s) s.t. fx (i) = 0 i ∈ V \ {r, s} 0 ≤ xe ≤ ue e ∈ E xe ∈ Z+ e∈E Jesper Larsen & Jens Clausen 6 Department of Management Engineering / Operations Research Max Flow and Cuts II We now consider R ⊂ V . δ(R) is the set of edges incident from a vertex in R to a vertex in R. δ(R) is also called the cut generated by R: δ(R) = {(i, j) ∈ E | i ∈ R, j ∈ R} Note the difference to the cut in an undirected graph. In a directed graph the cut only consists of arcs going from R to R and not the opposite direction. In an undirected graph we have δ(R) = δ(R), this does not hold here. Because the cut is uniquely defined by the vertex-set R we might simply call R the cut. R is an r,s-cut if r ∈ R and s ∈ / R. The capacity of the cut R is defined as: X u(δ(R)) = uij (i,j)∈E,i∈R,j∈R Jesper Larsen & Jens Clausen 7 Jesper Larsen & Jens Clausen 8 Department of Management Engineering / Operations Research Relationship between flows and cuts Proposition: For any r, s-cut δ(R) and any flow x we have: x(δ(R)) − x(δ(R̄)) = fx (s) Corollary: For any feasible flow x and any r, s-cut δ(R), we have: fx (s) ≤ u(δ(R)). Department of Management Engineering / Operations Research The Residual graph Suppose that x is a flow in G. The residual graph shows how flow excess can be moved in G given that the flow x is already present. The residual graph Gx for G wrt. x is defined by: V (Gx ) = V E(Gx ) = {(i, j) : (i, j) ∈ E ∧ xij < uij } ∪ {(j, i) : (i, j) ∈ E ∧ xij > 0} Short we write Vx = V (Gx ) and Ex = E(Gx ) Some textbooks use the word “auxiliary graph” instead of residual graph. Jesper Larsen & Jens Clausen 9 Department of Management Engineering / Operations Research Incrementing and augmenting path A path is called x-incrementing if for every forward arc e xe < ue and for every backward arc xe > 0. A x-incrementing path from r to s is called x-augmenting. Note: this relates to the original graph. In the Residual graph all arcs in a path are forward arcs. Jesper Larsen & Jens Clausen 11 Jesper Larsen & Jens Clausen 10 Department of Management Engineering / Operations Research Basic Approach 1. Build residual graph 2. Build augmenting path 3. If not possible stop 4. Increase flow along the augmenting path. 5. Go to step 1 Jesper Larsen & Jens Clausen 12 Department of Management Engineering / Operations Research The Augmenting Path Algorithm 7 xij ← 0 for all (i, j) ∈ E repeat construct Gx find an augmenting path P if s is reached then determine max amount K of augmentation augment x along the path P by K 8 until s is not reachable from r in Gx 1 2 3 4 5 6 Jesper Larsen & Jens Clausen 13 Department of Management Engineering / Operations Research Finding an augmenting path II 1 2 3 4 5 6 7 8 9 while Q 6= ∅ and s is not labeled yet do select a i ∈ Q and scan (i, j) ∈ Ex if (i, j) ∈ E and j unlabeled then label j; Q ← Q ∪ {j}; p[j] ← i umax [j] ← min{umax [i], uij − xij } if (j, i) ∈ E and j unlabeled then label j; Q ← Q ∪ {j}; p[j] ← i umax [j] ← min{umax [i], xji } Q ← Q \ {i}; S ← S ∪ {i} Jesper Larsen & Jens Clausen 15 Department of Management Engineering / Operations Research Finding an augmenting path I Input: The network G = (V, E, u) and the current feasible flow x. Output: An augmenting path from r to s and the capacity for the flow augmentation. Initialize: all vertices are unlabeled; Q ← {r}, S ← ∅, p[.] ← 0; umax [i] ← +∞ for i ∈ G Jesper Larsen & Jens Clausen 14 Department of Management Engineering / Operations Research Augmenting a feasible flow x Input: The network G = (V, E, u), the current feasible flow x, an augmenting path P from r to s in Gx and the x-width of P . Output: An “updated” feasible flow x′ . An updated flow is achieved by: for (i, j) ∈ P (i, j) ∈ E : x′ij ← xij + umax [s] for (i, j) ∈ P (j, i) ∈ E : x′ji ← xji − umax [s] for all other (i, j) ∈ E : x′ij ← xij Jesper Larsen & Jens Clausen 16 Department of Management Engineering / Operations Research Department of Management Engineering / Operations Research Example Max Flow - Min Cut Theorem 1 Given a network G = (V, E, u) and a current feasible flow x. The following 3 statements are equivalent: 4 3 6 6 2 1 4 3 r 3 2 5 4 s An r, s-cut R exists with capacity equal to the value of x, ie. u(R) = fx (s). 2 6 7 x is a maximum flow in G. A flow augmenting path does not exist (an r-s-dipath in Gx ). 1 8 1 3 2 3 Jesper Larsen & Jens Clausen 6 17 Department of Management Engineering / Operations Research Concluding Remarks We call an augmenting path from r to s shortest if it has the minimum possible number of arcs. The augmenting path algorithm with a breadth-first search solves the maximum flow problem in O(nm2 ). Breadth-first can easily be established using a queue. Jesper Larsen & Jens Clausen 19 Jesper Larsen & Jens Clausen 18
© Copyright 2026 Paperzz