Clever Geek Handbook
📜 ⬆️ ⬇️

Ford-Fulkerson Algorithm

The Ford - Fulkerson algorithm solves the problem of finding the maximum flow in the transport network .

The idea of ​​the algorithm is as follows. Initially, the value of the stream is assigned the value 0:f(u,v)=0 {\ displaystyle f (u, v) = 0} f (u, v) = 0 for allu,v∈V {\ displaystyle u, v \ in V} u, v \ in V . Then the flow magnitude iteratively increases by searching for an increasing path (path from source s to drain t , along which a larger flow can be sent). The process repeats until a magnifying path can be found.

Content

Algorithm

Informal Description

  1. Zero all threads. The residual network initially coincides with the original network.
  2. In the residual network, we find any path from the source to the drain. If there is no such way, stop.
  3. We run through the found path (it is called the increasing path or the increasing chain ) the maximum possible flow:
    1. On the found path in the residual network, we are looking for an edge with minimal throughputcmin {\ displaystyle c _ {\ min}}   .
    2. For each edge on the found path, increase the flow bycmin {\ displaystyle c _ {\ min}}   , and in the opposite - we reduce bycmin {\ displaystyle c _ {\ min}}   .
    3. Modify the residual network. For all edges on the found path, as well as for edges opposite to them, we calculate a new throughput. If it became nonzero, add an edge to the residual network, and if it is zero, we erase it.
  4. We return to step 2.

It is important that the algorithm does not specify which path we are looking for in step 2 or how we do it. For this reason, the algorithm is guaranteed to converge only for whole bandwidths, but even for them, with large values ​​of bandwidths, it can work for a very long time. If the throughputs are real, the algorithm can work indefinitely without converging to the optimal solution (see the example below ).

If you search not for any path, but for the shortest, you get the Edmonds – Karp algorithm or the Dinits algorithm . These algorithms converge for any real weights in timeO(|V||E|2) {\ displaystyle O (| V || E | ^ {2})}   andO(|V|2|E|) {\ displaystyle O (| V | ^ {2} | E |)}   respectively.

Formal Description

Dan EarlG(V,E) {\ displaystyle G (V, E)}   with bandwidthc(u,v) {\ displaystyle c (u, v)}   and flowf(u,v)=0 {\ displaystyle f (u, v) = 0}   for edges from u to v . It is necessary to find the maximum flow from source s to sink t . At each step of the algorithm, the same conditions apply as for all flows:

  • f(u,v)⩽c(u,v){\ displaystyle \ f (u, v) \ leqslant c (u, v)}   . Stream outu {\ displaystyle u}   atv {\ displaystyle v}   does not exceed bandwidth.
  • f(u,v)=-f(v,u){\ displaystyle \ f (u, v) = - f (v, u)}   .
  • ∑vf(u,v)=0⟺fin(u)=fout(u){\ displaystyle \ \ sum _ {v} f (u, v) = 0 \ Longleftrightarrow f_ {in} (u) = f_ {out} (u)}   for all nodesu {\ displaystyle u}   , Besidess {\ displaystyle s}   andt {\ displaystyle t}   . The flow does not change when passing through the node.

Residual networkGf(V,Ef) {\ displaystyle G_ {f} (V, E_ {f})}   - network with bandwidthcf(u,v)=c(u,v)-f(u,v) {\ displaystyle c_ {f} (u, v) = c (u, v) -f (u, v)}   and without flow.

Entry CountG {\ displaystyle G}   with bandwidthc {\ displaystyle c}   , a sources {\ displaystyle s}   and stockt {\ displaystyle t}  
Output Max Flowf {\ displaystyle f}   ofs {\ displaystyle s}   att {\ displaystyle t}  

  1. f(u,v): =0{\ displaystyle f (u, v): = 0}   for all the edges(u,v) {\ displaystyle (u, v)}  
  2. As long as there is a wayp {\ displaystyle p}   ofs {\ displaystyle s}   att {\ displaystyle t}   atGf {\ displaystyle G_ {f}}   such thatcf(u,v)>0 {\ displaystyle c_ {f} (u, v)> 0}   for all ribs(u,v)∈p {\ displaystyle (u, v) \ in p}   :
    1. To findcf(p)=min{cf(u,v)|(u,v)∈p} {\ displaystyle c_ {f} (p) = \ min \ {c_ {f} (u, v) \; | \; (u, v) \ in p \}}  
    2. For each rib(u,v)∈p {\ displaystyle (u, v) \ in p}  
      1. f(u,v): =f(u,v)+cf(p){\ displaystyle f (u, v): = f (u, v) + c_ {f} (p)}  
      2. f(v,u): =f(v,u)-cf(p){\ displaystyle f (v, u): = f (v, u) -c_ {f} (p)}  

