Negative-Weight edges:

Slides:



Advertisements
Similar presentations
Bellman-Ford algorithm
Advertisements

Single Source Shortest Paths
* Bellman-Ford: single-source shortest distance * O(VE) for graphs with negative edges * Detects negative weight cycles * Floyd-Warshall: All pairs shortest.
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
CS138A Single Source Shortest Paths Peter Schröder.
Shortest-paths. p2. Shortest-paths problems : G=(V,E) : weighted, directed graph w : E  R : weight function P=
 2004 SDU Lecture9- Single-Source Shortest Paths 1.Related Notions and Variants of Shortest Paths Problems 2.Properties of Shortest Paths and Relaxation.
chapter Single-Source Shortest Paths Problem Definition Shortest paths and Relaxation Dijkstra’s algorithm (can be viewed as a greedy algorithm)
CS420 lecture twelve Shortest Paths wim bohm cs csu.
Lecture 20: Shortest Paths Shang-Hua Teng. Weighted Directed Graphs Weight on edges for distance
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Shortest Path Problems
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
1.1 Data Structure and Algorithm Lecture 11 Application of BFS  Shortest Path Topics Reference: Introduction to Algorithm by Cormen Chapter 25: Single-Source.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 15 Shortest paths algorithms Properties of shortest paths Bellman-Ford algorithm.
Shortest Paths Definitions Single Source Algorithms
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
1 Graph Algorithms Single source shortest paths problem Dana Shapira.
1 Shortest Path Algorithms. 2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Graph Algorithms Shortest path problems. Graph Algorithms Shortest path problems.
1 Shortest Path Problems How can we find the shortest route between two points on a road map? Model the problem as a graph problem: –Road map is a weighted.
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
The single-source shortest path problem (SSSP) input: a graph G = (V, E) with edge weights, and a specific source node s. goal: find a minimum weight (shortest)
Single Source Shortest Paths Chapter 24 CSc 4520/6520 Fall 2013 Slides adapted from George Bebis, University of Reno, Nevada.
CSC317 Shortest path algorithms
Single-Source Shortest Path
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Algorithms and Data Structures Lecture XIII
ADVANCED ALGORITHMS GRAPH ALGORITHMS (UNIT-2).
Minimum Spanning Trees
Challenging Problem 2: Challenging problem 2 will be given on the website (week 4) at 9:30 am on Saturday (Oct 1, 2005). 2. The due time is Sunday (Oct.
SINGLE-SOURCE SHORTEST PATHS
Lecture 7 Shortest Path Shortest-path problems
CSCE 411 Design and Analysis of Algorithms
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Announcement 2: A 2 hour midterm (open book) will be given on March (Tuesday) during the lecture time. 2018/12/4.
Page 620 Single-Source Shortest Paths
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Basic Graph Algorithms
2018/12/27 chapter25.
Advanced Algorithms Analysis and Design
2-optimal Euler path problem Euler circuit in a directed graph:
Lecture 11 Topics Application of BFS Shortest Path
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Analysis of Algorithms
CSC 413/513: Intro to Algorithms
Lecture 13 Algorithm Analysis
CSCE 411 Design and Analysis of Algorithms
Lecture 13 Algorithm Analysis
Fundamental Data Structures and Algorithms
2019/2/25 chapter25.
Shortest Path Problems
Algorithms (2IL15) – Lecture 7
The Bellman-Ford Shortest Path Algorithm Neil Tang 03/27/2008
Evaluation of the Course (Modified)
Chapter 24: Single-Source Shortest Paths
Advanced Algorithms Analysis and Design
Chapter 24: Single-Source Shortest Paths
Negative-Weight edges:
Bellman Ford.
Negative-Weight edges:
CS 3013: DS & Algorithms Shortest Paths.
Chapter 24: Single-Source Shortest-Path
Analysis of Algorithms
Advanced Algorithms Analysis and Design
Presentation transcript:

Negative-Weight edges: Edge weight may be negative. negative-weight cycles– the total weight in the cycle (circuit) is negative. If no negative-weight cycles reachable from the source s, then for all v V, the shortest-path weight remains well defined,even if it has a negative value. If there is a negative-weight cycle on some path from s to v, we define = - . 2019/5/18 chapter25

a b -4 h i 3 -1 2 4 3 c d 6 8 5 -8 3 5 11 g s -3 e 3 f 2 7 j -6 Figure1 Negative edge weights in a directed graph.Shown within each vertex is its shortest-path weight from source s.Because vertices e and f form a negative-weight cycle reachable from s,they have shortest-path weights of - . Because vertex g is reachable from a vertex whose shortest path is - ,it,too,has a shortest-path weight of - .Vertices such as h, i ,and j are not reachable from s,and so their shortest-path weights are , even though they lie on a negative-weight cycle. 2019/5/18 chapter25

Relaxation: The process of relaxing an edge (u,v) consists of testing whether we can improve the shortest path to v found so far by going through u and,if so,updating d[v] and [v]. RELAX(u,v,w) if d[v]>d[u]+w(u,v) then d[v]  d[u]+w(u,v) (based on Lemma 25.3) [v]  u 2019/5/18 chapter25

u v u v 2 2 5 9 5 6 RELAX(u,v) RELAX(u,v) u v u v 2 2 5 7 5 6 (a) (b) Figure2 Relaxation of an edge (u,v).The shortest-path estimate of each vertex is shown within the vertex. (a)Because d[v]>d[u]+w(u,v) prior to relaxation, the value of d[v] decreases. (b)Here, d[v] d[u]+w(u,v) before the relaxation step,so d[v] is unchanged by relaxation. 2019/5/18 chapter25

Bellman-Ford algorithm: The Bellman-Ford algorithm solves the single-source shortest-paths problem in the more general case in which edge weights can be negative. It report FALSE if a negative-weight circuit exists. 2019/5/18 chapter25

Continue: BELLMAN-FORD(G,w,s): INITIALIZE-SINGLE-SOURCE(G,s) for i  1 to |V[G]| -1 do for each edge (u,v)  E[G] (The order here is arbitrary) do RELAX(u,v,w) for each edge (u,v) E[G] do if d[v]>d[u]+w(u,v) then return FALSE return TRUE Time complexity: O(|V||E|). 2019/5/18 chapter25

6 7 9 2 5 -2 8 -3 -4 z u v x y (a) 2019/5/18 chapter25

u 5 v 6 8 -2 6 -3 8 7 z -4 2 7 7 8 9 x y (b) 2019/5/18 chapter25

u 5 v 6 4 -2 6 -3 8 7 z -4 2 7 7 2 9 x y (c) 2019/5/18 chapter25

u 5 v 2 4 -2 6 -3 8 7 z -4 2 7 7 2 9 x y (d) 2019/5/18 chapter25

u 5 v 2 4 -2 6 -3 8 7 z -4 2 7 7 -2 9 x y (e) 2019/5/18 chapter25

Proof: We prove it by induction on i. Theorem: (hard) after the i-th iteration, the cost of a shortest path from s to any node v containing i edges is obtained. Proof: We prove it by induction on i. The theorem is true for i=1. The shortest path from s to v containing at most one edge is the the edge (s, v) (if exists). Assume that the theorem is true for i=k. Then we are going to show that the theorem is true for i=k+1. Let P: s-> v1-> v2 …->vm-> v be the shortest path from s to v containing at most k+1 edges. Then P1: s-> v1-> v2 …->vm must be the shortest path from s to vm containing at most k edges. By assumption, P1 has been obtained after (k)-th iteration. In the (k+1)-th iteration, we tried to RELAX(vm, v, w) on node vm. Thus, path P is obtained after the (k+1)-th iteration. 2019/5/18 chapter25

Corollary: If negative-weight circuit exists in the given graph, in the n-th iteration, the cost of a shortest path from s to some node v will be further reduced. Demonstrated by the following example. Note: For each iteration, the order of edges used does not effect the Theorem. However, the intermediate results may vary. The final results will be the same. 2019/5/18 chapter25

An example with negative-weight cycle 5  1 6 -2 8 7 7 9 2 2 5 -8 An example with negative-weight cycle 2019/5/18 chapter25

7 6  8 5 -2 1 2 9 -8 2019/5/18 chapter25

7 6 16  11 9 8 5 -2 1 2 -8 2019/5/18 chapter25

7 6 16 12 11 1 9 8 5 -2 2 -8 2019/5/18 chapter25

6 16 12 11 1 9 7 8 5 -2 2 -8 2019/5/18 chapter25

5 6 11 1 6 -2 8 7 12 7 9 2 6 15 2 5 -8 8 1 2019/5/18 chapter25

6 15 12 11 8 7 5 -2 1 2 9 -8 2019/5/18 chapter25

5 6 11 1 6 -2 8 7 12 7 9 2 5 15 2 5 -8 8 x 2019/5/18 chapter25

Exercise: use Bellman-Ford algorithm for the graph 2 5 -3  1 6 -2 8 7 7 9 2 2 5 -6 Exercise: use Bellman-Ford algorithm for the graph 2019/5/18 chapter25