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.

Slides:



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

2015/4/11CS4335 Design and Analysis of Algorithms /Shuai Cheng Li Page 1 Evaluation of the Course (Modified) Course work:30% –Four assignments (25%) 7.5.
Outline  Recap Network components & basic mechanisms Routing Flow control  Continue Basic queueing analysis Construct routing table.
COS 461 Fall 1997 Routing COS 461 Fall 1997 Typical Structure.
Routing Protocol.
CISCO NETWORKING ACADEMY Chabot College ELEC Routed and Routing Protocols.
Distance-Vector and Path-Vector Routing Sections , 4.3.2, COS 461: Computer Networks Spring 2011 Mike Freedman
Routing - I Important concepts: link state based routing, distance vector based routing.
DYNAMIC PROGRAMMING. 2 Algorithmic Paradigms Greedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer.
CMPE 150- Introduction to Computer Networks 1 CMPE 150 Fall 2005 Lecture 22 Introduction to Computer Networks.
Chapter 4 Distance Vector Problems, and Link-State Routing Professor Rick Han University of Colorado at Boulder
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Shortest Path With Negative Weights s 3 t
Routing.
Spring Routing & Switching Umar Kalim Dept. of Communication Systems Engineering 06/04/2007.
1 Computer Networks Routing Algorithms. 2 IP Packet Delivery Two Processes are required to accomplish IP packet delivery: –Routing discovering and selecting.
EE 122: Intra-domain routing Ion Stoica September 30, 2002 (* this presentation is based on the on-line slides of J. Kurose & K. Rose)
CSE 421 Algorithms Richard Anderson Lecture 21 Shortest Paths.
ROUTING ON THE INTERNET COSC Aug-15. Routing Protocols  routers receive and forward packets  make decisions based on knowledge of topology.
Routing Algorithms (Ch5 of Computer Network by A. Tanenbaum)
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 22.
Distributed Asynchronous Bellman-Ford Algorithm
Dynamic Routing Protocols  Function(s) of Dynamic Routing Protocols: – Dynamically share information between routers (Discover remote networks). – Automatically.
Review: routing algorithms. –Choose the appropriate paths. –Routing algorithms Flooding Shortest path routing (example). –Dijkstra algorithm. –Bellman-Ford.
1 Chapter 22 Network layer Delivery, Forwarding and Routing (part2)
Link-state routing  each node knows network topology and cost of each link  quasi-centralized: each router periodically broadcasts costs of attached.
1 Algorithmic Paradigms Greed. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer. Break up a problem into.
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 6 Shortest Path Algorithms.
Network Layer4-1 Chapter 4: Network Layer r 4. 1 Introduction r 4.2 Virtual circuit and datagram networks r 4.3 What’s inside a router r 4.4 IP: Internet.
1 Internet Routing. 2 Terminology Forwarding –Refers to datagram transfer –Performed by host or router –Uses routing table Routing –Refers to propagation.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 17.
Network Layer4-1 Distance Vector: link cost changes Link cost changes: r node detects local link cost change r updates distance table (line 15) r if cost.
TCOM 509 – Internet Protocols (TCP/IP) Lecture 06_a Routing Protocols: RIP, OSPF, BGP Instructor: Dr. Li-Chuan Chen Date: 10/06/2003 Based in part upon.
Spring 2006CS 3321 Intradomain Routing Outline Algorithms Scalability.
1 Computer Communication & Networks Lecture 21 Network Layer: Delivery, Forwarding, Routing Waleed.
Networking and internetworking devices. Repeater.
Data Structures & Algorithms Shortest Paths Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Internet Routing r Routing algorithms m Link state m Distance Vector m Hierarchical routing r Routing protocols m RIP m OSPF m BGP.
1 Version 3.1 Module 6 Routed & Routing Protocols.
1 7-Jan-16 S Ward Abingdon and Witney College Dynamic Routing CCNA Exploration Semester 2 Chapter 3.
ITI-510 Computer Networks ITI 510 – Computer Networks Meeting 3 Rutgers University Internet Institute Instructor: Chris Uriarte.
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.
1 © 2004, Cisco Systems, Inc. All rights reserved. CCNA 1 Module 10 Routing Fundamentals and Subnets.
Ch 22. Routing Direct and Indirect Delivery.
Spring 2000CS 4611 Routing Outline Algorithms Scalability.
Graph Algorithms Why graph algorithms ? It is not a “graph theory” course! Many problems in networks can be modeled as graph problems. Note that -The topology.
Spring Routing: Part I Section 4.2 Outline Algorithms Scalability.
Network Layer (2). Review Physical layer: move bits between physically connected stations Data link layer: move frames between physically connected stations.
Distance Vector Routing
CS 6401 Intra-domain Routing Outline Introduction to Routing Distance Vector Algorithm.
CSE 421 Algorithms Richard Anderson Lecture 21 Shortest Paths and Network Flow.
Distance Vector and Link State Routing Pragyaditya Das.
ROUTING ON THE INTERNET COSC Jun-16. Routing Protocols  routers receive and forward packets  make decisions based on knowledge of topology.
Shortest Paths.
COMP 3270 Computer Networks
Intra-Domain Routing Jacob Strauss September 14, 2006.
Routing: Distance Vector Algorithm
Shortest Paths with Dynamic Programming
Chapter 6 Dynamic Programming
CS 3700 Networks and Distributed Systems
Intradomain Routing Outline Introduction to Routing
Chapter 6 Dynamic Programming
Chapter 6 Dynamic Programming
CS 3700 Networks and Distributed Systems
Communication Networks
Advanced Computer Networks
Evaluation of the Course (Modified)
EE 122: Intra-domain routing: Distance Vector
Communication Networks
Presentation transcript:

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 Programming Shortest paths and Bellman-Ford

