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

Similar documents
Data Structures and Algorithms CMPSC 465

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

6. DYNAMIC PROGRAMMING II

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Dynamic Programming. Data Structures and Algorithms Andrei Bulatov

cs/ee/ids 143 Communication Networks

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

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

6. DYNAMIC PROGRAMMING II

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

6. DYNAMIC PROGRAMMING II

Lecture 2: Divide and conquer and Dynamic programming

6. DYNAMIC PROGRAMMING I

Running Time. Assumption. All capacities are integers between 1 and C.

Chapter 7. Network Flow. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

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

Algorithms: Lecture 12. Chalmers University of Technology

Mathematics for Decision Making: An Introduction. Lecture 8

CSE 202 Dynamic Programming II

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Dynamic Programming: Shortest Paths and DFA to Reg Exps

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

Shortest Path Algorithms

Shortest paths: label setting

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

Copyright 2000, Kevin Wayne 1

Theoretical Computer Science. Partially dynamic efficient algorithms for distributed shortest paths

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

Copyright 2000, Kevin Wayne 1

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

Algorithm Design and Analysis

2. ALGORITHM ANALYSIS

Algorithm Design and Analysis

CS 580: Algorithm Design and Analysis

Design and Analysis of Algorithms

2.1 Computational Tractability. Chapter 2. Basics of Algorithm Analysis. Computational Tractability. Polynomial-Time

12. LOCAL SEARCH. gradient descent Metropolis algorithm Hopfield neural networks maximum cut Nash equilibria

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

1. REPRESENTATIVE PROBLEMS

6. DYNAMIC PROGRAMMING I

12. LOCAL SEARCH. gradient descent Metropolis algorithm Hopfield neural networks maximum cut Nash equilibria

AGREEMENT PROBLEMS (1) Agreement problems arise in many practical applications:

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

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

CS 580: Algorithm Design and Analysis

Single Source Shortest Paths

Routing. Topics: 6.976/ESD.937 1

Algorithm Design and Analysis

Chapter 9. PSPACE: A Class of Problems Beyond NP. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

9. PSPACE 9. PSPACE. PSPACE complexity class quantified satisfiability planning problem PSPACE-complete

1. REPRESENTATIVE PROBLEMS

9. PSPACE. PSPACE complexity class quantified satisfiability planning problem PSPACE-complete

What Have We Learned from Reverse-Engineering the Internet s Inter-domain Routing Protocol?

CS 4407 Algorithms Lecture: Shortest Path Algorithms

CS 580: Algorithm Design and Analysis

1. STABLE MATCHING. stable matching problem Gale Shapley algorithm hospital optimality context

Chapter 7. Network Flow. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

CMSC 858F: Algorithmic Game Theory Fall 2010 BGP and Interdomain Routing

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

5. Solving the Bellman Equation

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Problem set 1. (c) Is the Ford-Fulkerson algorithm guaranteed to produce an acyclic maximum flow?

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

Dynamic Programming 1

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

CS781 Lecture 3 January 27, 2011

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

Matching Residents to Hospitals

Single Source Shortest Paths

Algorithm Design CS 515 Fall 2015 Sample Final Exam Solutions

Chapter 6. Weighted Interval Scheduling. Dynamic Programming. Algorithmic Paradigms. Dynamic Programming Applications

Distributed Optimization. Song Chong EE, KAIST

1. REPRESENTATIVE PROBLEMS

Section 6 Fault-Tolerant Consensus

Reductions. Reduction. Linear Time Reduction: Examples. Linear Time Reductions

8. INTRACTABILITY I. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley. Last updated on 2/6/18 2:16 AM

Dantzig s pivoting rule for shortest paths, deterministic MDPs, and minimum cost to time ratio cycles

Dynamic Programming. Cormen et. al. IV 15

LINEAR PROGRAMMING III

Copyright 2000, Kevin Wayne 1

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Linear Selection and Linear Sorting

Chapter 7. Network Flow. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Algorithm Design and Analysis

L11: Algebraic Path Problems with applications to Internet Routing Lectures 7 and 8

4/30/14. Chapter Sequencing Problems. NP and Computational Intractability. Hamiltonian Cycle

Algorithm Design and Analysis

Areas. ! Bioinformatics. ! Control theory. ! Information theory. ! Operations research. ! Computer science: theory, graphics, AI, systems,.

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

1 Introduction. 1.1 The Problem Domain. Self-Stablization UC Davis Earl Barr. Lecture 1 Introduction Winter 2007

Chapter 6. Dynamic Programming. CS 350: Winter 2018

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

Part V. Matchings. Matching. 19 Augmenting Paths for Matchings. 18 Bipartite Matching via Flows

Greedy Algorithms. Kleinberg and Tardos, Chapter 4

On the Exponent of the All Pairs Shortest Path Problem

Algorithms and Theory of Computation. Lecture 11: Network Flow

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

LINEAR PROGRAMMING II

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

Transcription:

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

6.8 Shortest Paths

Shortest Paths Shortest path problem. Given a directed graph G = (V, E), with edge weights c vw, find shortest path from node s to node t. allow negative weights Ex. Nodes represent agents in a financial setting and c vw is cost of transaction in which we buy from agent v and sell immediately to w. s 9 6 2 6 10 18-16 6 3 15-8 20 30 5 11 16 4 6 19 7 44 t 3

