# Antimatroid, The

thoughts on computer science, electronics, mathematics

## Tropical Representation of the All-Pairs Shortest Path Problem

### Motivation

While I was doing my Abstract Algebra research the other month, I came across an interesting way of simplifying the representation of the all-pairs shortest path problem using Tropical Geometry. I thought it was pretty clever, so I thought I’d do a quick write-up.

### Problem Statement

The all-pairs shortest path problem is to identify the minimum path cost, $\Omega(\pi) = \sum_{e \in \pi} \omega(e)$, out of the possible paths $\pi_{i,j} \in \Pi_{i,j}$ between vertices $v_{i}$ and $v_{j}$.

### Proposition

Consider a weighted directed graph (digraph), $G = (V, E, \omega)$, consisting of vertices, $V$, and directed edges (arcs), $E \subseteq V \times V$, and a function, $\omega : E \to \overline{\mathbb{R}}_{+}$, yielding the weight of an edge. Only those weights from the positive affinely extended real numbers, $\overline{\mathbb{R}}_{+} = \mathbb{R}_{+} \cup \lbrace \infty \rbrace$, are allowed per the problem statement. The adjacency matrix representation, $D \in \overline{\mathbb{R}}_{+}^{\lvert V \rvert \times \lvert V \rvert}$, of $G$ is given by the following matrix:

$D_{i, j} = \begin{cases} 0 & i = j \\ \omega((v_{i}, v_{j})) & (v_{i}, v_{j}) \in E \\ \infty & \text{otherwise} \end{cases}$

Now, consider a semi-ring over $x, y \in \overline{\mathbb{R}}_{+}$ whose additive operator, $\oplus \in \overline{\mathbb{R}}_{+} \to \overline{\mathbb{R}}_{+}$, is given by the minimum function, $x \oplus y = \min(x,y)$, and whose multiplicative operator, $\odot \in \overline{\mathbb{R}}_{+} \to \overline{\mathbb{R}}_{+}$, is given by addition, $x \odot y = x + y$. The additive unit is given by infinity, $x \oplus \infty = x$, and the multiplicative unit by zero, $x \odot 0 = x$. This semi-ring is the Tropical Semi-ring $\mathbb{T} = \left ( \overline{\mathbb{R}}_{+}, \oplus, \odot \right )$. (The namesake of tropical is in honor of Brazilian Imre Simon who developed this branch of mathematics.)

Linear algebra constructs can be tropicalized to yield the familiar definitions for matrix addition and multiplication for matricies $A, B \in \overline{\mathbb{R}}_{+}^{n \times m}$ and $C \in \overline{\mathbb{R}}_{+}^{m \times n}$.

$\displaystyle \left (A \oplus B \right )_{i, j} = A_{i,j} \oplus B_{i, j}$

$\displaystyle (A \odot C)_{i,j} = \bigoplus_{k}^{m} A_{i, k} \odot C_{k, j}$

Given the two prior statements, the elegant solution to the all-pairs shortest path problem is given by taking powers of the adjacency matrix: $D_{G}^{\odot \lvert V \rvert - 1}$.

### Proof

To see how this works out, start with $D_{G}$. The matrix represents the minimum cost between any two adjacent vertices. In other words, the minimum cost for all paths containing a single edge. The next inductive step is to consider paths containing at most two adjacent edges. Squaring the adjacency matrix yields all such paths. When the matrix is squared, each edge is concatenated to all other adjacent edges and the minimum weight of the paths is selected. This thought process can iterated as follows:

$\displaystyle D_{G}^{\odot r} = D_{G}^{\odot r - 1} \odot D_{G}$
$\displaystyle D_{i, j}^{\odot r} = \bigoplus_{k}^{m} D_{i, k}^{\odot r - 1} \odot D_{k, j}$
$\displaystyle D_{i, j}^{\odot r} = \min { \lbrace D_{i, k}^{\odot r - 1} + D_{k, j} \rbrace }$ $\forall k \in [1, m]$

The result is a typical Bellman equation. A graph can have at most $\lvert V \rvert - 1$ edges between any two vertices, thus, the solution to the all-pairs shortest path problem is given by $\displaystyle D_{G}^{\odot \lvert V \rvert - 1}$.

### Example

As a worked example, consider the following graph whose set of vertices is given by the set $V = \lbrace a, b, c, d \rbrace$, set of arcs by $E = \lbrace (a,b), (a,c), (a,d), (b,c), (b, d), (c,d) \rbrace$ and weight function, $\omega$, as labeled on the graph.

The all-pairs shortest paths are given by the following calculations where the row and column coordinates correspond to the vertices of $V$. Values in bold denote a change in the shortest path between two vertices.

$D_{G} = \begin{pmatrix}0 & 1 & 8 & 12\\\infty & 0 & 2 & 10\\\infty & \infty & 0 & 3 \\ \infty & \infty & \infty & 0 \end{pmatrix}$ $D_{G}^{\odot 2} = \begin{pmatrix}0 & 1 & \textbf{3} & \textbf{11}\\\infty & 0 & 2 & \textbf{5}\\\infty & \infty & 0 & 3 \\ \infty & \infty & \infty & 0 \end{pmatrix}$ $D_{G}^{\odot 3} = \begin{pmatrix}0 & 1 & 3 & \textbf{6}\\\infty & 0 & 2 & 5\\\infty & \infty & 0 & 3 \\ \infty & \infty & \infty & 0 \end{pmatrix}$

### Computational Complexity

From asymptotic standpoint, tropical matrix multiplication is still on the order of traditional matrix multiplication of $\mathcal{O}(\lvert V \rvert^{3} )$. Computing the all-pairs shortest path problem using this approach is on the order of $\mathcal{O}(\lvert V \rvert^{4})$ since we must perform the tropical matrix multiplication $\lvert V \rvert - 1$ times. Now, This can be improved slightly since tropical matrix multiplication is associative, so we can leverage the repeated squaring approach and reduce the time complexity down to $\mathcal{O}(\lvert V \rvert^{3} \log{\lvert V \rvert})$.

The time complexity can be further reduced to $\mathcal{O}(\lvert V \rvert^{3} )$ using the Floyd-Warshall Algorithm, which is another dynamic programming approach that is similar in form to the tropical representation of the problem. In essence, it follows the same base case, but it’s recurrence statement only considers a range of vertices with respect to the two vertices being considered. A more in depth review of the algorithm can be found in the references.

### References

Floyd-Warshall’s Algorithm.” Algorithmist. Web. 12 Apr. 2012.

Cormen, Thomas H., Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. “25.2 The Floyd-Warshall Algorithm.” Introduction to Algorithms. 2nd ed. Cambridge, MA: MIT, 2001. 629-35. Print.

Diestel, Reinhard. Graph theory. Heidelberg New York: Springer, 2010.

Laface, Antonio. Introduction to Tropical Geometry [pdf]. 29 Nov. 2006. Web. 11 Apr. 2012.

Maclagan, Diane, and Bernd Sturmfels. Introduction to Tropical Geometry [pdf]. 4 Nov. 2009. Web. 9 Apr. 2012.

Mohri, Mehryar. “Semiring Frameworks and Algorithms for Shortest-Distance Problems” [pdf]. Journal of Automata, Languages and Combinatorics 7 (2002) 3: 321-50. 8 Aug. 2002. Web. 31 Mar. 2012.

Written by lewellen

2012-06-01 at 8:00 am