# Transportation Geography and Network Science/Dijkstra's Algorithm

Jump to navigation Jump to search

## Overview

Dijkstra's Algorithm is a widely-used graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge weights, producing a shortest path tree. The algorithm was developed by Edsger W. Dijkstra in 1956 and is applicable to both directed and undirected graphs. It is often used in routing, as well as various applications that require finding the shortest path between nodes in a weighted graph.

## Dijkstra's Algorithm for a Directed Graph

For the directed graph ${\displaystyle G}$ defined previously, Dijkstra's Algorithm can be used to calculate the shortest (travel time) path between origin node ${\displaystyle r}$ and every other node in the network. Let ${\displaystyle \Delta }$ be the distance matrix of ${\displaystyle G}$ with ${\displaystyle \Delta _{ij}}$ representing the length (travel time) of the links from node ${\displaystyle i}$ to node ${\displaystyle j}$. If nodes ${\displaystyle i}$ and ${\displaystyle j}$ are not connected, the corresponding element in ${\displaystyle \Delta }$ is a very large number.

Let the set of nodes ${\displaystyle N}$ be divided into two subsets: ${\displaystyle \Omega _{r}}$ and ${\displaystyle \Gamma _{r}}$. ${\displaystyle \Omega _{r}}$ represents the set of nodes for which the shortest path from ${\displaystyle r}$ is known, and ${\displaystyle \Gamma _{r}}$ is the complementary set of ${\displaystyle \Omega _{r}}$. Let ${\displaystyle \Pi _{r}}$ represent a vector of permanent labels for nodes in ${\displaystyle \Omega _{r}}$. The permanent label of a node is the shortest distance from the origin node ${\displaystyle r}$. Let ${\displaystyle \Phi _{r}}$ be the set of nodes adjacent to nodes in ${\displaystyle \Omega _{r}}$ along the shortest path. Let ${\displaystyle \Lambda }$ be a vector of temporary labels for nodes in ${\displaystyle \Gamma _{r}}$. The following steps explain the algorithm:

• Initialization: Set ${\displaystyle \Omega _{r}={r},\Pi _{r}={0},\Phi _{r}={0}}$, and assign a large number to all elements of ${\displaystyle \Lambda }$.
• Node Exploration: Find all child nodes adjacent to any parent node ${\displaystyle j}$ in ${\displaystyle \Omega _{r}}$ that are not already in ${\displaystyle \Omega _{r}}$ using the distance matrix ${\displaystyle \Delta }$. Calculate a temporary label for each child node ${\displaystyle i}$ by summing the permanent label of parent node ${\displaystyle j}$ from vector ${\displaystyle \Pi _{r}}$ and the length of the link ${\displaystyle i\rightarrow j:\Delta _{ij}}$.
• Node Selection: Select the node with the smallest temporary label and add it to the end of the set ${\displaystyle \Omega _{r}}$, removing it from ${\displaystyle \Gamma _{r}}$. Add the corresponding parent node ${\displaystyle j}$ to the end of the set ${\displaystyle \Phi _{r}}$ and the corresponding temporary label to ${\displaystyle \Pi _{r}}$. With the updated ${\displaystyle \Omega _{r}}$, repeat steps 2 and 3 until there are no elements left in ${\displaystyle \Gamma _{r}}$.

To obtain the length of the shortest path from origin node ${\displaystyle r}$ to any other node in the network, find the position of the destination node in ${\displaystyle \Omega _{r}}$ and read the corresponding element in ${\displaystyle \Pi _{r}}$. To obtain the shortest path itself, find the position of the destination node ${\displaystyle s}$ in ${\displaystyle \Omega _{r}}$, read the element in the same position in ${\displaystyle \Phi _{r}}$, and repeat the process until node ${\displaystyle r}$ is reached in ${\displaystyle \Phi _{r}}$ (i.e., trace the shortest path backward until the origin is reached). The links along the shortest path from origin node ${\displaystyle r}$ to destination node ${\displaystyle s}$ calculated this way are assigned to a set ${\displaystyle K_{rs}}$.

The above algorithm is performed for a single origin node ${\displaystyle r}$, but to obtain the shortest path from every node to every other node for trip distribution and traffic assignment, Dijkstra's Algorithm should be performed for every node in the graph ${\displaystyle G}$.

Further details of the algorithm can be found in [1].