Shortest Path With Negative Weights s 3 t 2 6 7 4 5 10 18 -16 9 6 15 -8 30 20 44 16 11 6 19 6.

Slides:



Advertisements
Similar presentations
Graph Algorithms - 3 Algorithm Design and Analysis Victor AdamchikCS Spring 2014 Lecture 13Feb 12, 2014Carnegie Mellon University.
Advertisements

Lecture 7. Network Flows We consider a network with directed edges. Every edge has a capacity. If there is an edge from i to j, there is an edge from.
1 Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Single Source Shortest Paths
Lecture 24 Coping with NPC and Unsolvable problems. When a problem is unsolvable, that's generally very bad news: it means there is no general algorithm.
Introduction to Algorithms
Chapter 5 Shortest Paths: Label-Correcting Algorithms
1 Theory I Algorithm Design and Analysis (10 - Shortest paths in graphs) T. Lauer.
Online Scheduling with Known Arrival Times Nicholas G Hall (Ohio State University) Marc E Posner (Ohio State University) Chris N Potts (University of Southampton)
Sequential Timing Optimization. Long path timing constraints Data must not reach destination FF too late s i + d(i,j) + T setup  s j + P s i s j d(i,j)
Max Flow: Shortest Augmenting Path
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 19.
1 Maximum Flow w s v u t z 3/33/3 1/91/9 1/11/1 3/33/3 4/74/7 4/64/6 3/53/5 1/11/1 3/53/5 2/22/2 
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Lectures on Network Flows
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 7 Maximum Flows: Polynomial Algorithms
Chapter 3 The Greedy Method 3.
DYNAMIC PROGRAMMING. 2 Algorithmic Paradigms Greedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer.
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.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
The Theory of NP-Completeness
Shortest Paths Definitions Single Source Algorithms
Job Scheduling Lecture 19: March 19. Job Scheduling: Unrelated Multiple Machines There are n jobs, each job has: a processing time p(i,j) (the time to.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Greed: Shortest Path s 3 t
Approximation Algorithms Motivation and Definitions TSP Vertex Cover Scheduling.
Assignment 4. (Due on Dec 2. 2:30 p.m.) This time, Prof. Yao and I can explain the questions, but we will NOT tell you how to solve the problems. Question.
Advanced Algorithms Piyush Kumar (Lecture 5: Weighted Matching) Welcome to COT5405 Based on Kevin Wayne’s slides.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 22.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Operations Research Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD4207 University of Palestine.
1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.
Advanced Algorithms Piyush Kumar (Lecture 5: Weighted Matching) Welcome to COT5405 Based on Kevin Wayne’s slides.
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 6 Shortest Path Algorithms.
10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 17 Dynamic.
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Approximation Algorithms These lecture slides are adapted from CLRS.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 17.
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.
1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf.
15.082J & 6.855J & ESD.78J September 23, 2010 Dijkstra’s Algorithm for the Shortest Path Problem.
Introduction to Algorithms Jiafen Liu Sept
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)
Introduction to Graphs And Breadth First Search. Graphs: what are they? Representations of pairwise relationships Collections of objects under some specified.
Pipelining and Retiming
Shortest Path Algorithm 2 Prof. Sin-Min Lee Department of Computer Science.
and 6.855J March 6, 2003 Maximum Flows 2. 2 Network Reliability u Communication Network u What is the maximum number of arc disjoint paths from.
CS38 Introduction to Algorithms Lecture 10 May 1, 2014.
10/11/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 21 Network.
Supplementary: Feasible Labels and Linear Programming  Consider the LP formulation of the shortest s-t path problem: (P) Minimize  (i, j)  A c ij x.
15.082J & 6.855J & ESD.78J September 30, 2010 The Label Correcting Algorithm.
Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
TU/e Algorithms (2IL15) – Lecture 12 1 Linear Programming.
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Proof of correctness of Dijkstra’s algorithm: Basically, we need to prove two claims. (1)Let S be the set of vertices for which the shortest path from.
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Lectures on Network Flows
Chapter 5. Optimal Matchings
Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
3.3 Applications of Maximum Flow and Minimum Cut
Analysis of Algorithms
Chapter 6 Dynamic Programming
Dijkstra’s Algorithm for the Shortest Path Problem
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
3.5 Minimum Cuts in Undirected Graphs
Chapter 6 Dynamic Programming
Algorithms (2IL15) – Lecture 7
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Presentation transcript:

Shortest Path With Negative Weights s 3 t

2 Contents Contents. n Directed shortest path with negative weights. n Negative cycle detection. – application: currency exchange arbitrage n Tramp steamer problem. – application: optimal pipelining of VLSI chips

