Lecture 7: Shortest Paths in Graphs with Negative Arc Lengths. Reading: AM&O Chapter 5

Similar documents
Design and Analysis of Algorithms

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

Single Source Shortest Paths

Shortest paths: label setting

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

All-Pairs Shortest Paths

CS 4407 Algorithms Lecture: Shortest Path Algorithms

Introduction to Algorithms

Note that M i,j depends on two entries in row (i 1). If we proceed in a row major order, these two entries will be available when we are ready to comp

Chapter 8 Dynamic Programming

Analysis of Algorithms I: All-Pairs Shortest Paths

Design and Analysis of Algorithms

Lecture 3. 1 Polynomial-time algorithms for the maximum flow problem

Lecture 13: Polynomial-Time Algorithms for Min Cost Flows. (Reading: AM&O Chapter 10)

Chapter 8 Dynamic Programming

Chapter 9: Relations Relations

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Discrete Wiskunde II. Lecture 5: Shortest Paths & Spanning Trees

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

CS675: Convex and Combinatorial Optimization Fall 2016 Combinatorial Problems as Linear and Convex Programs. Instructor: Shaddin Dughmi

Shortest paths with negative lengths

NAME: Be clear and concise. You may use the number of points assigned toeach problem as a rough

The Budget-Constrained Maximum Flow Problem

Combinatorial Optimization

Flows. Chapter Circulations

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

CS 241 Analysis of Algorithms

Maximum flow problem (part I)

Lecture 11. Single-Source Shortest Paths All-Pairs Shortest Paths

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Partha Sarathi Mandal

Relation of Pure Minimum Cost Flow Model to Linear Programming

Mathematics for Decision Making: An Introduction. Lecture 8

Single Source Shortest Paths

Maximum flow problem CE 377K. February 26, 2015

iretilp : An efficient incremental algorithm for min-period retiming under general delay model

Shortest Paths. CS 320, Fall Dr. Geri Georg, Instructor 320 ShortestPaths 3

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

A NOTE ON STRATEGY ELIMINATION IN BIMATRIX GAMES

CS 410/584, Algorithm Design & Analysis, Lecture Notes 4

A Polynomial-Time Algorithm to Find Shortest Paths with Recourse

6.889 Lecture 4: Single-Source Shortest Paths

Lecture Notes for Chapter 25: All-Pairs Shortest Paths

Routing Algorithms. CS60002: Distributed Systems. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

CSC 373: Algorithm Design and Analysis Lecture 12

Written Qualifying Exam. Spring, Friday, May 22, This is nominally a three hour examination, however you will be

Dynamic Programming. Data Structures and Algorithms Andrei Bulatov

Copyright 1972, by the author(s). All rights reserved.

CS675: Convex and Combinatorial Optimization Fall 2014 Combinatorial Problems as Linear Programs. Instructor: Shaddin Dughmi

Informatique Fondamentale IMA S8

Discrete Optimization 2010 Lecture 3 Maximum Flows

Complexity Theory of Polynomial-Time Problems

Randomized Sorting Algorithms Quick sort can be converted to a randomized algorithm by picking the pivot element randomly. In this case we can show th

Lecture 2: Divide and conquer and Dynamic programming

6. DYNAMIC PROGRAMMING II. sequence alignment Hirschberg's algorithm Bellman-Ford distance vector protocols negative cycles in a digraph

CSC 1700 Analysis of Algorithms: Warshall s and Floyd s algorithms

Section Summary. Sequences. Recurrence Relations. Summations Special Integer Sequences (optional)

A faster algorithm for the single source shortest path problem with few distinct positive lengths

NATIONAL UNIVERSITY OF SINGAPORE CS3230 DESIGN AND ANALYSIS OF ALGORITHMS SEMESTER II: Time Allowed 2 Hours

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Econ 172A, Fall 2012: Final Examination Solutions (I) 1. The entries in the table below describe the costs associated with an assignment

Chapter 7 Network Flow Problems, I

Introduction to Algorithms

Introduction to Algorithms

6. DYNAMIC PROGRAMMING II

CS261: A Second Course in Algorithms Lecture #12: Applications of Multiplicative Weights to Games and Linear Programs

1 Review of Vertex Cover

Analysis of Algorithms. Outline. Single Source Shortest Path. Andres Mendez-Vazquez. November 9, Notes. Notes

On the Exponent of the All Pairs Shortest Path Problem

Solutions to Exercises

Determine the size of an instance of the minimum spanning tree problem.

Breadth-First Search of Graphs

Discrete Optimization Lecture 5. M. Pawan Kumar

Econ 172A, Fall 2012: Final Examination Solutions (II) 1. The entries in the table below describe the costs associated with an assignment

