The Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation

Similar documents
Shortest path problems

from notes written mostly by Dr. Carla Savage: All Rights Reserved

Algorithms for Data Science

Analysis of Algorithms, I

Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2007 Simonas Šaltenis

MA 252: Data Structures and Algorithms Lecture 36. Partha Sarathi Mandal. Dept. of Mathematics, IIT Guwahati

Lecture 11: Analysis of Algorithms (CS ) 1

COMP 182: Algorithmic Thinking Prim and Dijkstra: Efficiency and Correctness

Single Source Shortest Path (SSSP) Problem

Artificial Intelligence

Single Source Shortest Path

Week 11: Minimum Spanning trees

Shortest Paths. Nishant Mehta Lectures 10 and 11

Solving problems on graph algorithms

Shortest Path Problem

Shortest Paths. Nishant Mehta Lectures 10 and 11

Minimum Spanning Trees

Lecture 18 Solving Shortest Path Problem: Dijkstra s Algorithm. October 23, 2009

Dijkstra s Algorithm. Dijkstra s algorithm is a natural, greedy approach towards

CS420/520 Algorithm Analysis Spring 2009 Lecture 14

Single Source Shortest Path: The Bellman-Ford Algorithm. Slides based on Kevin Wayne / Pearson-Addison Wesley

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

Design and Analysis of Algorithms

22 Elementary Graph Algorithms. There are two standard ways to represent a

Design and Analysis of Algorithms

CSC 8301 Design & Analysis of Algorithms: Warshall s, Floyd s, and Prim s algorithms

Algorithms. All-Pairs Shortest Paths. Dong Kyue Kim Hanyang University

COL 702 : Assignment 1 solutions

Lecture 3: Totally Unimodularity and Network Flows

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Lecture #7. 1 Introduction. 2 Dijkstra s Correctness. COMPSCI 330: Design and Analysis of Algorithms 9/16/2014

Graph Algorithms (part 3 of CSC 282),

Ma/CS 6a Class 27: Shortest Paths

All Shortest Paths. Questions from exercises and exams

Review of course COMP-251B winter 2010

Parallel Graph Algorithms

Shortest Path Algorithms

09 B: Graph Algorithms II

Algorithms and Data Structures

Fundamental Algorithms CSCI-GA /Summer Solution to Homework 8

Introduction to Parallel & Distributed Computing Parallel Graph Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Graphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15

Dijkstra s algorithm for shortest paths when no edges have negative weight.

The Shortest Path Problem

Lecture 6 Basic Graph Algorithms

Mon Tue Wed Thurs Fri

CHAPTER 13 GRAPH ALGORITHMS

Shortest Paths. CSE 373 Data Structures Lecture 21

Graphs II - Shortest paths

Weighted Graph Algorithms Presented by Jason Yuan

Directed Graphs. DSA - lecture 5 - T.U.Cluj-Napoca - M. Joldos 1

Shortest Paths. March 21, CTU in Prague. Z. Hanzálek (CTU) Shortest Paths March 21, / 44

Dynamic Programming: 1D Optimization. Dynamic Programming: 2D Optimization. Fibonacci Sequence. Crazy 8 s. Edit Distance

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

Introduction. I Given a weighted, directed graph G =(V, E) with weight function

Parallel Graph Algorithms

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

2.3 Optimal paths. E. Amaldi Foundations of Operations Research Politecnico di Milano 1

5.4 Shortest Paths. Jacobs University Visualization and Computer Graphics Lab. CH : Algorithms and Data Structures 456

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees

Chapter 25: All-Pairs Shortest-Paths

