# Transportation Geography and Network Science/Dijkstra's Algorithm
## 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 $G$ defined previously, Dijkstra's Algorithm can be used to calculate the shortest (travel time) path between origin node $r$ and every other node in the network. Let $\Delta$ be the distance matrix of $G$ with $\Delta _{ij}$ representing the length (travel time) of the links from node $i$ to node $j$. If nodes $i$ and $j$ are not connected, the corresponding element in $\Delta$ is a very large number.
Let the set of nodes $N$ be divided into two subsets: $\Omega _{r}$ and $\Gamma _{r}$. $\Omega _{r}$ represents the set of nodes for which the shortest path from $r$ is known, and $\Gamma _{r}$ is the complementary set of $\Omega _{r}$. Let $\Pi _{r}$ represent a vector of permanent labels for nodes in $\Omega _{r}$. The permanent label of a node is the shortest distance from the origin node $r$. Let $\Phi _{r}$ be the set of nodes adjacent to nodes in $\Omega _{r}$ along the shortest path. Let $\Lambda$ be a vector of temporary labels for nodes in $\Gamma _{r}$. The following steps explain the algorithm:
* Initialization: Set $\Omega _{r}={r},\Pi _{r}={0},\Phi _{r}={0}$, and assign a large number to all elements of $\Lambda$.
* Node Exploration: Find all child nodes adjacent to any parent node $j$ in $\Omega _{r}$ that are not already in $\Omega _{r}$ using the distance matrix $\Delta$. Calculate a temporary label for each child node $i$ by summing the permanent label of parent node $j$ from vector $\Pi _{r}$ and the length of the link $i\rightarrow j:\Delta _{ij}$.
* Node Selection: Select the node with the smallest temporary label and add it to the end of the set $\Omega _{r}$, removing it from $\Gamma _{r}$. Add the corresponding parent node $j$ to the end of the set $\Phi _{r}$ and the corresponding temporary label to $\Pi _{r}$. With the updated $\Omega _{r}$, repeat steps 2 and 3 until there are no elements left in $\Gamma _{r}$.
To obtain the length of the shortest path from origin node $r$ to any other node in the network, find the position of the destination node in $\Omega _{r}$ and read the corresponding element in $\Pi _{r}$. To obtain the shortest path itself, find the position of the destination node $s$ in $\Omega _{r}$, read the element in the same position in $\Phi _{r}$, and repeat the process until node $r$ is reached in $\Phi _{r}$ (i.e., trace the shortest path backward until the origin is reached). The links along the shortest path from origin node $r$ to destination node $s$ calculated this way are assigned to a set $K_{rs}$.
The above algorithm is performed for a single origin node $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 $G$.
Further details of the algorithm can be found in.

## References

* ↑ Dijkstra's algorithm http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm