75
Lecture 3 : Shortest Paths Introduction Bellman’s Equation Dijkstra’s Algorithm Bellman Ford’s Method Floyd Warshall’s Method Dreyfus Method

Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Embed Size (px)

Citation preview

Page 1: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Lecture 3:

Shortest Paths • Introduction • Bellman’s Equation • Dijkstra’s Algorithm • Bellman Ford’s Method • Floyd Warshall’s Method • Dreyfus Method

Page 2: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Example • Shortest Path Problem

Page 3: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Shortest Path Problem • In this chapter, we concern exclusively with shortest path

problems in directed networks. • If all arc lengths are positive, then an undirected network

can be converted to a directed one with each arc replaced by a pair of arcs (i, j) and (j, i) with the original length.

• It is entirely feasible to compute shortest paths for undirected networks with positive and negative arc lengths, if such a network contains no cycles of negative length. D. B. Johnson, Algorithms for Shortest Paths, Ph.D.thesis, Cornell Univ., Ithaca, New York, 1973.

Page 4: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Length Matrix

Page 5: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Is the Problem Difficult?

Page 6: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Is This a Real Problem?

Page 7: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Call Routing Problem

Page 8: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Other Applications

Page 9: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Most Reliable Paths

Page 10: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Other Applications

Page 11: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Pert Network

Page 12: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Other Applications

Page 13: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Knapsack Problem

Page 14: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

How to Approach This Problem? • The dominant ideas in the solution of these shortest-path

problems are those of dynamic programming.

• Have you heard of “Bellman’s Equation” before? R. E. Bellman, On a Routing Problem", Quart. Appl. Math, 16 (1958) 87-90. • How about “Principle of Optimality”?

Page 15: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Observations

Page 16: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Observations • There seems to be no really good method for finding the

length of a shortest path from a specific origin to a specific destination without, in effect, finding the lengths of shortest path from the origin to all other nodes.

• Any portion of a shortest path must be of shortest distance – Principle of Optimality!

• This is a necessary condition, but not sufficient.

Page 17: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Saying in A Mathematical Way

Page 18: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Bellman’s Equation • It is a necessary condition.

• It holds under the assumption that “no directed cycle with

non-positive length” - (3.1)(a).

• It applies the “principle of optimality” – (3.1)(b).

• It has n variables and n equations, but in nonlinear relations.

• Can be handled in an iterative fashion.

Page 19: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Questions • When will Bellman's equation become a sufficient

condition for shortest paths?

• (A1) There exists a finite-length path from the origin to each of the other nodes.

• (A2) All directed cycles are strictly positive in length. (No directed cycle with non-positive length.)

• Existence and uniqueness of a solution to Bellman’s

equation?

Page 20: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Main Theorems (Under A1 and A2)

Page 21: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Proof of Existence

Page 22: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Proof of Uniqueness

Page 23: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

How to Solve Bellman’s Equation? • Some simple cases: - Acyclic directed network - Directed network with positive arc lengths

Page 24: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Acyclic Network Case

Page 25: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Acyclic Network Case

Page 26: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Acyclic Network Example

Page 27: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Case with Positive Arc Lengths E. W. Dijkstra, A Note on Two Problems in Connexion with Graphs," Numerische Mathematik, 1 (1950) 269-271.

Page 28: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Dijkstra’s Algorithm

Page 29: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Dijkstra’s Algorithm

Page 30: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Questions • Why is Dijkstra's algorithm valid?

• How efficient is the algorithm?

Page 31: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Complexity Analysis

Page 32: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Alternative Algorithm for Acyclic Network

Page 33: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Alternative Algorithm for Acyclic Network

Page 34: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

No Non-positive Cycle Case • Neither assume that the network is acyclic nor that all arc

lengths are positive.

• Only assume that there are no non-positive cycles.

• Use the concept of successive approximations. - Bellman-Ford Method L. R. Ford, Jr., Network Flow Theory, The Rand Corp., P-923, August 1956.

Page 35: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Bellman Ford Method – Successive Approximation • Define = the length of a shortest path from the origin to j,

subject to the condition that path contains no more than m arcs.

Page 36: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Complexity Analysis

Page 37: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Improvement in Efficiency • If not an order of reduction, how about a factor of

reduction in complexity?

• Yen’s algorithm J. Y. Yen, An Algorithm for Finding Shortest Routes from all Source Nodes to a Given Destination in General Network," Quart. Appl. Math., 27 (1970) 526-530.

Page 38: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Yen’s Algorithm • Observation

Page 39: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Yen’s Algorithm

Page 40: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Complexity Reduction • The work of the computation is reduced by a factor of

approximately two.

• Yen has pointed out that the computation can be reduced even further to approximately

Page 41: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Linear Programming Relaxations • Observations

Page 42: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

LP Problem

Page 43: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

LP Dual Problem

Page 44: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the
Page 45: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Optimality Conditions

Page 46: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the
Page 47: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the
Page 48: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the
Page 49: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

LP Relaxations Procedure

Page 50: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Shortest Paths between All Node Pairs • Instead of computing the shortest paths from an origin to

each of the n - 1 nodes, we seek to compute shortest paths from each of the n nodes to each of the other n - 1 nodes, i.e., n(n - 1) shortest paths in all.

• Assumption: No negative cycle in existence.

• Naïve approach: - apply Bellman-Ford method starting from each node - complexity no more than .

Page 51: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Solution Method

Page 52: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Complexity Analysis

• Can we do better?

Page 53: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Matrix Multiplication Method • An efficient implementation of the solution method by

using matrix multiplication-like mechanism. • Recall the regular matrix multiplication

Page 54: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the
Page 55: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Matrix Multiplication Procedure

Page 56: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Complexity Analysis • Like regular matrix multiplication, each time takes elementary operations. Note that We need

Page 57: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Example of Matrix Multiplication Method

Page 58: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Shortest Paths between All Node Pairs • Can we do better than the Matrix Multiplication method?

• R. W. Floyd, Algorithm 97, Shortest Path, Comm. ACM, 5 (1962) 345. • S. Warshall, A Theorem on Boolean Matrices, J. ACM, 9

(1962) 11-12.

Page 59: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Floyd-Warshall Method

Page 60: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Floyd-Warshall Method

Page 61: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Complexity Analysis

Page 62: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Floyd-Warshall Matrix Computation

Page 63: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Floyd-Warshall Matrix Computation

Page 64: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Example

Page 65: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Beyond the Method

Page 66: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Detection of Negative Cycles

Page 67: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Detection of Negative Cycles

Page 68: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Example

Page 69: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

M Shortest Paths

Page 70: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Dreyfus Method

Page 71: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Dreyfus Method

Page 72: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Question • Is there any implicit functional relation in (14.1)?

Page 73: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Other Shortest Paths of Interests

Page 74: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Other Shortest Paths of Interests

Page 75: Lecture 1: Introduction - ise.ncsu.edu · Lecture 3: Shortest Paths • ... problems in directed networks. ... • There seems to be no really good method for finding the

Other Shortest Paths of Interests