Goldberg Tarjan Push Relabel Algorithm

The maximum s-t flow has a value of 6

# The maximum flow problem

Suppose that we have a communication network, in which certain pairs of nodes are linked by connections; each connection has a limit to the rate at which data can be sent. Given two nodes on the network, what is the maximum rate at which one can send data to the other, assuming no other pair of nodes are attempting to communicate? (source)

This is a typical instance of a maximum flow problem: given an underlying network, where the edge weights denote the maximum possible capacity per edge, one wants to find out how much can be transerred over the edges from the source node s to the target node t.

## What do you want to do first?

maxflow-graph-editor.svg

## Legende

 node edge with capacity

## Which graph do you want to execute the algorithm on?

### Modify it to your desire:

• To create a node, make a double-click in the drawing area.
• To create an edge, first click on its start node and then on its end node. Alternatively, you may (single-)click on the drawing field to create a new node as end node.
• Right-clicking deletes edges and nodes.

• Maxflow specific:
• The maximum capacity of an edge can be changed by a double-click on the edge or its weight.

### Upload an existing graph:

A occured when reading from file: the contents:

### What next?

Graph G maxflow-graph-algorithm-graph.svg

## Legende

 source and target nodes current node active nodes edge with flow ≤ cap flow in blue, capacity in gray corresponding to thickness
Residual Graph G' with axis: maxflow-graph-algorithm-height.svg

## Legende

 Active node with height/excess. The height of the bar corresponds to the excess. Residual edges e' with their residual capacities c' leaving the current node. Ineligble edges are gray. Residual edge used for push. Residual edge to minmum height neighbour used for relabel.

## Algorithm status

### First choose a source node

Click on a node to select it as the source/starting node s

### Then choose a target node

Click on a node to select it as the target/sink node t. If you want to change the source node, go back with prev.

### Goldberg-Tarjan Push-Relabel maximum flow algorithm

Source and target node have been selected and are filled with green. Per default, these are the nodes with lowest and hightest id. If you want to change the target node, go back with prev.

Edges are annotated with preflow/capacity, where the latter corresponds to the thickness of the gray line.

Now the algorithm can begin. Click on next to start it

### Initializing the preflow

Set the preflow f(e) (light blue) to the maximum capacity c(e) for all edges emanating s and set f(e) = 0 for all other edges. Add all nodes v ≠ t having (s,v) ∈ E to the queue Q of active nodes (yellow).

The edges in G are labeled with f(e)/c(e) denoting the current preflow along the edge and its maximum capacity. The nodes in G' are labeled with height/excess, where the latter one is also shown as a bar next to the node.

### Initializing the height function

For each node v ≠ s set h(v) to the shortest directed path from v to t in the network G where the length of a path is the number of edges of the path. (In particular, set h(t) = 0). This can be done in time O(|V| + |E|) by a breadth first search starting at t and using all edges in the opposite direction. The source s isn’t reached by this BFS. We initialize h(s) by setting h(s) = |V|.

We mapped the height of a node to the y axis in G'.

### Main loop

As long as the queue Q containing the active nodes (in yellow) isn’t empty pop the first node v from the front of the queue. We call v the current node and fill it with red.

In the following, we will try to apply push or relabel operations to v to get rid of its excess flow e(v). These operate on the residual edges E' in G' leaving the active node and are displayed with dashed lines and labeled with their residual capacities c'.

### Check for admissible push operations

While the current node has excess e(v)>0 and the residual network G'=(V,E') contains an edge that is eligible or legal with respect to the current height function, i.e. there is an edge e'=(v,w) having h(v)==h(w)+1, we can apply a push operation.

All residual edges which are not legal are grayed out. If there is a legal residual edge e' it is displayed in orange.

### Push

Push δ = min{e(v), c'(e')} amount of flow from v to w. More precisely, if e' ∈ E' is a forward edge (-->) with respect to an edge e of G, increase the preflow f(e) of e by δ, and if e' is a backward edge (<--), then decrease the preflow f(e) of e by δ.

By doing so, e(v) is decreased by δ, and e(w) is increased by δ. If w ≠ s,t, and if w wasn't active before, w becomes active, and is added at the end of the queue Q containing the active nodes.

### Check for an admissible relabel operation

If the current node still has excess e(v)>0 and if there is no legal edge emanating from v in the residual network, then apply a relabel operation.

### Relabel

Increase the height h(v) of the current node so that it is exactly one level above the minimum height of its adjacent nodes in the residual Graph G'. The residual edge e* to the adjacent node of minimum height is displayed in purple.

Since the current node still has excess, re-add it to the end of the queue Q of active nodes after that.

### Finished

The algorithm terminated with a maximum flow value of:

### Variable status:

v Q e' e*
- - -

s ← pick(v)

t ← pick(v)

BEGIN

(* Initialize the preflow *)

FORALL e=(u,w) ∈ E

f(e) ← (u == s) ? c(e) : 0

IF u == s AND w ≠ t THEN Q.add(w)

(* Initialize the height function *)

h(s) ← |V|

FORALL v ∈ V\{s}

h(v) ← #arcs on shortest v-t path

(* Main Loop *)

WHILE Q ≠ ∅

v ← Q.pop()

WHILE e(v)>0 AND ∃ e'=(v,w)∈E'|h(v)==h(w)+1

(* PUSH *)

push min(e(v),c'(e')) flow from v to w

IF w ≠ s,t AND w ∉ Q THEN Q.add(w)

IF e(v)>0

(* RELABEL *)

h(v) ← 1+min({h(w)|e*=(v,w)∈E'})