REVISION SHEET DECISION MATHS 2 DECISION ANALYSIS

Limitations of Algorithm Power

Find: a multiset M { 1,..., n } so that. i M w i W and. i M v i is maximized. Find: a set S { 1,..., n } so that. i S w i W and. i S v i is maximized.

Breadth First Search, Dijkstra s Algorithm for Shortest Paths

Graphs and Network Flows IE411. Lecture 15. Dr. Ted Ralphs

Lecture 7: Dynamic Programming I: Optimal BSTs

CMPSCI 611 Advanced Algorithms Midterm Exam Fall 2015

Shortest Path Algorithms

GRAPH ALGORITHMS Week 3 (16-21 October 2017)

Data Structures in Java

Lecture 8: Complete Problems for Other Complexity Classes

CSC Design and Analysis of Algorithms. LP Shader Electronics Example

III. Linear Programming

Introduction to Algorithms

CS173 Lecture B, November 3, 2015

ACM-ICPC South Western European Regional SWERC 2008

Max-plus algebra. Max-plus algebra. Monika Molnárová. Technická univerzita Košice. Max-plus algebra.

Network Flows. 6. Lagrangian Relaxation. Programming. Fall 2010 Instructor: Dr. Masoud Yaghini

Basic Test. To show three vectors are independent, form the system of equations

CMPS 2200 Fall Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk. 10/8/12 CMPS 2200 Intro.

Linear Equations in Linear Algebra

6. DYNAMIC PROGRAMMING I

Combinatorial optimization problems

Numerical Solution Techniques in Mechanical and Aerospace Engineering

5. Solving the Bellman Equation

CS 781 Lecture 9 March 10, 2011 Topics: Local Search and Optimization Metropolis Algorithm Greedy Optimization Hopfield Networks Max Cut Problem Nash

Transcription:

Lecture 7: Shortest Paths in Graphs with Negative Arc Lengths Reading: AM&O Chapter

Label Correcting Methods Assume the network G is allowed to have negative arc lengths but no directed negativelyweighted cycles. Assume that there exist a directed (s, j)-path for every node j, and that all arc lengths are integer. Let C be the largest absolute value of an arc length. Recall Bellman s conditions for a set of node labels d j to comprise correct shortest (s, j)-path distances: (a) for each node j, there exists at least one (s, j)-path of length d j (b) Bellman s Equations are satisfied: d s = 0 d j = min{d i + c ij : i B(j)} j s. Idea of label correcting: Look for arcs (i, j) for which d j > d i + c ij and correct d j to satisfy d j = d i + c ij

