Top Banner
All-Pairs Shortest Path Theory and Algorithms Carlos Andres Theran Suarez Program Mathematics and Scientific Computing University of Puerto Rico [email protected] October – 2011 Mayaguez-Puerto Rico Dr Marko Schütz
32
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: My presentation all shortestpath

All-Pairs Shortest PathTheory and Algorithms

Carlos Andres Theran SuarezProgram Mathematics and Scientific Computing

University of Puerto Rico [email protected]

October – 2011Mayaguez-Puerto Rico

Dr Marko Schütz

Page 2: My presentation all shortestpath

Introduction

• In this section we consider de problem of finding shortest path between all pair of vertices in a directed graph .

– With a weight function where

For this goal we are going to use the adjacency-matrix of a graph.

• The input: is a which is adjacency-matrix of a • The output: is the matrix of SPL .

Page 3: My presentation all shortestpath

Recall

• Single-Source shortest paths.• Nonnegative edge weight.– Dijkstra’s algorithm: Running time Array

Running time Binary heap Running time Fibonacci heap

• General.– Bellman-Ford: Running time

• UDG.– Breadth for search: Running time

Page 4: My presentation all shortestpath

What do you think?

Can we solve all-pair shortest paths by running a single source-paths algorithms?

Page 5: My presentation all shortestpath

What do you think?

Can we solve all-pair shortest paths by running a single source-paths algorithms? All-pair shortest paths.• Nonnegative edge weight

Dijkstra’s algorithm: Running time Array

Page 6: My presentation all shortestpath

What do you think?

Can we solve all-pair shortest paths by running a single source-paths algorithms? All-pair shortest paths.• Nonnegative edge weight

Dijkstra’s algorithm: Running time Array Running time Binary heap

Page 7: My presentation all shortestpath

What do you think?

Can we solve all-pair shortest paths by running a single source-paths algorithms? All-pair shortest paths.• Nonnegative edge weight

Dijkstra’s algorithm: Running time Array Running time Binary heap Running time Binary heap

Page 8: My presentation all shortestpath

What do you think?

Can we solve all-pair shortest paths by running a single source-paths algorithms? All-pair shortest paths.• Nonnegative edge weight

Dijkstra’s algorithm: Running time Array Running time Binary heap Running time Binary heap

• General.Bellman-Ford: Running time

Page 9: My presentation all shortestpath

What do you think?

Can we solve all-pair shortest paths by running a single source-paths algorithms? All-pair shortest paths.• Nonnegative edge weight

Dijkstra’s algorithm: Running time Array Running time Binary heap Running time Binary heap

• General.Bellman-Ford: Running time In a dense graph

Page 10: My presentation all shortestpath

Predecessor Matrix

Let the predecessor Matrix, where

Now we define the predecessor subgraph of G for as .

Where

Page 11: My presentation all shortestpath

Predecessor Matrix

Page 12: My presentation all shortestpath

Outline

1. Present a dynamic programming algorithms based on matrix multiplication to solve the problem.

2. Dynamic programming algorithms called Floyd-Warshall algorithms.

3. Unlike the others algorithms, Johnson's algorithms used adjacency-list representation of a graph.

Page 13: My presentation all shortestpath

Shortest path and matrix multiplication

1. The structure of shortest path.Let suppose that we have a shortest path form vertix to vertex , and suppose that have at most edge.

• If then have weight 0.

• If then where has at most edge, by lemma 24.1 is a shortest path from .

So

Page 14: My presentation all shortestpath

2. A recursive solution. Let be the minimum weight of any path from vertex to vertex that contains at most edge.

Shortest path and matrix multiplication (cont.)

Page 15: My presentation all shortestpath

3. Computing shortest-path weight bottom upInput . We compute

Shortest path and matrix multiplication (cont.)

Page 16: My presentation all shortestpath

• Now we can see the relation to the matrix multiplication.

Let the matrix product of For We have .

If we set;

Shortest path and matrix multiplication (cont.)

Page 17: My presentation all shortestpath

Computing the sequence of matrix

Shortest path and matrix multiplication (cont.)

Page 18: My presentation all shortestpath

• Improving the running time.

Our goal, is to compute matrices, let go to see that we can compute with only matrix product.

Shortest path and matrix multiplication (cont.)

Page 19: My presentation all shortestpath

Shortest path and matrix multiplication (cont.)

Page 20: My presentation all shortestpath

Shortest path and matrix multiplication (cont.)

Page 21: My presentation all shortestpath

The algorithm consider a intermediate vertices of a shortest path.1. The structure of a shortest path.Intermediate vertex in a any vertex of other than or, so it can be the set Let assume that the vertex of are and a subset for some .

• If of path , then all the vertices intermediate are in the set . Thus, a shortest path from vertex to vertex with all intermediate vertices in the set is also a shortest path form to with all in the set .

The Floyd-Warshall algorithm

Page 22: My presentation all shortestpath

• If of path , we break down into is a shortest path from to, so of , thus is a shortest path form to with all in the set . Similarly is a shortest path form to with all in the set .

The Floyd-Warshall algorithm (cont)

Page 23: My presentation all shortestpath

3. A recursive solution.

Since for every path, all intermediate vertices are in the set , matriz gives the final answer:

The Floyd-Warshall algorithm (cont)

Page 24: My presentation all shortestpath

• input: A matrix • output: A matrix of shortest path weight.

• =

The Floyd-Warshall algorithm (cont)

Page 25: My presentation all shortestpath

The Floyd-Warshall algorithm (cont)

Page 26: My presentation all shortestpath

4. Constructing a Shortest pathWe compute the predecessor matrix just as the Floyd-warshall algorithm compute the matrices so.

Recursive formulation.

The Floyd-Warshall algorithm (cont)

Page 27: My presentation all shortestpath

• It is asymtoticaly better than repeated squaring of matrices or the Floyd-Warshall algoritm.

• It use a subroutine both Dijkstra’s algorithm and Bellman-Ford algorithm.

• Johnson's algorithm use the technique of reweighting.

Johnson's algorithm for sparse graphs.

Page 28: My presentation all shortestpath

Reweighting If has a negative weight edge but no negative weight cycle, we compute a new set of nonnegative edge weight that allow as to use Dijkstra’s algorithm.

The new set of edge must satisfy two condition.1. is a shortest path form is a shortest path

form .2. For all edges , the new weight is nonnegative.

Johnson's algorithm for sparse graphs (cont.).

Page 29: My presentation all shortestpath

• Lemma Give a weighted, directed graph with weight funtion be any funtion mapping vertices to real numbers. For each edge , define.

Johnson's algorithm for sparse graphs (cont.).

Page 30: My presentation all shortestpath

• Producing no negative weight by reweighting

Johnson's algorithm for sparse graphs (cont.).

Page 31: My presentation all shortestpath

Johnson's algorithm for sparse graphs (cont.).

Page 32: My presentation all shortestpath

Johnson's algorithm for sparse graphs (cont.).