Shortest Paths. Algorithms and Networks 2014/2015 Hans L. Bodlaender Johan M. M. van Rooij

Similar documents
Social Media Mining. Graph Essentials

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Cpt S 223. School of EECS, WSU

A Review And Evaluations Of Shortest Path Algorithms

The Goldberg Rao Algorithm for the Maximum Flow Problem

Minimum cost maximum flow, Minimum cost circulation, Cost/Capacity scaling

Data Structures and Algorithms Written Examination

Scheduling Shop Scheduling. Tim Nieberg

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. #-approximation algorithm.

Connectivity and cuts

Data Structures Fibonacci Heaps, Amortized Analysis

Bicolored Shortest Paths in Graphs with Applications to Network Overlay Design

Midterm Practice Problems

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. !-approximation algorithm.

Simplified External memory Algorithms for Planar DAGs. July 2004

Exam study sheet for CS2711. List of topics

Analysis of Algorithms, I

Problem Set 7 Solutions

IE 680 Special Topics in Production Systems: Networks, Routing and Logistics*

6.852: Distributed Algorithms Fall, Class 2

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

Approximation Algorithms

GRAPH THEORY LECTURE 4: TREES

Algorithm Design and Analysis

Chapter Load Balancing. Approximation Algorithms. Load Balancing. Load Balancing on 2 Machines. Load Balancing: Greedy Scheduling

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Dynamic programming. Doctoral course Optimization on graphs - Lecture 4.1. Giovanni Righini. January 17 th, 2013

5.1 Bipartite Matching

CS711008Z Algorithm Design and Analysis

Solutions to Homework 6

2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

Dynamic Programming. Lecture Overview Introduction

TU e. Advanced Algorithms: experimentation project. The problem: load balancing with bounded look-ahead. Input: integer m 2: number of machines

Lecture 15 An Arithmetic Circuit Lowerbound and Flows in Graphs

2.3 Convex Constrained Optimization Problems

The Binary Blocking Flow Algorithm. Andrew V. Goldberg Microsoft Research Silicon Valley goldberg/

Graph Theory and Complex Networks: An Introduction. Chapter 06: Network analysis

CMPSCI611: Approximating MAX-CUT Lecture 20

Section IV.1: Recursive Algorithms and Recursion Trees

Seminar. Path planning using Voronoi diagrams and B-Splines. Stefano Martina

Graph Theory Problems and Solutions

Mining Social Network Graphs

Labeling outerplanar graphs with maximum degree three

Single machine parallel batch scheduling with unbounded capacity

Scheduling Home Health Care with Separating Benders Cuts in Decision Diagrams

LECTURE 4. Last time: Lecture outline

Diversity Coloring for Distributed Data Storage in Networks 1

Why? A central concept in Computer Science. Algorithms are ubiquitous.

A hierarchical multicriteria routing model with traffic splitting for MPLS networks

Lecture 3. Linear Programming. 3B1B Optimization Michaelmas 2015 A. Zisserman. Extreme solutions. Simplex method. Interior point method

The Binary Blocking Flow Algorithm. Andrew V. Goldberg Microsoft Research Silicon Valley goldberg/

Routing in packet-switching networks

Any two nodes which are connected by an edge in a graph are called adjacent node.

Lecture 1: Course overview, circuits, and formulas

A simpler and better derandomization of an approximation algorithm for Single Source Rent-or-Buy

Approximability of Two-Machine No-Wait Flowshop Scheduling with Availability Constraints

Course on Social Network Analysis Graphs and Networks

Data Structure [Question Bank]

MapReduce and Distributed Data Analysis. Sergei Vassilvitskii Google Research

Guessing Game: NP-Complete?

Shortcut sets for plane Euclidean networks (Extended abstract) 1

Running Time Analysis of ACO Systems for Shortest Path Problems

THE PROBLEM WORMS (1) WORMS (2) THE PROBLEM OF WORM PROPAGATION/PREVENTION THE MINIMUM VERTEX COVER PROBLEM

A New Approach to Dynamic All Pairs Shortest Paths

Discrete Mathematics & Mathematical Reasoning Chapter 10: Graphs

Graph Theory and Complex Networks: An Introduction. Chapter 06: Network analysis. Contents. Introduction. Maarten van Steen. Version: April 28, 2014