Generic Label Correcting Procedure set labels d j = { 0 j = s otherwise while d j > d i + c ij for some arc (i, j) { set d j = d i + c ij, Pred(j)=(i, j) } Correctness and Complexity: 1. The Pred() graph will eventually include every node, and can never produce a cycle (Why?). Thus every node i will eventually have a path from s of length exactly d i. Labels are nonincreasing, and each of the n labels can become no smaller than nc. Thus the algorithm must terminate in at most n C iterations, with labels satistying Bellman s conditions. Problem: Not polynomial

Modified Label Correcting Algorithm Again we can modify FINDPATH to improve the complexity of the generic procedure. { 0 v = s set labels d v = otherwise set LIST = {s}, while LIST begin select k LIST for i A(k) do if d i > d k + c ki then begin set d i = d k + c ki set Pred(i)=(k, i) if i LIST than add i to LIST end remove k from LIST end

Example Problem 0 s 1 node 1 LIST - 0 1 Example Problem

0 s 1 node 1 LIST 0 1 1 0,

Example Problem 0 s 1 10 node 1 LIST 0 1 1 0, 0 10,

Example Problem s 10 0 1 10 node 1 LIST 0 1 1 0, 0 10, 0 10 10,

Example Problem 0 s 1 10 1 10 node 1 LIST 0 1 1 0, 0 10, 0 10 10, 0 10 10 1,

Example Problem 0 s 1 10 1 10 node 1 LIST 0 1 1 0, 0 10, 0 10 10, 0 10 10 1, 0 10 10 1,

Example Problem 9 0 1 s 1 10 node 1 LIST 0 1 1 0, 0 10, 0 10 10, 0 10 10 1, 0 10 10 1, 0 10 10 1 0 9 10 1

Example Problem 9 0 1 s 1 10 node 1 LIST 0 1 1 0, 0 10, 0 10 10, 0 10 10 1, 0 10 10 1, 0 10 10 1 0 9 10 1 0 9 10 1 0 9 10 1

Theorem: If elements from LIST are chosen in FIFO order, then the modified label correcting algorithm finds all minimum length (s, i)-paths in O(nm) steps. Proof: Because of the FIFO search order, a node i is reexamined only after every other node whose label was changed before i has been examined. Since a node that has not had its label changed will not affect any other labels, we can assume WLOG that in a particular pass of the algorithm all nodes are examined.

Claim: After the k th stage, the algorithm has determined the correct shortest path distance for all nodes i for which the shortest (s, i)-paths has at most k arcs. Proof of claim: Clearly true for k = 0. Now assume that the claim is true after k 0 passes. Since WLOG the algorithm examines all nodes in the (k + 1) st pass, then any node for whom the shortest path is of length k + 1 must be given the correct shortest path distance in the (k+1) st pass. Therefore the algorithm will have found the correct shortest distance labels after at most n 1 passes, each pass of which requires looking at possibly all of the edges. The total complexity is thus O(nm).

Converting Negative Arc Weights to Nonnegative Arc Weights Properties of shortest path distances: It follows directly from Label-Correcting Algorithm that the final set of distances d i satisfy (i) d i d j + c ij for every arc (i, j), and (ii) d i = d j + c ij for every arc in the shortest path tree. Useful Fact: Let π i, i N be any set of numbers assigned to the nodes, and set c π ij = c ij π i + π j. Then every path P between two nodes s and t will have c π -length c π (P ) = c(p ) π s + π t.

Valuable Application Suppose you solved the Shortest s-to-all Path Problem for a graph G with general arc weights, and obtained the correct shortest (s, i)-path distances d i, i N. If we set π = d above, then it follows directly from the the above two observations that (i) c π ij = c ij + d i d j 0 for all arcs (i, j), (ii) c π ij = 0 for all arcs in the shortest path tree, (iii) for any pair of nodes s and t, the shortest c π -length (s, t)-paths and the shortest c-length (s, t)-paths will be identical. In particular, it follows from (i) and (iii) that once you find all shortest (s, i)-paths for one s using, say label correcting methods, than any other shortest (i, j)-paths can be found using Dijkstra s Algorithm (which is much faster).

Example 1 9 10 1 0 9 10 Final Label Correcting Distances Adjusted Arc Weights 0 1 0 0 1 0 0 0 1 s 1 s

Example: Finding shortest pairs between all pairs of nodes involves n applications of a shortest (s, j)-path algorithm (one for each s). Using the Modified Label Correcting Algorithm will take O(n m) time, but with the above procedure the time is now O(nS(m, n)) Where S(m, n) is the fastest implementation of Dijkstra s Algorithm. This could be as small as O(nm + n log n) (Fibonacci heaps) or O(nm + n log C) (radix+fibonacci heaps).

Matrix Methods for Finding All-Pairs Shortest Paths Given: n n matrix C of arc costs for n-node graph G where c ij = 0 if i = j and c ij = if arc (i, j) is not present for which there are no negative weight directed cycles. Find: n n matrix D all-pair shortest path lengths (that is, d ij = shortest path from i to j, and if no (i, j)-path exists). General Procedure: Produce the sequence D 0, D 1,..., D r of n n matrices, with D 0 = C and D r = D.

Matrix Multiplication Method D k has entries [ d k shortest length of an (i, j)-path [i, j] = containing at most k + 1 arcs The update from D k 1 to D k is the matrix multiplication D k = D k 1 C, with the arithmetic operations redefined as follows: where numbers were multiplied, they are now added; where numbers were added, the minimum is now found. and D n now represents the all-pairs shortest path lengths. ] Complexity: O(n log n) (by successive squaring )

Example 1 1-1 D 0 = D 1 = D = 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0

Floyd-Warshall Method D k has entries d k [i, j] = shortest length of an (i, j)-path all of whose interior nodes are in the set {1,,..., k} The update from D k 1 to D k is produced by the pivot operation d k [i, j] = min{d k 1 [i, j], d k 1 [i, k] + d k 1 [k, j]} and D n now represents the all-pairs shortest path lengths.

Floyd-Warshall Procedure Pred[i, j] = node preceding j on the shortest (i, j)- path Initialize: set d[i, j] = Pred[i, j] = i all i, j 0 i = j c ij (i, j) A i j, (i, j) A for k = 1,..., n do for i = 1,..., n do for j = 1,..., n do if d[i, j] > d[i, k] + d[k, j] then begin set d[i, j] = d[i, k] + d[k, j] set Pred[i, j]=pred[k, j] end Complexity: O(n )

Example 1 1-1 D k ( 0 1 0 1 0 0 ( 0 1 0 1 0 0 ( 0 1 0 1 0 0 1 0 ( 0 1 0 1 0 0 1 0 ( 0 1 0 1 0 1 0 0 1 0 ) ) ) ) ) k = 0 k = 1 k = k = (no change) k = Pred k ( 1 1 1 1 ( 1 1 1 1 1 ( 1 1 1 1 1 ( 1 1 1 1 1 ( 1 1 1 ) ) ) ) ) Shortest (1,)-path: 1=Pred(1,) =Pred(1,) =Pred(1,)

Finding Negative Cycles The Floyd-Warshall Algorithm will find negative cycles naturally. The first time a negative cycle is encountered, it will do so by creating a negative number in one of the diagonal elements of the array. The corresponding change in the Pred array will allow you to reconstruct the cycle. 1 1 1 D k ( 0 1 0 1 0 0 ( 0 1 0 1 0 0 ) ) 0 1 0 1 0 1 k = 0 k = 1 k = Pred k ( 1 1 1 1 ( 1 1 1 1 1 1 1 1 1 1 1 ) ) Cycle: =Pred(,) =Pred(,1) 1=Pred(,)

Application: The Tramp Steamer Problem A tramp steamer travels from port to port, doing business at each of the ports it visits. The net profit counting travel costs of making the trip from Port i to Port j is p ij, and the time (in days) to get from Port i to Port j is τ ij (all data are positive integers). The steamer captain wants to choose a circuit W : i 1, i,..., i k = i 1 which has maximum mean daily profit µ(w ) = k 1 j=1 p i j i j+1 k 1 j=1 τ. i j i j+1

Choose a target value µ and attempt to determine if there is a route W which exceeds the daily profit target, µ(w ) > µ, or equivalently, (u,v) W (µτ uv p uv ) < 0 Letting c uv = µτ uv p uv, we are interested in finding a negative length cycle in G. Cases: G has a negative cycle: Then µ underestimates the value of the maximum mean daily profit. Increase µ and try again. G has only positive length cycles: Then µ overestimates the value of the maximum mean daily profit. Decrease µ and try again. G has a minimum cycle W of zero length: Then µ = µ is the correct value for the cycle with maximum mean daily profit, and W is the optimal cycle.

Binary Search to Find the Correct µ Facts: Let P = max{p uv : (u, v) A} and τ 0 = max{τ uv : (u, v) A} 1. The minimum value for µ is P, and the maximum value for µ is P.. If W 1 and W are two cycles in G with different mean daily profits µ(w 1 ) and µ(w ), then µ(w 1 ) µ(w ) 1/(nτ 0 ) The binary search procedure searches for µ within an interval [µ, µ] = {µ : µ µ µ} known to contain µ, progressively halving the interval based on the outcome of the negative cycle procedure.

The Procedure 1. Begin with the interval [ P, P ]. Now for interval [µ, µ] obtained in a general step of the procedure:. Test for a negative cycle, using the value µ 0 = (µ + µ)/. If a negative cycle is found in G, then reset the interval to [µ, µ] = [µ 0, µ]. If only positive cycles are found, then reset the interval to [µ, µ] = [µ, µ 0 ]. If the minimum length cycle has zero length, then halt the algorithm, returning the value µ = µ and the corresponding cycle of maximum mean daily profit.

Termination of the algorithm: If the algorithm fails to find a zero length cycle by the time the interval [µ, µ] is small enough so that µ µ < 1/(nτ 0 ), then there must be exactly one number µ [µ, µ] having denominator 1/(nτ 0 ). By Fact this must be the maximum mean daily profit value, and so we run Step one time to find the optimal cycle W. Complexity of procedure: The number of steps in the binary search procedure is O(log((nτ 0 ) P )) = O(log((nτ 0 ) P )), each of which requires one search for negative cycles. Using Floyd-Warshall, the complexity becomes O(n log((nτ 0 ) P ))).

Example Consider the following tramp steamer problem, where the arcs are marked p ij, τ ij : 1,,,,1,1, Note that 1 1 is the maximum length cycle using either p ij or p ij τ for ij arc weights. Using binary search with P = and τ 0 =, we have the following sequence of stages:

1 [µ, µ] = [, ], µ 0 = 0 1 0 0 0 1 [µ, µ] = [0, ], µ 0 =

1 1 0 [µ, µ] = [, ], µ 0 = 1 1 1 1/ 1/ [µ, µ] = [, ], µ 0 =

1 1/ / 1/ 1/ / / [µ, µ] = [, /], µ 0 = 9/ At this point we obtain zero-length cycle 1, which is the minimum-mean-length cycle, of mean length + + 1 + 1 + = 9. Note that if no zero-length cycle was found, we would have continued until the interval size reached µ µ < 1/(nτ 0 ) =.01 which would have taken another stages.