Preflow Push Algorithm M Amber Hassaan Preflow Push
Preflow Push Algorithm M. Amber Hassaan Preflow Push Algorithm
Max Flow Problem n n n 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 n First value is flow capacity n 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 a ¨ Malhotra, Kumar and Maheshwari 1978 ¨ Goldberg and Tarjan 1986 (Preflow Push) 5, 2 ¨ Boykov and Kolmogorov 2006 4, 4 6, 2 s t 8, 7 Preflow Push Algorithm Min-cut 5, 5 b 2
Max Flow Problem n n 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 a 5, 2 4, 4 6, 2 s t 8, 7 Preflow Push Algorithm 5, 5 b 3
Max Flow Problem n 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 5, 2 Residual Graph a 2 4 4, 4 3 6, 2 s t 4 s 2 1 8, 7 5, 5 b 7 Preflow Push Algorithm t 5 b 4
Preflow Push Algorithm for Maxflow problem n Relaxation algorithm: Performs local updates repeatedly until global constraint is satisfied ¨ Similar to Stencil computations ¨ n n Fluid flows from a higher point to a lower point In the beginning ¨ ¨ n Source sends maximum flow on its outgoing edges ¨ n “Source” is the highest point “Sink” and all other nodes are at the lowest point 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 Preflow Push Algorithm 5
Preflow Push Algorithm for Maxflow problem n 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 n A node is said to be “active” if it has excess flow in it Preflow Push Algorithm 6
Preflow Push Algorithm for Maxflow problem n 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) n Then we “push” the excess flow to the neighbors ¨ That are lower than the active node and can admit flow ¨ Thus make them active n Algorithm terminates when there are no “active” nodes left Preflow Push Algorithm 7
Example n a A simple graph: ¨ n ¨ Height ‘h’ Excess flow ‘e’ n s has h=6 i. e. number of nodes ¨ Push 10 along (s, a) 3, 0 s First value is edge capacity Second value is flow Initialize: ¨ e(a) = 10 t 8, 0 h=6 17, 0 12, 0 c ¨ n b 5, 0 Edges have pairs: n 15, 0 h=0 e=0 10, 0 Nodes have two attributes: n n h=0 e=0 6, 0 h=0 e=0 d h=0 e=0 Push 12 along (s, c) n e(c) = 12 Preflow Push Algorithm 8
Example n n 3, 0 s 5 along (c, a) Relabel c with h=7 t 8, 0 h=6 17, 0 12, 12 c e(a) = 5 ¨ Push b 5, 0 Relabel c with h=2 n 15, 0 h=0 e=10 10, 10 6 along (c, d) e(d) = 6 ¨ Push n a Relabel c with h=1 ¨ Push n h=0 e=10 h=1 e=12 6, 0 h=0 e=0 d h=0 e=0 -1 along (s, c) Preflow Push Algorithm 9
Example n h=1 e=15 a Relabel a with h=1 ¨ Push n b 10, 10 3, 0 15 along (a, b) e(b) = 15 15, 0 h=0 e=0 5, 5 s t 8, 0 h=6 17, 0 12, 11 c h=7 e=0 Preflow Push Algorithm 6, 6 h=0 e=0 d h=0 e=5 10
Example n a Relabel b with h=1 ¨ Push n n 3, 0 s 17, 0 12, 11 -4 along (a, b) t 8, 0 h=6 8 along (b, d) Relabel b with h=2 n b 5, 5 e(d) = 14 ¨ Push 15, 15 h=1 e=15 10, 10 3 along (b, t) e(t) = 3 ¨ Push n h=1 e=0 c h=7 e=0 6, 6 h=0 e=3 d h=0 e=6 e(a) = 4 Preflow Push Algorithm 11
Example n h=1 e=4 a Relabel d with h=1 ¨ Push n b 10, 10 3, 3 14 along (d, t) e(t) = 17 15, 11 h=2 e=0 5, 5 s t 8, 8 h=6 17, 0 12, 11 c h=7 e=0 Preflow Push Algorithm 6, 6 h=0 e=3 d h=1 e=14 12
Example n h=3 e=4 a Relabel a with h=3 ¨ Push n b 10, 10 3, 3 4 along (a, b) e(b) = 4 15, 11 h=2 e=0 5, 5 s 8, 8 h=6 12, 11 c h=7 e=0 Preflow Push Algorithm 6, 6 t h=0 17, 14 e=17 d h=1 e=0 13
Example n h=3 e=0 a Relabel b with h=4 ¨ Push n b 10, 10 3, 3 -4 along (a, b) e(a) = 4 15, 15 h=4 e=4 5, 5 s 8, 8 h=6 12, 11 c h=7 e=0 Preflow Push Algorithm 6, 6 t h=0 17, 14 e=17 d h=1 e=0 14
Example n h=5 e=4 a Relabel a with h=5 ¨ Push n b 10, 10 3, 3 4 along (a, b) e(b) = 4 15, 11 h=4 e=0 5, 5 s 8, 8 h=6 12, 11 c h=7 e=0 Preflow Push Algorithm 6, 6 t h=0 17, 14 e=17 d h=1 e=0 15
Example n h=5 e=0 a Relabel b with h=6 ¨ Push n b 10, 10 3, 3 -4 along (a, b) e(a) = 4 15, 15 h=6 e=4 5, 5 s 8, 8 h=6 12, 11 c h=7 e=0 Preflow Push Algorithm 6, 6 t h=0 17, 14 e=17 d h=1 e=0 16
Example n h=7 e=4 a Relabel a with h=7 ¨ Push n b 10, 10 3, 3 -4 along (s, a) e(a) = 0 15, 11 h=6 e=0 5, 5 s 8, 8 h=6 12, 11 c h=7 e=0 Preflow Push Algorithm 6, 6 t h=0 17, 14 e=17 d h=1 e=0 17
Example n n No active nodes left The algorithm terminates h=7 e=0 15, 11 a h=6 e=0 b 10, 6 3, 3 5, 5 s 8, 8 h=6 12, 11 c h=7 e=0 6, 6 t h=0 17, 14 e=17 d h=1 e=0 Min-cut Preflow Push Algorithm 18
Pseudo code 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. Worklist wl = initialize. Preflow. Push(); while (!wl. is. Empty()) { Node n = wl. remove(); n. relabel(); for (Node w in n. neighbors()) { if (n can push flow to w) { pushflow(n, w); wl. add(w); } } if (n has excess flow) { wl. add(n); } } Preflow Push Algorithm 19
Amorphous Data Parallelism in Preflow Push n n n 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: 512 x 512 Grid Preflow Push Algorithm 21
Preflow Push: Global Relabeling n 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 ¨ n 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 ¨ n n 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 e=0 h=1 e=0 4 a 4 b 11 6 3 5 s t 8 h=6 14 11 1 c h=2 e=0 6 d h=0 e=17 3 h=1 e=0 Preflow Push Algorithm 23
Conclusion Preflow Push is an algorithm to find the max-flow in a graph n It exhibits amorphous data parallelism n ¨ Parallelism is dependent on the structure of the graph Preflow Push Algorithm 24
- Slides: 24