Incremental Network Design with Shortest Paths

Lecture 22: November 10

CS 598CSC: Combinatorial Optimization Lecture date: 2/4/2010

Well-Separated Pair Decomposition for the Unit-disk Graph Metric and its Applications

Network File Storage with Graceful Performance Degradation

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Graphs without proper subgraphs of minimum degree 3 and short cycles

Fast Edge Splitting and Edmonds Arborescence Construction for Unweighted Graphs

2.8 An application of Dynamic Programming to machine renewal

SYSM 6304: Risk and Decision Analysis Lecture 5: Methods of Risk Analysis

Near Optimal Solutions

Class notes Program Analysis course given by Prof. Mooly Sagiv Computer Science Department, Tel Aviv University second lecture 8/3/2007

Data Structures. Chapter 8

ONLINE DEGREE-BOUNDED STEINER NETWORK DESIGN. Sina Dehghani Saeed Seddighin Ali Shafahi Fall 2015

SCORE SETS IN ORIENTED GRAPHS

An Introduction to The A* Algorithm

Distributed Computing over Communication Networks: Maximal Independent Set

Dynamic Programming and Graph Algorithms in Computer Vision

5 Directed acyclic graphs

V. Adamchik 1. Graph Theory. Victor Adamchik. Fall of 2005

Time-dependent networks as models to achieve fast exact time-table queries

How To Solve The Line Connectivity Problem In Polynomatix

Modeling and Performance Evaluation of Computer Systems Security Operation 1

A Practical Scheme for Wireless Network Operation

136 CHAPTER 4. INDUCTION, GRAPHS AND TREES

Handout #Ch7 San Skulrattanakulchai Gustavus Adolphus College Dec 6, Chapter 7: Digraphs

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Single machine models: Maximum Lateness -12- Approximation ratio for EDD for problem 1 r j,d j < 0 L max. structure of a schedule Q...

DATA ANALYSIS II. Matrix Algorithms

1 Definitions. Supplementary Material for: Digraphs. Concept graphs

Fast Point-to-Point Shortest Path Computations with Arc-Flags

Computer Algorithms. NP-Complete Problems. CISC 4080 Yanjun Li

Search Heuristics for Load Balancing in IP-networks

CS Computer Networks 1: Routing Algorithms

Transcription:

Shortest Paths Algorithms and Networks 2014/2015 Hans L. Bodlaender Johan M. M. van Rooij 1

Contents The shortest path problem: Statement Versions Applications Algorithms Reminders: Dijkstra, Bellman-Ford, Floyd-Warshall Reweighting (Johnson s algorithm) Scaling technique (Gabow s algorithm) Variant algorithms / optimisations: A* Bidirectional search Bottleneck shortest paths 2

Notation In the entire course (and most of the literature): G = (V,E) is an undirected graph with vertices V and edge E. G = (V,A) is a directed graph with vertices V and arcs A. n = V is the number of vertices. m = E or m = A is the number of edges/arcs. 3

Shortest Paths Algorithms and Networks DEFINITIONS AND APPLICATIONS 4

Shortest path problem Graph G=(V,E), length for each edge e in E, w(e). (Also for directed graphs) Distance from u to v: length of shortest path from u to v. Shortest path problem: find distances or find shortest paths. Versions: All pairs Single pair Single source Single destination Lengths can be All equal (unit lengths) (BFS) Non-negative Negative but no negative cycles Negative with negative cycles (problematic) 5

Notations d w (s,t): distance of s to t: length of shortest path from s to t when using edge length function w d(s,t): the same, but w is clear from context d(s,s) = 0: we always assume there is a path with 0 edges from a vertex to itself. 6

Applications Route planning Subroutine in other graph algorithms Some other examples we will explore further: Allocating inspection effort on a production line. Difference constraints. 7

Application 1: Allocating Inspection Efforts on a Production Line Production line: ordered sequence of n production stages Each stage can make an item defect Items are inspected at some stages When should we inspect to minimize total costs? 0 1 2 3 8