3 Shortest Paths with Negative Weights Negative cost cycle. If some path from s to v contains a negative cost cycle, there does not exist a shortest s-v path; otherwise, there exists one that is simple. sv W c(W) <

4 Shortest Paths with Negative Weights OPT(i, v) = length of shortest s-v path using at most i arcs. n Let P be such a path. n Case 1: P uses at most i-1 arcs. n Case 2: P uses exactly i arcs. – if (u, v) is last arc, then OPT selects best s-u path using at most i-1 arcs, and then uses (u, v) Goal: compute OPT(n-1, t) and find a corresponding s-t path.

5 Shortest Paths with Negative Weights: Algorithm INPUT: G = (V, E), s, t n = |V| ARRAY: OPT[0..n, V] FOREACH v  V OPT[0, v] =  OPT[0,s] = 0 FOR i = 1 to n FOREACH v  V m = OPT[i-1, v] m' =  FOREACH (u, v)  E m' = min (m', OPT[i-1, u] + c[u,v]) OPT[i, v] = min(m, m') RETURN OPT[n-1, t] Dynamic Programming Shortest Path

6 Shortest Paths: Running Time Dynamic programming algorithm requires  (mn) time and space. n Outer loop repeats n times. n Inner loop for vertex v considers indegree(v) arcs. Finding the shortest paths. n Could maintain predecessor variables. n Alternative: compute optimal distances, consider only zero reduced cost arcs.

7 Shortest Paths: Detecting Negative Cycles L1: if OPT(n,v) < OPT(n-1,v) for some node v, then (any) shortest path from s to v using at most n arcs contains a cycle; moreover any such cycle has negative cost. n Proof (by contradiction). n Since OPT(n,v) < OPT(n-1,v), P has n arcs. n Let C be any directed cycle in P. n Deleting C gives us a path from s to v of fewer than n arcs  C has negative cost. sv C c(C) < 0

8 Shortest Paths: Detecting Negative Cycles L1: if OPT(n,v) < OPT(n-1,v) for some node v, then (any) shortest path from s to v using at most n arcs contains a cycle; moreover any such cycle has negative cost. n Proof (by contradiction). n Since OPT(n,v) < OPT(n-1,v), P has n arcs. n Let C be any directed cycle in P. n Deleting C gives us a path from s to v of fewer than n arcs  C has negative cost. Corollary: can detect negative cost cycle in O(mn) time. n Need to trace back through sub-problems s

9 Detecting Negative Cycles: Application Currency conversion. n Given n currencies (financial instruments) and exchange rates between pairs of currencies, is there an arbitrage opportunity? n Fastest algorithm very valuable! F$ £ ¥ DM 1/7 3/10 2/ /50 4/3 8 IBM 1/

10 Shortest Paths: Practical Improvements Practical improvements. n If OPT(i, v) = OPT(i-1, v) for all nodes v, then OPT(i, v) are the shortest path distances.  Consequence: can stop algorithm as soon as this happens. n Maintain only one array OPT(v).  Use O(m+n) space; otherwise  (mn) best case. n No need to check arcs of the form (u, v) unless OPT(u) changed in previous iteration.  Avoid unnecessary work. Overall effect. n Still O(mn) worst case, but O(m) behavior in practice.

11 Shortest Paths: Practical Improvements INPUT: G = (V, E), s, t n = |V| ARRAY: OPT[V], pred[V] FOREACH v  V OPT[v] = , pred[v] =  OPT[s] = 0, Q = QUEUEinit(s) WHILE (Q   ) u = QUEUEget() FOREACH (u, v)  E IF (OPT[u] + c[u,v] < OPT[v]) OPT[v] = OPT[u] + c[u,v] pred[v] = u IF (v  Q) QUEUEput(v) RETURN OPT[n-1] Bellman-Ford FIFO Shortest Path Negative cycle tweak: stop if any node enqueued n times.

12 Shortest Paths: State of the Art All times below are for single source shortest path in directed graphs with no negative cycle. O(mn) time, O(m + n) space. n Shortest path: straightforward. n Negative cycle: Bellman-Ford predecessor variables contain shortest path or negative cycle (not proved here). O(mn 1/2 log C) time if all arc costs are integers between –C and C. n Reduce to weighted bipartite matching (assignment problem). n "Cost-scaling." n Gabow-Tarjan (1989), Orlin-Ahuja (1992). O(mn + n 2 log n) undirected shortest path, no negative cycles. n Reduce to weighted non-bipartite matching. n Beyond the scope of this course.

13 Tramp-Steamer Problem Tramp-steamer (min cost to time ratio) problem. n A tramp steamer travels from port to port carrying cargo. A voyage from port v to port w earn p(v,w) dollars, and requires t(v,w) days. n Captain wants a tour that achieves largest mean daily profit p = 30 t = 7 p = 12 t = 3 p = -3 t = 5 mean daily profit = Westward Ho (1894 – 1946)

