Given a directed, connected weighted graph , for each edge , a weight is associated with the edge. The all pairs of shortest paths problem (APSP) is to find a shortest path from to for every pair of vertices and in .
The input is an matrix w ij ) .
The algorithm is based on dynamic programming, in which each major loop will invoke an operation that is very similar to matrix multiplication. Following the DP strategy, the structure of this problem is, for any two vertices and ,
A recursive solution for the APSP problem is defined. Let ( k ) be the minimum weight of any path from to that contains at most edges.
D ( k ) , W ) for . We only need to run to because that will give us giving us all the shortest path lengths of at most edges (you only need edges to connect vertices). Since SPECIAL-MATRIX-MULTIPLY is called times, the total running time is n 4 ) .
Read full article from All Pairs Shortest Paths
1 The representation of
|
2 Algorithms for the APSP problem
- Matrix Multiplication / Repeated Squaring
- The Floyd-Warshall Algorithm
- Transitive Closure of a Graph
3 Matrix Multiplication Algorithm
- if , then the shortest path from to is 0.
- otherwise, decompose into , where is a path from to and contains at most edges and it is the shortest path from to .
- If , then
( 0 ) = { 0 if i = j ∞ if i ≠ j - Otherwise, for ,
can be computed from( k ) and the adjacency matrix .( k - 1 ) ( k ) = min { d ij ( k - 1 ) , min 1 ≤ l ≤ n { d il ( k - 1 ) + w lj } } = min 1 ≤ l ≤ n { d il ( k - 1 ) + w lj }
SPECIAL-MATRIX-MULTIPLYThe optimal solution can be computed by calling SPECIAL-MATRIX-MULTIPLY
1 ←
2 ← new matrix
3 for ← to
4 do for ← to
5 do ←
6 for ← to
7 do ←c ij , a ik + b kj )
. /* Here's where this algorithm */
. /* differs from MATRIX-MULTIPLY. */
8 return
Read full article from All Pairs Shortest Paths
No comments:
Post a Comment