Solve By Modelling As a Shortest Paths Problem Production line: ordered sequence of n production stages. Items are produced in batches of B > 0 items. Probability that stage i produces a defect item is a i. Manufacturing cost per item at stage i: p i. Cost of inspecting at stage j, when last inspection has been done at stage i: f ij per batch, plus g ij per item in the batch 0 1 2 3 w( i, j) = f ij + B( i) g ij + B( i) j k = i+ 1 Where B(i) denotes the expected number of non-defective items after stage i p k B( i) = B i k = 1 (1 a k ) 9

Idea behind model w(i,j) is the cost of production and inspection from stage i to stage j, assuming we inspect at stage i, and then again at stage j. Find the shortest path from 0 to n. 10

Application 2: Difference Constraints Tasks with precedence constraints and running length. Each task i has: Time to complete b i > 0 Some tasks can be started after other tasks have been completed: Constraint: s j + b j s i First task can start at time 0. When can we finish last task? Longest/shortest paths problem on directed acyclic graphs (see next slides)! 11

Model Take vertex for each task. Take special vertex v 0. Vertex v 0 models time 0. Arc (v 0, i) for each task vertex i, with length 0. For each precedence constraint s j + b j s i an arc (j, i) with length b j. Note: we have a Directed Acyclic Graph (DAG). If there is a cycle, then we set is infeasible. 12

Long paths give time lower bounds If there is a path from v 0 to vertex i with length x, then task i cannot start before time x. Proof with induction... Optimal: start each task i at time equal to the length of longest path from v 0 to i. This gives a valid scheme, and it is optimal by the solution. The longest path problem can be solved in O(n+m) time, as we have a directed acyclic graph. Transforming to shortest paths problem: multiply all lengths and times by 1. 13

Shortest Paths Algorithms and Networks REMINDER: ALGORITHMS FOR SHORTEST PATHS 14

Basics of single source algorithms Source vertex s. Each vertex v has variable D[v] Invariant: d(s,v) D[v] for all v Initially: D[s]=0; v s: D[v] = Relaxation/update step over edge (u,v): D[v] = min{ D[v], D[u]+ w(u,v) } 15 To compute a shortest path (not only the length), one could maintain pointers to the `previous vertex on the current shortest path (sometimes NULL): p(v). Initially: p(v) = NULL for each v. Relaxation step becomes: p-values build paths of length D(v). Shortest paths tree! If D[v] > D[u]+ w(u,v) then D[v] = D[u] + w(u,v); p(v) = u; End if;

Dijkstra s Algorithm 1. Initialize 2. Take priority queue Q, initially containing all vertices 3. While Q is not empty, Select vertex v from Q of minimum value D[v] Relax across all outgoing edges from v Note: each relaxation can cause a change of a D-value and thus a change in the priority queue. This happens at most E times. 16

On Dijkstra s Algorithm Assumes all lengths are non-negative Correctness proof (done in `Algoritmiek ) Running time depends on selection algorithm for vertex v, that it, the implementation of the priority queue: O(n 2 ): array (select v in O(n) time) O((m + n) log n): red-black trees, heaps O(m + n log n): Fibonacci heaps 17

Negative lengths What if w(u,v) < 0? What if there are negative cycles reachable from s? No shortest paths! Bellman-Ford algorithm: For instances without negative cycles. In O(nm) time: single source shortest path problem when there are no negative cycles reachable from s. Also: detects whether a negative cycle exists. 18

Bellman-Ford Algorithm Clearly: O(nm) time 1. Initialize 2. Repeat V -1 times: For every edge (u,v) in E do: Relax(u,v,w) 3. For every edge (u,v) in E If D[v] > D[u] + w(u,v) then there exists a negative cycle. Invariant: If there is no negative cycle reachable from s, then after i runs of main loop, we have: If there is a shortest path from s to u with at most i edges, then D[u]=d(s,u), for all u. If there is no negative cycle reachable from s, then every vertex has a shortest path with at most n 1 edges. If there is a negative cycle reachable from s, then there will always be an edge with a relaxation/update possible. 19

Finding a negative cycle in a graph Reachable from s: Apply Bellman-Ford, and look back with pointers. Or: add a vertex s with edges to each vertex in G. s G 20

