Chapter 6 Dynamic Programming

Slides:



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

Single Source Shortest Paths
Chapter 4 Distributed Bellman-Ford Routing
Routing Protocol.
DYNAMIC PROGRAMMING. 2 Algorithmic Paradigms Greedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer.
Shortest Path With Negative Weights s 3 t
ROUTING ON THE INTERNET COSC Aug-15. Routing Protocols  routers receive and forward packets  make decisions based on knowledge of topology.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 22.
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)
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.
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.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 17.
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.
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.
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Dynamic routing Routing Algorithm (Dijkstra / Bellman-Ford) – idealization All routers are identical Network is flat. Not true in Practice Hierarchical.
Data Structures and Algorithm Analysis Lecture 5
The network layer: routing
Centralized vs Distributed Routing
Shortest Paths.
Dynamic Routing Protocols part2
(How the routers’ tables are filled in)
Dijkstra’s shortest path Algorithm
Routing Information Protocol (RIP)
Dynamic routing Routing Algorithm (Dijkstra / Bellman-Ford) – idealization All routers are identical Network is flat. Not true in Practice Hierarchical.
Chapter 4 Network Layer A note on the use of these ppt slides:
COMP 3270 Computer Networks
Dynamic Routing Protocols part2
Distance Vector Routing
Intra-Domain Routing Jacob Strauss September 14, 2006.
Routing: Distance Vector Algorithm
Dynamic routing Routing Algorithm (Dijkstra / Bellman-Ford) – idealization All routers are identical Network is flat. Not true in Practice Hierarchical.
Routing.
Chapter 5: Dynamic Routing
Dynamic Routing Protocols part2
Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Routing in Packet Networks Shortest Path Routing
Road Map I. Introduction II. IP Protocols III. Transport Layer
Shortest Paths with Dynamic Programming
CS 4700 / CS 5700 Network Fundamentals
Greedy Algorithms / Dijkstra’s Algorithm Yin Tat Lee
Chapter 6 Dynamic Programming
Shortest Paths.
CS 3700 Networks and Distributed Systems
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Intradomain Routing Outline Introduction to Routing
Richard Anderson Lecture 20 LCS / Shortest Paths
Chapter 6 Dynamic Programming
ECE453 – Introduction to Computer Networks
Communication Networks NETW 501
CS 3700 Networks and Distributed Systems
Communication Networks
Advanced Computer Networks
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Evaluation of the Course (Modified)
COS 461: Computer Networks
Brad Karp UCL Computer Science
EE 122: Intra-domain routing: Distance Vector
Communication Networks
Shortest Paths.
Routing.
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Memory Efficient Dynamic Programming / Shortest Paths
CSCI 465 Data Communications and Networks Lecture 16
Dynamic routing Routing Algorithm (Dijkstra / Bellman-Ford) – idealization All routers are identical Network is flat. Not true in Practice Hierarchical.
Data Structures and Algorithm Analysis Lecture 8
Chapter 4 Network Layer A note on the use of these ppt slides:
Presentation transcript:

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

6.8 Shortest Paths

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

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

Shortest Paths: Negative Cost Cycles 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. -6 -4 7 s t W c(W) < 0

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 Remark. By previous observation, if no negative cycles, then OPT(n-1, v) = length of shortest v-t path.

Shortest Paths: Implementation Analysis. (mn) time, (n2) 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 M[i, v]  M[i-1, v] foreach edge (v, w)  E M[i, v]  min { M[i, v], M[i-1, w] + cvw } } Alternative to maintaining predecessor indices: compute optimal distances, then consider only zero reduced cost edges.

Shortest Paths: 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.

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] + cvw) { M[v]  M[w] + cvw successor[v]  w If no M[w] value changed in iteration i, stop.

6.9 Distance Vector Protocol

Distance Vector Protocol Communication network. Nodes  routers. Edges  direct communication link. 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 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). in some protocols, length = hop count since each node determines is values based on its neighbors, protocol sometimes facetiously reffered to as routing by rumor route invalidation timer: v flags path to t as invalid if v doesn't hear from t for a while RIP fix for counting to infinity: maintain max hop count = 16 1 s v t "counting to infinity" 1 1 2 1 deleted

Path Vector Protocols Link state routing. 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). not just the distance and first hop each router stores whole network topology

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 t W c(W) < 0

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 18 2 6 -23 5 v -11 -15

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 3/10 4/3 2/3 2 3/50 IBM 1/10000 £ 170 DM 56 ¥

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. 288 for improved version and early termination rule. Undirected. O(mn + n2 log n) Reduce to weighted non-bipartite matching. Beyond the scope of this course.