A path can be found, for example, by a breadth-first search ( Edmonds-Karp algorithm ) or depth-deep search inGf(V,Ef) {\ displaystyle G_ {f} (V, E_ {f})}   .

Difficulty

At each step, the algorithm adds the incremental path stream to the existing stream. If the capacities of all the edges are integers, it is easy to prove by induction that the flows through all the edges will always be integer. Therefore, at each step, the algorithm increases the flow by at least one, therefore, it converges in no more than O ( f ) steps, where f is the maximum flow in the graph. You can complete each step in time O ( E ), where E is the number of edges in the graph, then the total time of the algorithm is limited to O ( Ef ).

If the throughput of at least one of the edges is an irrational number, then the algorithm can work infinitely, without even necessarily converging to the correct solution. An example is given below.

Example of a non-convergent algorithm

 

Consider the network on the right, with the sources {\ displaystyle \ s}   by stockt {\ displaystyle \ t}   bandwidtheone {\ displaystyle \ e_ {1}}   =one {\ displaystyle \ 1}   ,e2 {\ displaystyle \ e_ {2}}   =r=(five-one)/2 {\ displaystyle r = ({\ sqrt {5}} - 1) / 2}   ,e3 {\ displaystyle \ e_ {3}}   =one {\ displaystyle \ 1}   and the throughput of all other edges equal to an integerM≥2 {\ displaystyle M \ geq 2}   . Constantr {\ displaystyle \ r}   chosen so thatr2=one-r {\ displaystyle \ r ^ {2} = 1-r}   . We use the paths from the residual graph given in the table, andpone={s,vfour,v3,v2,vone,t} {\ displaystyle \ p_ {1} = \ {s, v_ {4}, v_ {3}, v_ {2}, v_ {1}, t \}}   ,p2={s,v2,v3,vfour,t} {\ displaystyle \ p_ {2} = \ {s, v_ {2}, v_ {3}, v_ {4}, t \}}   andp3={s,vone,v2,v3,t} {\ displaystyle \ p_ {3} = \ {s, v_ {1}, v_ {2}, v_ {3}, t \}}   .

StepPath foundAdded streamResidual bandwidth
eone{\ displaystyle e_ {1}}  e2{\ displaystyle e_ {2}}  e3{\ displaystyle e_ {3}}  
0r0=one{\ displaystyle r ^ {0} = 1}  r{\ displaystyle r}  one{\ displaystyle 1}  
one{s,v2,v3,t}{\ displaystyle \ {s, v_ {2}, v_ {3}, t \}}  one{\ displaystyle 1}  r0{\ displaystyle r ^ {0}}  rone{\ displaystyle r ^ {1}}  0{\ displaystyle 0}  
2pone{\ displaystyle p_ {1}}  rone{\ displaystyle r ^ {1}}  r2{\ displaystyle r ^ {2}}  0{\ displaystyle 0}  rone{\ displaystyle r ^ {1}}  
3p2{\ displaystyle p_ {2}}  rone{\ displaystyle r ^ {1}}  r2{\ displaystyle r ^ {2}}  rone{\ displaystyle r ^ {1}}  0{\ displaystyle 0}  
fourpone{\ displaystyle p_ {1}}  r2{\ displaystyle r ^ {2}}  0{\ displaystyle 0}  r3{\ displaystyle r ^ {3}}  r2{\ displaystyle r ^ {2}}  
fivep3{\ displaystyle p_ {3}}  r2{\ displaystyle r ^ {2}}  r2{\ displaystyle r ^ {2}}  r3{\ displaystyle r ^ {3}}  0{\ displaystyle 0}  