All Pairs Shortest Paths: Floyd-Warshall Dynamic programming: O(n 3 ) (Floyd-Warshall, 1962) 1. Initialise d(u,v) = w(u,v) for all (u, v) in E d(u,v) = otherwise 2. For all u in V - For all v in V - For all x in V - d(v,x) = min{ d(v,u) + d(u,x), d(v,x) } 21

All Pairs Shortest Paths: Johnson s Algorithm Johnson: improvement for sparse graphs with reweighting technique: O(n 2 log n + nm) time. Works if no negative cycles. Observation: if all weights are non-negative we can run Dijkstra with each vertex as starting vertex. This gives O(n 2 log n + nm) time using a Fibonacci heap. What if we have negative lengths: reweighting 22

Reweighting with a potential function Let h: V R be any function to the reals. Write w h (u,v) = w(u,v) + h(u) h(v). Lemmas (for the height/potential function h): Let P be a path from x to y. Then: w h (P) = w(p) + h(x) h(y). d h (x,y) = d(x,y) + h(x) h(y). P is a shortest path from x to y with lengths w, if and only if, it is so with lengths w h. G has a negative-length circuit with lengths w, if and only if, it has a negative-length circuit with lengths w h. 23

What height function h is good? Look for height function h with w h (u,v) 0, for all edges (u,v). If so, we can: Compute w h (u,v) for all edges. Run Dijkstra but now with w h (u,v). Special method to make h with a SSSP problem and Bellman-Ford. 24

Choosing h 1. Add a new vertex s to the graph. 2. Set h(v) = d(s,v) 3. Solving SSSP problem with negative edge lengths; use Bellman-Ford. If negative cycle detected: stop. s 0 Note: for all edges (u,v): w h (u,v) = w(u,v) + h(u) h(v) = w(u,v) + d(s,u) d(s,v) 0 because: d(s,u) + w(u,v) d(s,v) G 25

Johnson s algorithm 1. Build graph G (as shown) 2. Compute with Bellman-Ford d(s,v) for all v 3. Set w h (u,v) = w(u,v) + d G (s,u) d G (s,v) for all (u,v) in A. 4. For all u do: Use Dijkstra s algorithm to compute d h (u,v) for all v. Set d(u,v) = d h (u,v) + d G (s,v) d G (s,u). O(n 2 log n + nm) time 26

Shortest Paths - Algorithms and Networks USING THE NUMBERS 27

Using the numbers Back to the single source shortest paths problem with nonnegative distances Suppose is an upper bound on the maximum distance from s to a vertex v. Let L be the largest length of an edge. Single source shortest path problem is solvable in O(m + ) time. 28

In O(m+ ) time Keep array of doubly linked lists: L[0],, L[ ], Maintain that for v with D[v], v in L[D[v]]. Keep a current minimum µ. Invariant: all L[k] with k < µ are empty Run Dijkstra while: Update D[v] from x to y: take v from L[x] (with pointer), and add it to L[y]: O(1) time each. Extract min: while L[µ] empty, µ ++; then take the first element from list L[µ]. Total time: O(m+ ) 29

Corollary and extension SSSP: in O(m+nL) time. (Take =nl). Gabow (1985): SSSP problem can be solved in O(m log R L) time, where R = max{2, m/n} L : maximum length of edge Gabow s algorithm uses scaling technique! 30

Gabow s Algorithm: Main Idea First, build a scaled instance: For each edge e set w (e) = w(e) / R. Recursively, solve the scaled instance and switch to using Dijkstra using the numbers if weights are small enough. R * d w (s,v) is when we scale back our scaled instance. We want d(s,v). What error did we make while rounding? Another shortest paths instance can be used to compute the error correction terms! 31

Computing the correction terms through another shortest path problem Set for each edge (x,y) in E: Z(x,y) = w(x,y) + R* d w (s,x) - R * d w (s,y) Works like a height function, so the same shortest paths! Height of x is - R * d w (s,x) Z compares the differences in rounding errors from the shortest paths from s to x and y to the weight w(x,y). Claim: For all vertices v in V: d(s,v) = d Z (s,v) + R * d w (s,v) Proof by property of the height function: d(s,v) = d Z (s,v) + h(s) h(v) = d Z (s,v) R*d w (s,s) + R*d w (s,v) (d w (s,s) = 0) = d Z (s,v) + R * d w (s,v) Thus, we can compute distances for w by computing distances for Z and for w 32