Shortest Paths: Failed Attempts Dijkstra. Can fail if negative edge costs. 2 u 3 s v 1 t -6 Re-weighting. Adding a constant to every edge weight can fail. 5 5 2 2 s 6 3 0-3 6 3 t 4

Shortest Paths: Negative Cost Cycles Negative cost cycle. -6-4 7 Observation. If some path from s to t contains a negative cost cycle, there does not exist a shortest s-t path; otherwise, there exists one that is simple. s W t c(w) < 0 5

Shortest Paths: Dynamic Programming Def. OPT(i, v) = length of shortest v-t path P using at most i edges. Case 1: P uses at most i-1 edges. OPT(i, v) = OPT(i-1, v) Case 2: P uses exactly i edges. if (v, w) is first edge, then OPT uses (v, w), and then selects best w-t path using at most i-1 edges OPT(i, v) = $ * % &* 0 if i = 0 $ ' min% OPT(i "1, v), min { OPT(i "1, w)+ c vw } ( otherwise & (v, w) # E ) Remark. By previous observation, if no negative cycles, then OPT(n-1, v) = length of shortest v-t path. 6

Shortest Paths: Implementation Shortest-Path(G, t) { foreach node v V M[0, v] M[0, t] 0 } for i = 1 to n-1 foreach node v V M[i, v] M[i-1, v] foreach edge (v, w) E M[i, v] min { M[i, v], M[i-1, w] + c vw } Analysis. Θ(mn) time, Θ(n 2 ) space. Finding the shortest paths. Maintain a "successor" for each table entry. 7

Shortest Paths: Practical Improvements Practical improvements. Maintain only one array M[v] = shortest v-t path that we have found so far. No need to check edges of the form (v, w) unless M[w] changed in previous iteration. Theorem. Throughout the algorithm, M[v] is length of some v-t path, and after i rounds of updates, the value M[v] is no larger than the length of shortest v-t path using i edges. Overall impact. Memory: O(m + n). Running time: O(mn) worst case, but substantially faster in practice. 8

Bellman-Ford: Efficient Implementation Push-Based-Shortest-Path(G, s, t) { foreach node v V { M[v] successor[v] φ } } M[t] = 0 for i = 1 to n-1 { foreach node w V { if (M[w] has been updated in previous iteration) { foreach node v such that (v, w) E { if (M[v] > M[w] + c vw ) { M[v] M[w] + c vw successor[v] w } } } If no M[w] value changed in iteration i, stop. } 9

6.9 Distance Vector Protocol

Distance Vector Protocol Communication network. Node router. Edge direct communication link. Cost of edge delay on link. naturally nonnegative, but Bellman-Ford used anyway! Dijkstra's algorithm. Requires global information of network. Bellman-Ford. Uses only local knowledge of neighboring nodes. Synchronization. We don't expect routers to run in lockstep. The order in which each foreach loop executes in not important. Moreover, algorithm still converges even if updates are asynchronous. 11

Distance Vector Protocol Distance vector protocol. Each router maintains a vector of shortest path lengths to every other node (distances) and the first hop on each path (directions). Algorithm: each router performs n separate computations, one for each potential destination node. "Routing by rumor." Ex. RIP, Xerox XNS RIP, Novell's IPX RIP, Cisco's IGRP, DEC's DNA Phase IV, AppleTalk's RTMP. Caveat. Edge costs may change during algorithm (or fail completely). 1 s 1 v 1 t "counting to infinity" 2 1 deleted 12

Path Vector Protocols Link state routing. not just the distance and first hop Each router also stores the entire path. Based on Dijkstra's algorithm. Avoids "counting-to-infinity" problem and related difficulties. Requires significantly more storage. Ex. Border Gateway Protocol (BGP), Open Shortest Path First (OSPF). 13

6.10 Negative Cycles in a Graph

Detecting Negative Cycles Lemma. If OPT(n,v) = OPT(n-1,v) for all v, then no negative cycles. Pf. Bellman-Ford algorithm. Lemma. If OPT(n,v) < OPT(n-1,v) for some node v, then (any) shortest path from v to t contains a cycle W. Moreover W has negative cost. Pf. (by contradiction) Since OPT(n,v) < OPT(n-1,v), we know P has exactly n edges. By pigeonhole principle, P must contain a directed cycle W. Deleting W yields a v-t path with < n edges W has negative cost. v W t c(w) < 0 15

Detecting Negative Cycles Theorem. Can detect negative cost cycle in O(mn) time. Add new node t and connect all nodes to t with 0-cost edge. Check if OPT(n, v) = OPT(n-1, v) for all nodes v. if yes, then no negative cycles if no, then extract cycle from shortest path from v to t t 0 0 0 0 0 18 2 6 5-23 -15 v -11 16

Detecting Negative Cycles: Application Currency conversion. Given n currencies and exchange rates between pairs of currencies, is there an arbitrage opportunity? Remark. Fastest algorithm very valuable! 8 $ 1/7 F 800 4/3 2/3 2 3/10 3/50 IBM 1/10000 170 DM 56 17

Detecting Negative Cycles: Summary Bellman-Ford. O(mn) time, O(m + n) space. Run Bellman-Ford for n iterations (instead of n-1). Upon termination, Bellman-Ford successor variables trace a negative cycle if one exists. See p. 304 for improved version and early termination rule. 18