Вы находитесь на странице: 1из 24

Preflow Push Algorithm

M. Amber Hassaan
Max Flow Problem
Given a graph with Source and Sink nodes we want to compute:
The maximum rate at which fluid can flow from Source to Sink
The rate of flow through each edge of the graph
Given a graph:
Edges have flow capacities
First value is flow capacity
Second value is current flow rate
Edges behave like pipes
Nodes are junctions of pipes
History:
Ford and Fulkerson 1956 (Augmenting Paths)
Dinic 1970
Edmonds and Karp 1972
Min-cut
a
Malhotra, Kumar and Maheshwari 1978
Goldberg and Tarjan 1986 (Preflow Push) 5, 2 4, 4
Boykov and Kolmogorov 2006

s 6, 2 t

8, 7 5, 5
Preflow Push Algorithm b 2
Max Flow Problem
Flow f(u,v) is a real-valued function defined for
every edge (u,v) in the graph
The flow needs to satisfy the following 3
properties:
c(u,v) i.e. capacity of edge (u,v)
f(u,v)
f(u,v)
= - f(v,u)
Flow coming into node v = Flow leaving v
a
5, 2 4, 4

s 6, 2 t

8, 7 5, 5

Preflow Push Algorithm


b 3
Max Flow Problem
Residual Graph:
A Graph that contains edges that can admit more flow
Define a Graph G(V,E) for G(V,E)
We define residual flow r(u,v) = c(u,v) f(u,v)
If r(u,v) > 0 then (u,v) is in E

Original Graph a a Residual Graph


2
5, 2 4, 4 4
3
s 6, 2 t s 4 t
2
1
8, 7 5, 5 5
7
b Preflow Push Algorithm
b 4
Preflow Push Algorithm for Maxflow problem
Relaxation algorithm:
Performs local updates repeatedly until global constraint is
satisfied
Similar to Stencil computations
Fluid flows from a higher point to a lower point
In the beginning
Source is the highest point
Sink and all other nodes are at the lowest point
Source sends maximum flow on its outgoing edges
Sending flow to out-neighbors is called Push operation
The height of Sources neighbors is then increased so
that fluid can flow out
Increasing height of a node is called Relabel operation

Preflow Push Algorithm 5


Preflow Push Algorithm for Maxflow problem
A node is allowed (temporarily) to have
more flow coming into it than flow going
out
i.e.a node can have excess flow
But the edges must respect the capacity
condition
Source can have arbitrary amount of excess
flow
A node is said to be active if it has
excess flow in it
Preflow Push Algorithm 6
Preflow Push Algorithm for Maxflow problem
We increase the height of the active node with
a Relabel operation
Ifh is the minimum height among neighbors that can
accept flow
Then height is relabeled to (h+1)
Then we push the excess flow to the neighbors
That are lower than the active node and can admit
flow
Thus make them active
Algorithm terminates when there are no active
nodes left
Preflow Push Algorithm 7
Example h=0 h=0
e=0 e=0
15,0
a b
A simple graph: 10,0 3,0
Nodes have two attributes:
Height h
5,0
Excess flow e
s t
Edges have pairs: 8,0
First value is edge capacity h=6 h=0
Second value is flow 17,0 e=0
12,0
Initialize:
s has h=6 i.e. number of c d
6,0
nodes h=0 h=0
Push 10 along (s,a) e=0 e=0
e(a) = 10
Push 12 along (s,c)
e(c) = 12

Preflow Push Algorithm 8


Example h=0 h=0
e=10 e=10
15,0
a b
Relabel c with h=1 10,10 3,0

Push 6 along (c,d) 5,0


e(d) = 6 s t
8,0
h=6 h=0
Relabel c with h=2 17,0 e=0
12,12
Push 5 along (c,a) c d
6,0
e(a) = 5 h=1 h=0
e=12 e=0
Relabel c with h=7
Push -1 along (s,c)

Preflow Push Algorithm 9


Example h=1 h=0
e=15 e=0
15,0
a b
Relabel a with h=1 10,10 3,0

Push 15 along 5,5


(a,b) s t
8,0
e(b) = 15 h=6 h=0
17,0 e=0
12,11
c d
6,6
h=7 h=0
e=0 e=5

Preflow Push Algorithm 10


Example h=1 h=1
e=0 e=15
15,15
a b
Relabel b with h=1 10,10 3,0

Push 3 along (b,t) 5,5