Note that after step 1, as well as after step 5, the residual ability of the edgeseone {\ displaystyle e_ {1}}   ,e2 {\ displaystyle e_ {2}}   ande3 {\ displaystyle e_ {3}}   are shapedrn {\ displaystyle r ^ {n}}   ,rn+one {\ displaystyle r ^ {n + 1}}   and0 {\ displaystyle 0}   , respectively, for some kind of naturaln {\ displaystyle n}   . This means that we can use magnifying paths.pone {\ displaystyle p_ {1}}   ,p2 {\ displaystyle p_ {2}}   ,pone {\ displaystyle p_ {1}}   andp3 {\ displaystyle p_ {3}}   infinitely many times, and the residual throughput of these edges will always be in the same form. The total flow after step 5 isone+2(rone+r2) {\ displaystyle 1 + 2 (r ^ {1} + r ^ {2})}   . For infinite time, the full flow will converge toone+2∑i=one∞ri=3+2r {\ displaystyle \ textstyle 1 + 2 \ sum _ {i = 1} ^ {\ infty} r ^ {i} = 3 + 2r}   , while the maximum flow is2M+one {\ displaystyle 2M + 1}   . Thus, the algorithm not only works infinitely long, but does not even converge to the optimal solution. [one]

Example

The following example shows the first steps of the Ford-Fulkerson algorithm in a transport network with four nodes, source A and drain D. This example shows the worst case. When using a breadth-first search, the algorithm only needs 2 steps.

WayThroughputResult
Initial transport network 
A,B,C,D{\ displaystyle A, B, C, D}  min(cf(A,B),cf(B,C),cf(C,D))={\ displaystyle \ min (c_ {f} (A, B), c_ {f} (B, C), c_ {f} (C, D)) =}  
min(c(A,B)-f(A,B),c(B,C)-f(B,C),c(C,D)-f(C,D))={\ displaystyle \ min (c (A, B) -f (A, B), c (B, C) -f (B, C), c (C, D) -f (C, D)) =}  
min(1000-0,one-0,1000-0)=one{\ displaystyle \ min (1000-0,1-0,1000-0) = 1}  
 
A,C,B,D{\ displaystyle A, C, B, D}  min(cf(A,C),cf(C,B),cf(B,D))={\ displaystyle \ min (c_ {f} (A, C), c_ {f} (C, B), c_ {f} (B, D)) =}  
min(c(A,C)-f(A,C),c(C,B)-f(C,B),c(B,D)-f(B,D))={\ displaystyle \ min (c (A, C) -f (A, C), c (C, B) -f (C, B), c (B, D) -f (B, D)) =}  
min(1000-0,0-(-one),1000-0)=one{\ displaystyle \ min (1000-0.0 - (- 1), 1000-0) = 1}  
 
After the 1998 steps ...
End network 

See also

  • Ford-Fulkerson Theorem

Links

  • YouTube task solution example
  • Algorithm Visualizer
  • Implementing Ford-Fulkerson Max Stream Search in Java
  •   Wikimedia Commons has media related to the Ford-Fulkerson Algorithm

Literature

  • Thomas H. Cormen et al. Algorithms: Construction and Analysis = INTRODUCTION TO ALGORITHMS. - 2nd ed. - M .: "Williams", 2006. - S. 1296. - ISBN 0-07-013151-1 .

Notes

  1. ↑ Zwick, Uri. The smallest networks on which the Ford-Fulkerson maximum flow procedure may fail to terminate (English) // Theoretical Computer Science : journal. - 1995 .-- 21 August ( vol. 148 , no. 1 ). - P. 165-170 . - DOI : 10.1016 / 0304-3975 (95) 00022-O .
Source - https://ru.wikipedia.org/w/index.php?title=Ford____Falkerson's algorithm&oldid = 100973197


More articles:

  • Dogwood
  • Star Defender 2
  • Otto Gang (ship)
  • Loli
  • Afanasenkov, Vladimir Nikolaevich
  • Macklin, Don (singer)
  • Plague Post
  • Part of the film
  • Oko (satellite system)
  • Kashgaria

All articles

Clever Geek | 2019