Reaves.dev

v0.1.0

built using

Phoenix v1.7.17

Ford-Fulkerson

Stephen M. Reaves

::

2025-02-20

Ford-Fulkerson algorithm to find max flow

Summary

Find the max flow of a graph by iteratively augmenting the residual graph

Contents

Problem Setup

Sending supply from vertex s to t

Goal is to maximize amount sent without exceeding capacity

Gssaas->a6bbs->b4ccs->c5ttdda->d8eea->e2d->t5d->c3b->e1e->d2ffc->f8f->t7f->e3

A flow network is a graph G=(V,E), designated s,t in V, and for each e in E, capacity ce>0 c_e > 0

fe= f_e = flow along edge e

eE,0fece \forall e \in E, 0 \le f_e \le c_e

vVst, \forall v \in V - {s \bigcup t}, flow in must equal flow out (conserved)

vVst,wvEfwv=vzEfvz \forall v \in V - {s \bigcup t}, \displaystyle\sum_{\overrightarrow{wv} \in E}f_{wv} = \displaystyle\sum_{\overrightarrow{vz} \in E}f_{vz}

size of flow is total flow sent

Gssaas->a6/6bbs->b1/4ccs->c5/5ttdda->d6/8eea->e0/2d->t5/5d->c2/3b->e1/1e->d1/2ffc->f7/8f->t7/7f->e0/3
Gssaas->a6/6bbs->b1/4ccs->c5/5ttdda->d6/8eea->e0/2d->t5/5d->c2/3b->e1/1e->d1/2ffc->f7/8f->t7/7f->e0/3

size = 12

There’s never a reason to use a cycle

Anti-Parallel Edges

We can simplify the graph by removing anti-parallel edges

Gssaas->a7bbs->b9a->b2tta->t5b->a3b->t4
Gssaas->a7bbs->b9a->b2tta->t5b->a3b->t4
Gssaas->a7bbs->b9a->b2tta->t5ffb->f3b->t4f->a3

Toy Example

Gssaas->a10bbs->b7a->b10tta->t7b->t10

Simple Algorithm

Start by initializing the flow to be zero everywhere

Create an available graph based on the input graph and try to find a path from s to t

Send max flow along that path

Repeat until there is no more path from s to t

instead we can create a Residual Graph by adding antiparallel edges to one way edges

Residual Network

For flow network G=(V,E0) with ce for e in E, and fe for e in E.

residual network Gf=(V,Ef)

if vwE&fvw<cvw \overrightarrow{vw} \in E &amp; f_{vw} < c_{vw} then add vw \overrightarrow{vw} to Gf with capacity cvwfvw c_{vw} - f_{vw}

if vwE&fvw>0 \overrightarrow{vw} \in E &amp; f_{vw} > 0 then add wv \overrightarrow{wv} to Gf with capacity fvw f_{vw}

Ford-Fulkerson Algorithm

Runtime

O(mC) where C is size of max flow (assuming integer capacities)