preflow push algorithm

24
Preflow Push Algorithm M. Amber Hassaan

Upload: tavi

Post on 08-Jan-2016

71 views

Category:

Documents


5 download

DESCRIPTION

Preflow Push Algorithm. M. Amber Hassaan. a. 5, 2. 4, 4. s. 6, 2. t. 8, 7. 5, 5. b. 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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Preflow Push Algorithm

Preflow Push Algorithm

M. Amber Hassaan

Page 2: Preflow Push Algorithm

Preflow Push Algorithm 2

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 Malhotra, Kumar and Maheshwari 1978 Goldberg and Tarjan 1986 (Preflow Push) Boykov and Kolmogorov 2006

s

a

b

t

5, 2

8, 7

4, 4

6, 2

5, 5

Min-cut

Page 3: Preflow Push Algorithm

Preflow Push Algorithm 3

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: f(u,v) ≤ c(u,v) i.e. capacity of edge (u,v) f(u,v) = - f(v,u) Flow coming into node v = Flow leaving v

s

a

b

t

5, 2

8, 7

4, 4

6, 2

5, 5

Page 4: Preflow Push Algorithm

Preflow Push Algorithm 4

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’

s

a

b

t

5, 2

8, 7

4, 4

6, 2

5, 5

s

a

b

t

2

3

1

7

42

4

5

Original Graph Residual Graph

Page 5: Preflow Push Algorithm

Preflow Push Algorithm 5

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 Source’s neighbors is then increased so that fluid can flow out Increasing height of a node is called “Relabel” operation

Page 6: Preflow Push Algorithm

Preflow Push Algorithm 6

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

conditionSource can have arbitrary amount of excess

flow A node is said to be “active” if it has

excess flow in it

Page 7: Preflow Push Algorithm

Preflow Push Algorithm 7

Preflow Push Algorithm for Maxflow problem

We increase the height of the “active” node with a “Relabel” operation If h 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

Page 8: Preflow Push Algorithm

Preflow Push Algorithm 8

Example

A simple graph: Nodes have two attributes:

Height ‘h’ Excess flow ‘e’

Edges have pairs: First value is edge capacity Second value is flow

Initialize: s has h=6 i.e. number of

nodes Push 10 along (s,a)

e(a) = 10 Push 12 along (s,c)

e(c) = 12

s

c

a b

t

d

h=6

h=0e=0

h=0e=0

h=0e=0

h=0e=0

h=0e=0

10,0

12,0

5,0

8,0

15,0

6,0

17,0

3,0

Page 9: Preflow Push Algorithm

Preflow Push Algorithm 9

Example

Relabel c with h=1 Push 6 along (c,d)

e(d) = 6

Relabel c with h=2 Push 5 along (c,a)

e(a) = 5

Relabel c with h=7 Push -1 along (s,c)

s

c

a b

t

d

h=6

h=0e=10

h=0e=10

h=0e=0

h=1e=12

h=0e=0

10,10

12,12

5,0

8,0

15,0

6,0

17,0

3,0

Page 10: Preflow Push Algorithm

Preflow Push Algorithm 10

Example

Relabel a with h=1 Push 15 along

(a,b) e(b) = 15

s

c

a b

t

d

h=6

h=1e=15

h=0e=0

h=0e=0

h=7e=0

h=0e=5

10,10

12,11

5,5

8,0

15,0

6,6

17,0

3,0

Page 11: Preflow Push Algorithm

Preflow Push Algorithm 11

Example

Relabel b with h=1 Push 3 along (b,t)

e(t) = 3

Push 8 along (b,d) e(d) = 14

Relabel b with h=2 Push -4 along (a,b)

e(a) = 4

s

c

a b

t

d

h=6

h=1e=0

h=1e=15

h=0e=3

h=7e=0

h=0e=6

10,10

12,11

5,5

8,0

15,15

6,6

17,0

3,0

Page 12: Preflow Push Algorithm

Preflow Push Algorithm 12

Example

Relabel d with h=1 Push 14 along (d,t)

e(t) = 17 s

c

a b

t

d

h=6

h=1e=4

h=2e=0

h=0e=3

h=7e=0

h=1e=14

10,10

12,11

5,5

8,8

15,11

6,6

17,0

3,3

Page 13: Preflow Push Algorithm

Preflow Push Algorithm 13

Example

Relabel a with h=3 Push 4 along (a,b)

e(b) = 4 s

c

a b

t

d

h=6

h=3e=4

h=2e=0

h=0e=17

h=7e=0

h=1e=0

10,10

12,11

5,5

8,8

15,11

6,6

17,14

3,3

Page 14: Preflow Push Algorithm

Preflow Push Algorithm 14

Example

Relabel b with h=4 Push -4 along (a,b)

e(a) = 4 s

c

a b

t

d

h=6

h=3e=0

h=4e=4

h=0e=17

h=7e=0

h=1e=0

10,10

12,11

5,5

8,8

15,15

6,6

17,14

3,3

Page 15: Preflow Push Algorithm

Preflow Push Algorithm 15

Example

Relabel a with h=5 Push 4 along (a,b)

e(b) = 4 s

c

a b

t

d

h=6

h=5e=4

h=4e=0

h=0e=17

h=7e=0

h=1e=0

10,10

12,11

5,5

8,8

15,11

6,6

17,14

3,3

Page 16: Preflow Push Algorithm

Preflow Push Algorithm 16

Example

Relabel b with h=6 Push -4 along (a,b)

e(a) = 4 s

c

a b

t

d

h=6

h=5e=0

h=6e=4

h=0e=17

h=7e=0

h=1e=0

10,10

12,11

5,5

8,8

15,15

6,6

17,14

3,3

Page 17: Preflow Push Algorithm

Preflow Push Algorithm 17

Example

Relabel a with h=7 Push -4 along (s,a)

e(a) = 0 s

c

a b

t

d

h=6

h=7e=4

h=6e=0

h=0e=17

h=7e=0

h=1e=0

10,10

12,11

5,5

8,8

15,11

6,6

17,14

3,3

Page 18: Preflow Push Algorithm

Preflow Push Algorithm 18

Example

No active nodes left

The algorithm terminates

s

c

a b

t

d

h=6

h=7e=0

h=6e=0

h=0e=17

h=7e=0

h=1e=0

10,6

12,11

5,5

8,8

15,11

6,6

17,14

3,3

Min-cut

Page 19: Preflow Push Algorithm

Preflow Push Algorithm 19

Pseudo code1. 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. }

Page 20: Preflow Push Algorithm

Preflow Push Algorithm 20

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

Page 21: Preflow Push Algorithm

Preflow Push Algorithm 21

Parallelism profile for Preflow Push

Input Graph: 512x512 Grid

Page 22: Preflow Push Algorithm

Preflow Push Algorithm 22

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

Page 23: Preflow Push Algorithm

Preflow Push Algorithm 23

Preflow Push: Global Relabeling

s

c

a b

t

d

h=6

h=2e=0

h=1e=0

h=0e=17

h=2e=0

h=1e=0

5

8

6

34

1

6

11

4

11

14

3

Page 24: Preflow Push Algorithm

Preflow Push Algorithm 24

Conclusion

Preflow Push is an algorithm to find the max-flow in a graph

It exhibits amorphous data parallelismParallelism is dependent on the structure of

the graph