14 Tramp-Steamer Problem Tramp-steamer (min cost to time ratio) problem. n Input: digraph G = (V, E), arc costs c, and arc traversal times t > 0. n Goal: find a directed cycle W that minimizes ratio Novel application. n Minimize cycle time (maximize frequency) of logic chip on IBM processor chips by adjusting clocking schedule. Special case. n Find a negative cost cycle.

15 Tramp-Steamer Problem Linearize objective function. n Let  * be value of minimum ratio cycle. n Let  be a constant. n Define e = c e –  t e. Case 1: there exists negative cost cycle W using lengths e. Case 2: every directed cycle has positive cost using lengths e.

16 Tramp-Steamer Problem Linearize objective function. n Let  * be value of minimum ratio cycle. n Let  be a constant. n Define e = c e –  t e. Case 3: every directed cycle has nonnegative cost using lengths e, and there exists a zero cost cycle W*.

17 Tramp-Steamer Problem Linearize objective function. n Let  * be value of minimum ratio cycle. n Let  be a constant. n Define e = c e –  t e. Case 1: there exists negative cost cycle W using lengths e. n  * <  Case 2: every directed cycle has positive cost using lengths e. n  * >  Case 3: every directed cycle has nonnegative cost using lengths e, and there exists a zero cost cycle W*. n  * = 

18 Tramp-Steamer: Sequential Search Procedure Theorem: sequential algorithm terminates. n Case 1   strictly decreases from one iteration to the next. n  is the ratio of some cycle, and only finitely many cycles. Let  be a known upper bound on  *. REPEAT (forever) e  c e –  Solve shortest path problem with lengths e IF (negative cost cycle W w.r.t. e )    (W) ELSE Find a zero cost cycle W* w.r.t. e. RETURN W*. Sequential Tramp Steamer

19 Tramp-Steamer: Binary Search Procedure W  cycle left  -C, right  C REPEAT (forever) IF (  (W) =  *) RETURN W   (left + right) / 2 e  c e –  Solve shortest path problem with lengths e IF (negative cost cycle w.r.t. e ) right   W  negative cost cycle w.r.t. e ELSE IF (zero cost cycle W*) RETURN W*. ELSE left   Binary Search Tramp Steamer left   *  right

20 Tramp-Steamer: Binary Search Procedure Invariant: interval [left, right] and cycle W satisfy: left   *   (W) < right. n Proof by induction follows from cases 1-2. Lemma. Upon termination, the algorithm returns a min ratio cycle. n Immediate from case 3. Assumption. n All arc costs are integers between –C and C. n All arc traversal times are integers between –T and T. Lemma. The algorithm terminates after O(log(nCT)) iterations. n Proof on next slide. Theorem. The algorithm finds min ratio cycle in O(mn log (nCT)) time.

21 Tramp-Steamer: Binary Search Procedure Lemma. The algorithm terminates after O(log(nCT)) iterations. Initially, left = -C, right = C. n Each iteration halves the size of the interval. n Let c(W) and t(W) denote cost and traversal time of cycle W. n We show any interval of size less than 1 / (n 2 T 2 ) contains at most one value from the set { c(W) / t(W) : W is a cycle }. – let W 1 and W 2 cycles with  (W 1 ) >  (W 2 ) – numerator of RHS is at least 1, denominator is at most n 2 T 2 n After 1 + log 2 ((2C) (n 2 T 2 )) = O(log (nCT)) iterations, at most one ratio in the interval. Algorithm maintains cycle W and interval [left, right] s.t. left   *   (W) < right.

22 Tramp Steamer: State of the Art Min ratio cycle. n O(mn log (nCT)). n O(n 3 log 2 n) dense. (Megiddo, 1979) n O(n 3 log n) sparse. (Megiddo, 1983) Minimum mean cycle. n Special case when all traversal times = 1. n  (mn). (Karp, 1978) n O(mn 1/2 log C). (Orlin-Ahuja, 1992) n O(mn log n). (Karp-Orlin, 1981) – parametric simplex - best in practice

23 Optimal Pipelining of VLSI Chip Novel application. n Minimize cycle time (maximize frequency) of logic chip on IBM processor chips by adjusting clocking schedule. If clock signal arrive at latches simultaneously, min cycle time = 14. Allow individual clock arrival times at latches. Clock signal at latch: n A: 0, 10, 20, 30,... n B: -1, 9, 19, 29,... n C: 0, 10, 20, 30,... n D: -4, 6, 16, 26,... Optimal cycle time = 10. Max mean weight cycle = 10. B D C 14 A Latch Graph 7 6