ADVANCED ALGORITHMS GRAPH ALGORITHMS (UNIT-2).

Slides:



Advertisements
Similar presentations
Maximum flow Main goals of the lecture:
Advertisements

1 Review of some graph algorithms Graph G(V,E) (Chapter 22) –Directed, undirected –Representation Adjacency-list, adjacency-matrix Breadth-first search.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
MAXIMUM FLOW Max-Flow Min-Cut Theorem (Ford Fukerson’s Algorithm)
Advanced Algorithm Design and Analysis (Lecture 8) SW5 fall 2004 Simonas Šaltenis E1-215b
CS138A Network Flows Peter Schröder. CS138A Flow Networks Definitions a flow network G=(V,E) is a directed graph in which each edge (u,v)
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
1 Maximum flow problems. 2 - Introduction of: network, max-flow problem capacity, flow - Ford-Fulkerson method pseudo code, residual networks, augmenting.
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
1 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method Maximum bipartite matching.
Shortest Paths Definitions Single Source Algorithms
All-Pairs Shortest Paths
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Maximum Flow Maximum Flow Problem The Ford-Fulkerson method
Theory of Computing Lecture 13 MAS 714 Hartmut Klauck.
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.
Max Flow – Min Cut Problem. Directed Graph Applications Shortest Path Problem (Shortest path from one point to another) Max Flow problems (Maximum material.
Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Flow Networks Ching-Chen Huang Hsi-Yue Hsiao. CONTENTS Network flows on directed acyclic graphs Ford-fulkerson Algorithms -Residual networks.
CSEP 521 Applied Algorithms Richard Anderson Lecture 8 Network Flow.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
A directed graph G consists of a set V of vertices and a set E of arcs where each arc in E is associated with an ordered pair of vertices from V. V={0,
Instructor Neelima Gupta Edited by Divya Gaur(39, MCS '09) Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09)
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Maximum Flow Chapter 26.
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Maximum Flow Chapter 26.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Graph Algorithms Minimum Spanning Tree (Chap 23)
CS4234 Optimiz(s)ation Algorithms
Lectures on Network Flows
Algorithms and Networks Hans Bodlaender
Network flow problem [Adapted from M.Chandy].
Richard Anderson Lecture 23 Network Flow
Lecture 22 Network Flow, Part 2
Algorithms and Data Structures Lecture XIII
Max Flow – Min Cut Problem
Instructor: Shengyu Zhang
Edmonds-Karp Algorithm
Network Flows and Matching (Supplementary)
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
CSE Algorithms Max Flow Problems 11/21/02 CSE Max Flow.
Lecture 10 Network flow Max-flow and Min-cut Ford-Fulkerson method
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Flow Networks Topics Flow Networks Residual networks
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Richard Anderson Lecture 23 Network Flow
Vertex Covers, Matchings, and Independent Sets
Richard Anderson Lecture 21 Network Flow
Network Flows and Matching (Supplementary)
Flow Networks General Characteristics Applications
Advanced Algorithms Analysis and Design
Flow Networks and Bipartite Matching
Lecture 13 Algorithm Analysis
Honors Track: Competitive Programming & Problem Solving Avoiding negative edges Steven Ge.
Algorithms (2IL15) – Lecture 7
EE5900 Advanced Embedded System For Smart Infrastructure
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Text Book: Introduction to algorithms By C L R S
MAXIMUM flow by Eric Wengert.
Richard Anderson Lecture 22 Network Flow
Lecture 21 Network Flow, Part 1
Lecture 22 Network Flow, Part 2
Advanced Graph Homer Lee 2013/10/31.
Presentation transcript:

ADVANCED ALGORITHMS GRAPH ALGORITHMS (UNIT-2)

The Bellman-Ford Algorithm (BFA) The BFA solves the single-source shortest-paths problem in general case in which edge weights may be negative. Given a weighted directed graph G = (V,E). with source s, and weight function w, the BFA returns a boolean value indicating whether or not there is a negative-weight cycle that is reachable from the source.

Bellman-Ford(G,w,s) Initialize-Single-Source(G,s) for i = 1 to |V| -1 for each edge (u,v) ∊ E RELAX(u,v,w) if v.d > u.d + w(u,v) return FALSE 8 return TRUE RELAX (u,v,w) if v.d > u.d + w(u,v) 2 v.d = u.d + w(u,v) 3 v.∏ = u

Single –Source Shortest Paths in DAG: DAG stands for ‘Directed Acyclic Graph’. There is no cycle in a directed acyclic graph. Topological Sort : Topological Sort of a DAG, G = (V,E) is a linear ordering of all its nodes such that if G has an edge (u,v), then u appears before v in the ordering. The algorithm starts by topologically sorting the DAG to impose a linear ordering on the vertices. If a DAG contains a path from u to v, then u preceds v in the topological sort.

DAG-SHORTEST-PATHS(G,w,s) Topologically sort the vertices of G INITIALIZE-SINGLE-SOURCE(G,s) for each vertex u, taken in topologically sorted order for each vertex v ∊ G.Adj[u] 5. RELAX (u, v, w) Ex-1 : Topologically sort the following DAG : t r x y s z

Ex-2 : Draw the Graph and Solve it for the following Weight Table : r  s  t  x  y  z Ex-2 : Draw the Graph and Solve it for the following Weight Table : ------------------------------------------------ r  s s  t t  x x  y y  z 5 2 7 -1 -2 s  x x  z r  t t  y t  z 6 1 3 4 2

3. Johnson’s Algorithm for Sparse Graphs: This algorithm finds shortest paths between all pairs. This algorithm returns a matrix of shortest-path weights for all pairs of vertices or reports that the that the input graph contains a negative-weight cycle. This algorithm uses the technique of ’reweighting’. If all edge weights w in a graph G = (V,E) are non-negative, we can find shortest paths between all pairs of vertices by running Dijkstra’s algorithm once from each matrix. b) If G has negative –weight edges, then compute a new set of non-negative edge weights (reweighting) that allows us to use the same method.

JOHNSON(G,w) Compute G’, where G’.V = G.V U {s} G’.E = G.E U { (s,v) : v ∊ G.V w(s,v) = 0 for all v ∊ G.V if BELLMAN-FORD(G’, w, s) = = FALSE print “the input graph contains a negative- weight cycle”. else for each vertex v ∊ G’.V set h(v) to the value of δ(s,v) computed by the BF algorithm. for each edge (u,v) ∊ G’. E 7 w’(u,v) = w(u,v) + h(u) – h(v)

Let D = (duv) be a new matrix. for each vertex u ∊ G.V 10. run DIJKSTRA(G,w’,u) to compute δ’(s,v) for all v ∊ G.V for each vertex v ∊ G.V duv = δ’(u,v) + h(v) – h(u) return D Ex-3: Consider the following Graph. G(V) = [ a, b, c, d, e] G(E) = [ (a  b : 3), (a  c : 8), (a  e : -4), (b  d : 1), (b  e : 7), (c  b : 4), (d  c : -5), (d  a : 2), (e  d : 6) ]

Consider new vertex s. Draw edges from s to a, b, c, d, e with weights zero. Draw the Graph G’ (V’,E’), where V’ = V U (s). and E’ = E U [(s,a), (s,b), (s,c), (s,d),(s,e)] for G, we have |V| = 5 |E| = 9 for G’, we have |V| = 6 |E| = 14 And h(a) = δ(s,a) = 0 h(b) = δ(s,b) = -1 h(c) = δ(s,c) = -5 h(d) = δ(s,d) = 0 h(e) = δ(s,e) = -4

Bellman-Ford Algorithm : TRUE REWEIGHTING : w’(a,b) = w(a,b) + h(a) – h(b) = 3 + 0 – (-1) = 4 w’(a,c) = w(a,c) + h(a) – h(c) = 13 w’(a,e) = w(a,e) + h(a) – h(e) = 0 w’(b,d) = w(b,d) + h(b) – h(d) = 0 w’(b,e) = w(b,e) + h(b) – h(e) = 10 Similarily w’(c,b) = 0 w’(d,c) = 0 w’(d,a) = 2 w’(e,d) = 2 w’(s,a) = 0 w’(s,b) = 1 w’(s,c) = 5 w’(s,d) = 0 w’(s,e) = 4

Draw the D-Matrix (5 x 5 ) : δ(u,v) = duv The Output : Draw the D-Matrix (5 x 5 ) : δ(u,v) = duv δ(u,v) a b c d e --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- a 0 1 - 3 2 - 4 b 3 0 - 4 1 - 1 c 7 4 0 5 3 d 2 - 1 - 5 0 - 2 e 8 5 1 6 0

A flow network G = (V,E) is a directed graph in 4. FLOW NETWORKS : A flow network G = (V,E) is a directed graph in which each edge (u,v) ∊ E has a non-negative capacity c(u,v)  0. There are two distinguished vertices : source s sink t A flow in G has two following properties : a) Capacity Constraint : 0 ≤ f(u,v) ≤ c(u,v) b) Flow Conservation : For all u ∊ V – {s,t}  f(u,v) =  f(v,u) v ∊ V v ∊ V

Ex-4 : Consider the following Flow Network v1 12 v3 16 20 s 4 9 7 t 13 4 v2 14 v4 The following is FNW for |f| = 19 v1 12/12 v3 11/16 15/20 s 1/4 4/9 7/7 t 8/13 4/4 v2 11/14 v4

4. The Ford-Fulkerson Method : The following is FNW for |f| = 20 v1 12/12 v3 8/16 16/20 S 4/4 3/9 7/7 T 12/13 4/4 v2 11/14 v4 4. The Ford-Fulkerson Method : This FF Method is used for solving the maximum- flow problem. This method iteratively increases the value of the flow.

Residual Capacity : Residual Network : Let f be a flow in G. Consider a pair of vertices u,v ∊ V The Residual Capacity Cf(u,v) is : = c(u,v) – f(u,v) if (u,v) ∊ E Cf(u,v) = f(v,u) if (v,u) ∊ E = 0 otherwise Residual Network : Given a flow network G = (V,E) and a flow f, the residual network of G induced by f is Gf = (V,Ef), where Ef = { (u,v) ∊ V X V : Cf(u,v) > 0 }

The Ford-Fulkerson Algorithm : FORD-FULKERSON(G,s,t) 1 for each edge (u,v) ∊ E 2 (u,v).f = 0 3 while there exists a path p from s to t in the residual network Gf Cf(p) = min {Cf(u,v) : (u,v) is in p} for each edge (u,v) in p 6 if (u,v) ∊ E 7 (u,v) .f = (u.v).f + Cf(p) 8 else (v,u).f = (v,u).f - Cf(p)

Example-5 : Consider the following FNW :

The above Residual network has no augmenting paths, and the flow f shown above is therefore a maximum flow. The value of the maximum flow found is  23

Maximum Bipartite Matching : Let there is an Undirected Graph : G = (V,E) A matching is a subset of edges M  E such that for all vertices v ∊ V, at most one edge of M is incident on v. A vertex v ∊ V is matched by the matching M, if some edge in M is incident on v, otherwise, v is unmatched. A maximum matching is a matching of maximum cardinality, i.e., a matching M such that for any matching M’, it is |M|  |M’|.

Let the vertex set V is partitioned in to L and R : V = L U R where L and R are disjoint and all edges in E are in either L or R. Ex-6 : Let there are L machines. Let there are R tasks. Here the edge (u,v) in E is to mean that a particular machine u ∊ L is capable of performing a particular task v ∊ R. A maximum matching provides work for as many machines as possible.

Finding a Maximum Bipartite Matching : Let there is a Bipartite Graph G = (V, E) . The Ford-Fulkerson method can be used here. Construct a FNW, G’ = (V’,E’) , where V’ = V U {s,t} E’ = E U all edges from s to L U all edges from R to t. Here, E’ = { (s,u) : u ∊ L } U {(u,v) : (u,v) ∊ E } U {(v,t) ∊ R }

6. Max Flow - Min Cut Theorem : Ex-7 : Consider the following Graph :

A cut is a node partition (S,T) such that s is in S, and t is in T. capacity(S,T) = sum of weights of edges leaving S.

The Max-Flow of the above Graph is : 28 Consider the above Original Graph. Find its Max-Flow : The Max-Flow of the above Graph is : 28 Max-Flow Min-Cut Theorem : The value of the max flow is equal to the capacity of the min cut. i.e., Max-Flow = Min-Cut * * * * *