### The Maximum Flow Algorithm

• Algorithm overview

• The max. flow algorithm consists of 2 parts:

• A labelling procedure:

 Label the appropriate vertices in order to find a flow augmenting path from S → T

• A flow augmentation procedure:

 Increases the flow along the flow augmenting path found in the previous step.

• The Max. flow algorithm

• Psuedo code:

 ``` for ( each edge e in network ) do { f(e) = 0; } repeat { Clear the label of all nodes; Use DFS to find a path S → T { During DFS traversal: 1. Use only "flow augmenting edges" (1. forward edges that are unsaturated or 2. backward edges with flow > 0) 2. if ( node visited is unlabeled ) label the node x with the predecessor node } if ( T received a label ) { // T was reached by a flow augmenting path !! 1. Use the labels to trace (back) the path; 2. increase flow by the slack of the (flow augmenting) path } } until T not reached during DFS ```

• Example: DFS with labeling

• Sample flow:

• We start in S.

The only flow augmenting edge available is: S → C.

DFS visits and labels the node C:

• The DFS continues from node C

The only flow augmenting edge available is: C → E.

DFS visits and labels the node E:

• The DFS continues from node E

The only flow augmenting edge available is the backward edge: E → B !!!

DFS visits and labels the node B:

• The DFS continues from node B

The flow augmenting edges are:

 B → D B → F (Edge B → E is disqualified because E is already labeled !!!)

Let's use B → D first....

DFS visits and labels the node D:

• The DFS continues from node D

The flow augmenting edges are:

 D → T The backward edge D → A

Let's use D → T first....

DFS visits and labels the node T:

DONE !!!

• Flow augmenting path:

Slack = 1

After increasing flow by 1:

• Worked out example: (Ford-Fulkerson algorithm)

• Basic network:

• Initial flow:

• Find a flow augmenting path using DFS (traverse node in alpha-numerical order)

(The algorithm uses labels.

The flow augmenting path is highlighted for your convenient.)

Augment flow: by 3

• Find a flow augmenting path using DFS (traverse node in alpha-numerical order)

Augment flow: by 1

• Find a flow augmenting path using DFS (traverse node in alpha-numerical order)

Augment flow: by 1

• Find a flow augmenting path using DFS (traverse node in alpha-numerical order)

Augment flow: by 1

• Find a flow augmenting path using DFS (traverse node in alpha-numerical order)

• No more flow augmenting paths

Done

• Practice

• Find a maximum flow in the following basic network:

Solution: (max flow = 17)

Flow augmenting paths are "color coded" with the given amount of flow passing through various links.