Outline. (single-source) shortest path. (all-pairs) shortest path. minimum spanning tree. Dijkstra (Section 4.4) Bellman-Ford (Section 4.

Introduction. I Given a weighted, directed graph G =(V, E) with weight function

22 Elementary Graph Algorithms. There are two standard ways to represent a

2.3 Optimal paths. Optimal (shortest or longest) paths have a wide range of applications:

1 Non greedy algorithms (which we should have covered

Graph Algorithms (part 3 of CSC 282),

2. CONNECTIVITY Connectivity

Algorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm. ADS: lects 14 & 15 slide 1

Week 12: Minimum Spanning trees and Shortest Paths

Solution for Homework set 3

CSC 1700 Analysis of Algorithms: Minimum Spanning Tree

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G.

Problem Set 6 Solutions

CS521 \ Notes for the Final Exam

Graph Algorithms shortest paths, minimum spanning trees, etc.

4/8/11. Single-Source Shortest Path. Shortest Paths. Shortest Paths. Chapter 24

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Algorithms on Graphs: Part III. Shortest Path Problems. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar..

These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions.

Chapter 24. Shortest path problems. Chapter 24. Shortest path problems. 24. Various shortest path problems. Chapter 24. Shortest path problems

Title. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20.

1 More on the Bellman-Ford Algorithm

CSE 502 Class 23. Jeremy Buhler Steve Cole. April BFS solves unweighted shortest path problem. Every edge traversed adds one to path length

Dijkstra s Algorithm Last time we saw two methods to solve the all-pairs shortest path problem: Min-plus matrix powering in O(n 3 log n) time and the

CS599: Convex and Combinatorial Optimization Fall 2013 Lecture 14: Combinatorial Problems as Linear Programs I. Instructor: Shaddin Dughmi

Repetition: Primal Dual for Set Cover

Unit-5 Dynamic Programming 2016

Introduction to Algorithms. Lecture 11

Graph Algorithms shortest paths, minimum spanning trees, etc.

1 Dijkstra s Algorithm

Dynamic Programming Shabsi Walfish NYU - Fundamental Algorithms Summer 2006

Chapter 9 Graph Algorithms

CS490 Quiz 1. This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed.

Homework Assignment #3 Graph

TCOM 501: Networking Theory & Fundamentals. Lecture 11 April 16, 2003 Prof. Yannis A. Korilis

Chapter 9 Graph Algorithms

Transcription:

The Shortest Path Problem jla,jc@imm.dtu.dk Department of Management Engineering Technical University of Denmark The Shortest Path Problem Given a directed network G = (V,E,w) for which the underlying undirected graph is connected. Furthermore, a source vertex r is given. Objective: Find for each v V a shortest directed path from r to v (if such one exists). Let n denote the number of nodes and m the number of edges in G. Integer Programming Formulation Suppose r is the source vertex. Look at the number of paths leaving a vertex vs. the number of paths entering a vertex. For r n paths have to leave r. For any other vertex, the number of paths entering the vertex must be exactly larger than the number of paths leaving the vertex. Let x e denote the number of paths using each edge e E. Mathematical Model This gives the following mathematical model: min w e x e e E s.t. x ir x ri = (n ) i V i V x ij x ji = j {,...,n} i V i V x e Z + e E

Feasible potentials Consider an n-vector y = y,...,y n. If y satisfies that y r = 0 and (i,j) E : y i + w ij y j then y is called a feasible potential. Feasible potentials II If P is a path from r to v V, then if y is a feasible potential, w P y v : w P = k i= w e i k i= (y v i y vi ) = y vk y v0 = y v Basic algorithmic idea Start with the potential with y r = 0 and y i =, i V \ {r} Check for each edge if the potential is feasible If YES - Stop - the potentials identify shortest paths If an edge (i, j) violates the feasibility condition, update y j - this is sometimes called correct (i,j) or relax (i,j) Ford s Shortest Path Algorithm y r 0,y i for all other i p r 0,p i Nil for all other i while an edge exists (i, j) E such that y j > y i + w ij do y j y i + w ij p j i 8

Problem with Ford s Algorithm Complexity! Beware of negative length circuits - these may lead to infinite computation. Solution: Use the same sequence for the edges in each iteration. Bellman-Ford s Shortest Path Algorithm 8 9 y r 0;y i for all other i p r 0;p i Nil for all other i k 0 while k < n and (y feasible) do k k + for (i,j) E do /* correct (i,j) */ if y j > y i + w ij then y j y i + w ij p j i 9 0 Complexity of Bellman-Ford s Algorithm A worst-case time complexity analysis leads to the following conclusions: Initialization: O(n). Outer loop: (n ) times. In the loop: each edge is considered one time - O(m). All in all: O(nm). Correctness of Bellman-Ford s Algorithm Proof is based on induction. The induction hypothesis is: After iteration k of the main loop, y i contains the length of any shortest path with at most k edges from to i for any i V. For the base case k = 0 the induction hypothesis is trivially fulfilled. (y r = 0 = shortest path from r to r).

Correctness of Bellman-Ford s Algorithm II For the inductive step, we assume that y vi = shortest path from r to v i after the (i ) st pass. Then (v i,v i ) is relaxed in the i th iteration. So y vi = shortest path from r to v i. If all distances are non-negative, a shortest path containing at most (n ) edges exists for each v V. If negative edge lengths are present, the algorithm still works. If a negative length circuit exists, this can be discovered by an extra iteration in the main loop. If at least on y i changes, there is a negative length circuit. Introduction to Dijkstra s Algorithm If we assume all edge weights are non-negative we can derive a more efficient algorithm. A new algorithm for a general graph could therefore be: Find the most negative edge weight w e and add w e to all edge weights. Now all w f 0 for all f E. Use the Dijkstra algorithm. Does that work???? Dijkstra s Algorithm for Shortest Path Example 8 9 0 S {r}, T p r 0,y r 0 p i Nil,y i for all other i while S do select a i S minimizing y i for {j V : j T (i,j) E} do if y j > y i + w ij then y j y i + w ij, p j i S S {j} S S \ {i}, T T {i}

Complexity of Dijkstras Algorithm The only difference to Prim s algorithm for Minimum Spanning Trees is the update step in the inner loop, and this step takes - like in the MST algorithm - O(). Hence the complexity of the algorithm is O(n ) if a list representation of the y vector is used, and a complexity of O(mlogn) can be obtained if the heap data structure is used for the representation of y vector. Correctness of Dijkstras Algorithm This proof is made by induction: Suppose that before an iteration of the while loop it holds that. for each vertex u T, the shortest path from r to u has been found and is of length y u, and. for each vertex u T, y u is the shortest path from from r to u with all vertices except u belonging to T. This is obviously true initially. 8 Correctness of Dijkstras Algorithm II Let v be the element with least y value picked initially in the inner loop of iteration k. y v is the length of a path Q from r to v passing only through vertices in T. Suppose that this is not the shortest path from r to v - then another path R from r to v is shorter. Correctness of Dijkstras Algorithm III v Q r R u w y w >= y v (= length(q)) length(r) length(q) 9 0

Correctness of Dijkstras Algorithm IV Look at R: R starts in r, which is in T. Since v is not in T, R has an edge from a vertex in P to a vertex not in T. Let (u,w) be the first edge of this type. w is a candidate for vertex choice in the current iteration, where v was picked. Hence y w y v. If all edge lengths are non-negative, the length of the part of R from w to v is non-negative, and hence the total length of R is at least the length of the path Q. Correctness of Dijkstras Algorithm V This is a contradiction hence Q is a shortest path from r to v. Furthermore, the update step in the inner loop ensures that after the current iteration it again holds for u not in P (which is now the old P augmented with v) that y u is the shortest path from from r to u with all vertices except u belonging to P. Floyd-Warshall s all-to-all Algorithm y ij w ij,p ij i for all (i,j) with w ij, p ij 0 otherwise. for k to n do for i to n do for j to n do if i k j k y ij > y ik + y kj then y ij y ik + y kj p ij p kj Complexity of Floyd-Warshall s Algorithm In addition to the initialisation, which takes O(n ), the algorithm has three nested loops each of which is performed n times. The overall complexity is hence O(n ).

Correctness of Floyd-Warshall s Algorithm This proof is made by induction: Suppose that prior to iteration k it holds that for i,j v y ij contains length of the shortest path Q from i to j in G containing only vertices in the vertex set {,...,k }, and that p ij contains the immediate predecesor of j on Q. This is obviously true after the initialisation. Correctness of Floyd-Warshall s Algorithm II In iteration k, the length of Q is compared to the length of a path R composed of two subpaths, R and R. R is a path from i to k path with intermediate vertices only in {,...,k }, and R is a path from k to j path with intermediate vertices only in {,...,k }. The shorter of these two is chosen. Correctness of Floyd-Warshall s Algorithm III R k R p[k,j] i j Q p[i,j] contains only vertices from {,..., k } Correctness of Floyd-Warshall s Algorithm III The shortest path from i to j in G containing only vertices in the vertex set {,...,k} either. does not contain k - and hence is the one found in iteration k, or. contains k - and then can be decomposed into a path from i to k followed by a path from k to j, each of which has been found in iteration k. Hence the update ensures the correctness of the induction hypothesis after iteration k. 8

9