Gabow s algorithm 1. If L R, then 2. Else solve the problem using the O(m+nR) algorithm (Base case) For each edge e: set w (e) = w(e) / R. Recursively, compute the distances but with the new length function w. Set for each edge (u,v): Z(u,v) = w(u,v) + R* d w (s,u) R * d w (s,v). Compute d Z (s,v) for all v (how? See next slide!) Compute d(s,v) using: d(s,v) = d Z (s,v) + R * d w (s,v) 33

A property of Z For each edge (u,v) E we have: Z(u,v) = w(u,v) + R* d w (s,u) R * d w (s,v) 0, because w(u,v) R * w (u,v) R * (d w (s,v) d w (s,u)). So, a variant of Dijkstra can be used to compute distances for Z. 34

Computing distances for Z For each vertex v we have: d Z (s,v) nr for all v reachable from s Consider a shortest path P for distance function w from s to v For each of the less than n edges e on P, w(e) R + R*w (e) So, d(s,v) w(p) nr + R* w (P) = nr + R* d w (s,v) Use that d(s,v) = d Z (s,v) + R * d w (s,v) So, we can use the O(m+nR) algorithm (Dijkstra with doubly-linked lists) to compute all values d Z (v). 35

Gabow s algorithm (analysis) Recursive step: costs O( m log R L ) with L = L/R. SSSP for Z costs O(m + nr) = O(m). R = max{2, m/n} Note: log R L (log R L) 1. So, Gabow s algorithm uses O(m log R L) time. 36

Example 191 a 180 s t 223 b 116 37

Shortest Paths - Algorithms and Networks VARIANTS: A* AND BIDIRECTIONAL SEARCH 38

A* Practical heuristic for shortest paths Consider shortest paths in geometric setting (e.g., routeplanning for cars system) Standard Dijkstra would explore many paths that are clearly in the wrong direction Utrecht to Groningen would look at roads near Den Bosch or even Maastricht 39

A heuristic for the distance to the target Suppose we have a heuristic h that approximates the distance to target t. We call h admissible if for each vertex v: h(v) d(v,t) We call h is consistent if for each (u,v) in E: h(u) h(v) + w(u,v) Example: Euclidean distance on the plane of the points Somewhat smaller than the real distance, but looks reasonable 40

A* algorithm as shortest paths with height function Use h as a height function, i.e., set for each edge (u,v): w h (u,v) = w(u,v) h(u) + h(v) Consistent: all new lengths are non-negative Admissible: no fear of stopping too early Note: arcs in wrong direction are less frequently used Faster algorithm; still correct 41

Bidirectional search For a single pair shortest path problem: Start a Dijkstra-search from both sides simultaneously Analysis needed for stopping criterion Faster in practice Combines nicely with A* s t s t 42

Shortest Paths Algorithms and Networks BOTTLENECK SHORTEST PATH 43

Bottleneck shortest path Given: weighted graph G, weight w(e) for each arc, vertices s, t. Problem: find a path from s to t such that the maximum weight of an arc on the path is as small as possible. Or, reverse: such that the minimum weight is as large as possible: maximum capacity path 44

Algorithms On directed graphs: O((m+n) log m), Or: O((m+n) log L) with L the maximum absolute value of the weights. Binary search and DFS. On undirected graphs: O(m+n) with divide and conquer strategy. 45

Bottleneck shortest paths on undirected graphs Find the median weight of all weights of edges, say r. Look to graph G r formed by edges with weight at most r. If s and t in same connected component of G r, then the bottleneck is at most r: now remove all edges with weight more than r, and repeat (recursion). If s and t in different connected components of G r : the bottleneck is larger than r. Now, contract all edges with weight at most r, and recurse. T(m) = O(m) + T(m/2) 46

Shortest Paths Algorithms and Networks CONCLUSION 47

Summary on Shortest Paths We have treated: Some examples of applications Several algorithms for shortest paths Variants of the problem Detection of negative cycles Reweighting technique Scaling technique A*, bidirectional search Bottleneck shortest paths Any questions? Dijkstra / Floyd-Warshall Bellman-Ford Algorithm Johnson s Algorithm Gabow s Algorithm 48