Shortest Paths: Negative Cost Cycles Negative cost cycle. 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. st W c(W) <

Shortest Paths: Dynamic Programming Def. OPT(i, v) = length of shortest v-t path P using at most i edges (  if no such path exists) n Case 1: P uses at most i-1 edges. – OPT(i, v) = OPT(i-1, v) n 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 Remark. By previous observation, if no negative cycles, then OPT(n-1, v) = length of shortest v-t path. or 

Shortest Paths: Implementation Analysis.  (mn) time,  (n 2 ) space. Finding the shortest paths. Maintain a "successor" for each table entry. 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 } }

Shortest Paths: Improvements Maintain only one array M[v] = length of shortest v-t path 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. n Memory: O(m + n). n Running time: O(mn) worst case, but substantially faster in practice.

Bellman-Ford: Efficient Implementation Bellman-Ford-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. }

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Example of Bellman-Ford A A B B E E C C D D – – The demonstration is for a sligtly different version of the algorithm (see CLRS) that computes distances from the sourse node rather than distances to the destination node.

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Example of Bellman-Ford A A B B E E C C D D – –  0   Initialization.

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Example of Bellman-Ford A A B B E E C C D D – –  0   Order of edge relaxation. 6

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Example of Bellman-Ford A A B B E E C C D D – –  0  

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Example of Bellman-Ford A A B B E E C C D D – –  0  

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Example of Bellman-Ford A A B B E E C C D D – –  0  

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne  Example of Bellman-Ford A A B B E E C C D D – –  

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne    Example of Bellman-Ford A A B B E E C C D D – –  

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne   Example of Bellman-Ford A A B B E E C C D D – –  

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne   Example of Bellman-Ford A A B B E E C C D D – –  

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne   Example of Bellman-Ford A A B B E E C C D D – –  

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne   Example of Bellman-Ford A A B B E E C C D D – –   End of pass 1. 6

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne     Example of Bellman-Ford A A B B E E C C D D – – 

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne    Example of Bellman-Ford A A B B E E C C D D – – 

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne      Example of Bellman-Ford A A B B E E C C D D – –

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne     Example of Bellman-Ford A A B B E E C C D D – –

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne     Example of Bellman-Ford A A B B E E C C D D – –

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne     Example of Bellman-Ford A A B B E E C C D D – –

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne     Example of Bellman-Ford A A B B E E C C D D – –

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne     Example of Bellman-Ford A A B B E E C C D D – –

10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne     Example of Bellman-Ford A A B B E E C C D D – – End of pass 2 (and 3 and 4).

Distance Vector Protocol Communication network. n Nodes  routers. n Edges  direct communication links. n Cost of edge  delay on link. 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. naturally nonnegative, but Bellman-Ford used anyway!

Distance Vector Protocol Distance vector protocol. n Each router maintains a vector of shortest path lengths to every other node (distances) and the first hop on each path (directions). n Algorithm: each router performs n separate computations, one for each potential destination node. n "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). t v 1 s 1 1 deleted "counting to infinity" 2 1

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

Detecting Negative Cycles Bellman-Ford is guaranteed to work if there are no negative cost cycles. How can we tell if neg. cost cycles exist? We could pick a destination vertex t and check if the cost estimates in Bellman-Ford converge or not. What is wrong with this? (What if a cycle isn’t on any path to t?) v

Detecting Negative Cycles Theorem. Can find negative cost cycle in O(mn) time. n Add new node t and connect all nodes to t with 0-cost edge. n 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 v t

Detecting Negative Cycles Lemma. If OPT(n,v) = OPT(n-1,v) for all v, then no negative cycles are connected to t. Pf. If OPT(n,v)=OPT(n-1,v) for all v, then distance estimates won’t change again even with many executions of the for loop. In particular, OPT(2n,v)=OPT(n-1,v). So there are no negative cost cycles. 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) n Since OPT(n,v) < OPT(n-1,v), we know P has exactly n edges. n By pigeonhole principle, P must contain a directed cycle W. n Deleting W yields a v-t path with < n edges  W has negative cost. v t W c(W) < 0

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! F$ £ ¥ DM 1/7 3/10 2/ /50 4/3 8 IBM 1/

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

Homework ideas Johnson’s algorithm for All-Pairs SP matrix algs for APSP Programming project? longest path: in a DAG using 2^n-time DP