e(t) = 3 s t
8,0
h=6 h=0
Push 8 along (b,d) e=3
12,11 17,0
e(d) = 14
c d
Relabel b with h=2 6,6
h=7 h=0
Push -4 along (a,b) e=0 e=6
e(a) = 4

Preflow Push Algorithm 11


Example h=1 h=2
e=4 e=0
15,11
a b
Relabel d with h=1 10,10 3,3

Push 14 along (d,t) 5,5


e(t) = 17 s t
8,8
h=6 h=0
17,0 e=3
12,11
c d
6,6
h=7 h=1
e=0 e=14

Preflow Push Algorithm 12


Example h=3 h=2
e=4 e=0
15,11
a b
Relabel a with h=3 10,10 3,3

Push 4 along (a,b) 5,5


e(b) = 4 s t
8,8
h=6 h=0

12,11 17,14 e=17


c d
6,6
h=7 h=1
e=0 e=0

Preflow Push Algorithm 13


Example h=3 h=4
e=0 e=4
15,15
a b
Relabel b with h=4 10,10 3,3

Push -4 along (a,b) 5,5


e(a) = 4 s t
8,8
h=6 h=0

12,11 17,14 e=17


c d
6,6
h=7 h=1
e=0 e=0

Preflow Push Algorithm 14


Example h=5 h=4
e=4 e=0
15,11
a b
Relabel a with h=5 10,10 3,3

Push 4 along (a,b) 5,5


e(b) = 4 s t
8,8
h=6 h=0

12,11 17,14 e=17


c d
6,6
h=7 h=1
e=0 e=0

Preflow Push Algorithm 15


Example h=5 h=6
e=0 e=4
15,15
a b
Relabel b with h=6 10,10 3,3

Push -4 along (a,b) 5,5


e(a) = 4 s t
8,8
h=6 h=0

12,11 17,14 e=17


c d
6,6
h=7 h=1
e=0 e=0

Preflow Push Algorithm 16


Example h=7 h=6
e=4 e=0
15,11
a b
Relabel a with h=7 10,10 3,3

Push -4 along (s,a) 5,5


e(a) = 0 s t
8,8
h=6 h=0

12,11 17,14 e=17


c d
6,6
h=7 h=1
e=0 e=0

Preflow Push Algorithm 17


Example h=7 h=6
e=0 e=0
15,11
a b
No active nodes 10,6 3,3

left 5,5
s t
The algorithm 8,8
h=0
h=6
terminates 17,14 e=17
12,11
c d
6,6
h=7 h=1
e=0 e=0

Min-cut

Preflow Push Algorithm 18


Pseudo code
1. Worklist wl = initializePreflowPush();
2. while (!wl.isEmpty()) {
3. Node n = wl.remove();
4. n.relabel();
5. for (Node w in n.neighbors()) {
6. if (n can push flow to w) {
7. pushflow(n, w);
8. wl.add(w);
9. }
10. }
11. if (n has excess flow) {
12. wl.add(n);
13. }
14. }

Preflow Push Algorithm 19


Amorphous Data Parallelism in Preflow Push

Topology: graph
Operator: local computation (data driven)
Active nodes: nodes with excess flow
Neighborhoods: active nodes and their
neighbors
Ordering: unordered
Parallelism: Shoots in the beginning and then
drops down
Dependent on number of active nodes

Preflow Push Algorithm 20


Parallelism profile for Preflow Push

Input Graph: 512x512 Grid

Preflow Push Algorithm 21


Preflow Push: Global Relabeling
The height of the nodes directs the flow towards the sink:
It affects the flow of fluid globally
But is updated locally
Which causes the fluid to flow in arbitrary directions
Increases the total number of push/relabel operations
Global Relabeling:
After every N push/relabel operations we compute the height of
every node from the sink
The height is computed by a breadth-first scan on the Residual
Graph
starting at the sink
The height is incremented at each next level of BFS
It reduces the number of push/relabel operations significantly
N is determined heuristically

Preflow Push Algorithm 22


Preflow Push: Global Relabeling
h=2 h=1
e=0 4 e=0
a b
4 11 3
6
5
s t
8 14
h=6 h=0
11
e=17
1 3
c d
6
h=2 h=1
e=0 e=0

Preflow Push Algorithm 23


Conclusion
Preflow Push is an algorithm to find the
max-flow in a graph
It exhibits amorphous data parallelism
Parallelism is dependent on the structure of
the graph

Preflow Push Algorithm 24

Вам также может понравиться