Shortest path problem
In graph theory, the shortest path problem is the problem of finding a path between two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is minimized.
This is analogous to the problem of finding the shortest path between two intersections on a road map: the graph's vertices correspond to intersections and the edges correspond to road segments, each weighted by the length of its road segment.
Contents
Definition
The shortest path problem can be defined for graphs whether undirected, directed, or mixed. It is defined here for undirected graphs; for directed graphs the definition of path requires that consecutive vertices be connected by an appropriate directed edge.
Two vertices are adjacent when they are both incident to a common edge. A path in an undirected graph is a sequence of vertices such that is adjacent to for . Such a path is called a path of length from to . (The are variables; their numbering here relates to their position in the sequence and needs not to relate to any canonical labeling of the vertices.)
Let be the edge incident to both and . Given a real-valued weight function , and an undirected (simple) graph , the shortest path from to is the path (where and ) that over all possible minimizes the sum When each edge in the graph has unit weight or , this is equivalent to finding the path with fewest edges.
The problem is also sometimes called the single-pair shortest path problem, to distinguish it from the following variations:
- The single-source shortest path problem, in which we have to find shortest paths from a source vertex v to all other vertices in the graph.
- The single-destination shortest path problem, in which we have to find shortest paths from all vertices in the directed graph to a single destination vertex v. This can be reduced to the single-source shortest path problem by reversing the arcs in the directed graph.
- The all-pairs shortest path problem, in which we have to find shortest paths between every pair of vertices v, v' in the graph.
These generalizations have significantly more efficient algorithms than the simplistic approach of running a single-pair shortest path algorithm on all relevant pairs of vertices.
Algorithms
The most important algorithms for solving this problem are:
- Dijkstra's algorithm solves the single-source shortest path problem.
- Bellman–Ford algorithm solves the single-source problem if edge weights may be negative.
- A* search algorithm solves for single pair shortest path using heuristics to try to speed up the search.
- Floyd–Warshall algorithm solves all pairs shortest paths.
- Johnson's algorithm solves all pairs shortest paths, and may be faster than Floyd–Warshall on sparse graphs.
- Viterbi algorithm solves the shortest stochastic path problem with an additional probabilistic weight on each node.
Additional algorithms and associated evaluations may be found in Cherkassky et al.^{[1]}
Road networks
A road network can be considered as a graph with positive weights. The nodes represent road junctions and each edge of the graph is associated with a road segment between two junctions. The weight of an edge may correspond to the length of the associated road segment, the time needed to traverse the segment or the cost of traversing the segment. Using directed edges it is also possible to model one-way streets. Such graphs are special in the sense that some edges are more important than others for long distance travel (e.g. highways). This property has been formalized using the notion of highway dimension.^{[2]} There are a great number of algorithms that exploit this property and are therefore able to compute the shortest path a lot quicker than would be possible on general graphs.
All of these algorithms work in two phases. In the first phase, the graph is preprocessed without knowing the source or target node. This phase may take several days for realistic data and some techniques. The second phase is the query phase. In this phase, source and target node are known. The running time of the second phase is generally less than a second. The idea is that the road network is static, so the preprocessing phase can be done once and used for a large number of queries on the same road network.
The algorithm with the fastest known query time is called hub labeling and is able to compute shortest path on the road networks of Europe or the USA in a fraction of a microsecond.^{[3]} Other techniques that have been used are:
- ALT
- Arc Flags
- Contraction hierarchies
- Transit Node Routing
- Reach based Pruning
- Labeling
Single-source shortest paths
Undirected graphs
Weights | Time complexity | Author |
---|---|---|
ℝ_{+} | O(E + V log V) | Template:Harvnb |
ℕ | O(E) | Thorup^{[4]} (requires constant-time multiplication). |
Directed unweighted graphs
Algorithm | Time complexity | Author |
---|---|---|
Breadth-first search | O(E) |
Directed acyclic graphs
Directed graphs with nonnegative weights
The following table is taken from Schrijver (2004).^{[5]} A green background indicates an asymptotically best bound in the table.
Algorithm | Time complexity | Author |
---|---|---|
O(V^{2}EL) | Template:Harvnb | |
Bellman–Ford algorithm | O(VE) | Template:Harvnb, Template:Harvnb |
O(V^{2} log V) | Template:Harvnb, Template:Harvnb, Minty (cf. Template:Harvnb), Template:Harvnb | |
Dijkstra's algorithm with list | O(V^{2}) | Template:Harvnb, Template:Harvnb |
Dijkstra's algorithm with modified binary heap | O((E + V) log V) | |
. . . | . . . | . . . |
Dijkstra's algorithm with Fibonacci heap | O(E + V log V) | Template:Harvnb, Template:Harvnb |
O(E log log L) | Template:Harvnb, Template:Harvnb | |
Gabow's algorithm | O(E log_{E/V} L) | Template:Harvnb, Template:Harvnb |
O(E + V√Template:Overline) | Template:Harvnb |
{{ safesubst:#invoke:Unsubst||$N=Expand list |date=__DATE__ |$B=
}}
Planar directed graphs with nonnegative weights
Directed graphs with arbitrary weights
Algorithm | Time complexity | Author |
---|---|---|
Bellman–Ford algorithm | O(VE) | Template:Harvnb, Template:Harvnb |
{{ safesubst:#invoke:Unsubst||$N=Expand list |date=__DATE__ |$B=
}}
Planar directed graphs with arbitrary weights
All-pairs shortest paths
The all-pairs shortest path problem finds the shortest paths between every pair of vertices Template:Mvar, Template:Mvar in the graph. The all-pairs shortest paths problem for unweighted directed graphs was introduced by Template:Harvtxt, who observed that it could be solved by a linear number of matrix multiplications that takes a total time of O(V^{4}).
Undirected graph
Weights | Time complexity | Algorithm |
---|---|---|
ℝ_{+} | O(V^{3}) | Floyd-Warshall algorithm |
ℝ_{+} | O(EV log α(E,V)) | Pettie-Ramachandran^{[6]} |
ℕ | O(EV) | Thorup^{[4]} (requires constant-time multiplication). |
Directed graph
Weights | Time complexity | Algorithm |
---|---|---|
ℝ (no negative cycles) | O(V^{3}) | Floyd-Warshall algorithm |
ℝ (no negative cycles) | O(EV + V^{2} log V) | Johnson-Dijkstra |
ℝ (no negative cycles) | O(EV + V^{2} log log V) | Johnson-Pettie^{[7]} |
ℕ | O(EV + V^{2} log log V) | Hagerup^{[8]} |
Applications
Shortest path algorithms are applied to automatically find directions between physical locations, such as driving directions on web mapping websites like Mapquest or Google Maps. For this application fast specialized algorithms are available.^{[9]}
If one represents a nondeterministic abstract machine as a graph where vertices describe states and edges describe possible transitions, shortest path algorithms can be used to find an optimal sequence of choices to reach a certain goal state, or to establish lower bounds on the time needed to reach a given state. For example, if vertices represent the states of a puzzle like a Rubik's Cube and each directed edge corresponds to a single move or turn, shortest path algorithms can be used to find a solution that uses the minimum possible number of moves.
In a networking or telecommunications mindset, this shortest path problem is sometimes called the min-delay path problem and usually tied with a widest path problem. For example, the algorithm may seek the shortest (min-delay) widest path, or widest shortest (min-delay) path.
A more lighthearted application is the games of "six degrees of separation" that try to find the shortest path in graphs like movie stars appearing in the same film.
Other applications, often studied in operations research, include plant and facility layout, robotics, transportation, and VLSI design".^{[10]}
Related problems
For shortest path problems in computational geometry, see Euclidean shortest path.
The travelling salesman problem is the problem of finding the shortest path that goes through every vertex exactly once, and returns to the start. Unlike the shortest path problem, which can be solved in polynomial time in graphs without negative cycles, the travelling salesman problem is NP-complete and, as such, is believed not to be efficiently solvable for large sets of data (see P = NP problem). The problem of finding the longest path in a graph is also NP-complete.
The Canadian traveller problem and the stochastic shortest path problem are generalizations where either the graph isn't completely known to the mover, changes over time, or where actions (traversals) are probabilistic.
The shortest multiple disconnected path ^{[11]} is a representation of the primitive path network within the framework of Reptation theory.
The widest path problem seeks a path so that the minimum label of any edge is as large as possible.
Linear programming formulation
There is a natural linear programming formulation for the shortest path problem, given below. It is very simple compared to most other uses of linear programs in discrete optimization, however it illustrates connections to other concepts.
Given a directed graph (V, A) with source node s, target node t, and cost w_{ij} for each edge (i, j) in A, consider the program with variables x_{ij}
The intuition behind this is that is an indicator variable for whether edge (i, j) is part of the shortest path: 1 when it is, and 0 if it is not. We wish to select the set of edges with minimal weight, subject to the constraint that this set forms a path from s to t (represented by the equality constraint: for all vertices except s and t the number of incoming and outcoming edges that are part of the path must be the same (i.e., that it should be a path from s to t).
This LP has the special property that it is integral; more specifically, every basic optimal solution (when one exists) has all variables equal to 0 or 1, and the set of edges whose variables equal 1 form an s-t dipath. See Ahuja et al.^{[12]} for one proof, although the origin of this approach dates back to mid-20th century.
The dual for this linear program is
- maximize y_{t} − y_{s} subject to for all ij, y_{j} − y_{i} ≤ w_{ij}
and feasible duals correspond to the concept of a consistent heuristic for the A* algorithm for shortest paths. For any feasible dual y the reduced costs are nonnegative and A* essentially runs Dijkstra's algorithm on these reduced costs.
General algebraic framework on semirings: the algebraic path problem
Template:Expand section Many problems can be framed as a form of the shortest path for some suitably substituted notions of addition along a path and taking the minimum. The general approach to these is to consider the two operations to be those of a semiring. Semiring multiplication is done along the path, and the addition is between paths. This general framework is known as the algebraic path problem.^{[13]}^{[14]}^{[15]}
Most of the classic shortest-path algorithms (and new ones) can be formulated as solving linear systems over such algebraic structures.^{[16]}
More recently, an even more general framework for solving these (and much less obviously related problems) has been developed under the banner of valuation algebras.^{[17]}
See also
- Pathfinding
- IEEE 802.1aq
- Flow network
- Shortest path tree
- Euclidean shortest path
- Min-plus matrix multiplication
- Bidirectional search, an algorithm that finds the shortest path between two vertices on a directed graph
References
- ↑ {{#invoke:Citation/CS1|citation |CitationClass=journal }}.
- ↑ Abraham, Ittai; Fiat, Amos; Goldberg, Andrew V.; Werneck, Renato F. "Highway Dimension, Shortest Paths, and Provably Efficient Algorithms". ACM-SIAM Symposium on Discrete Algorithms, pages 782-793, 2010.
- ↑ Abraham, Ittai; Delling, Daniel; Goldberg, Andrew V.; Werneck, Renato F. research.microsoft.com/pubs/142356/HL-TR.pdf "A Hub-Based Labeling Algorithm for Shortest Paths on Road Networks". Symposium on Experimental Algorithms, pages 230-241, 2011.
- ↑ ^{4.0} ^{4.1} {{#invoke:Citation/CS1|citation |CitationClass=journal }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }} Here: vol.A, sect.7.5b, p.103
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }} pp.267–276
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }} pp.47–74
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }} pp.61–72
- ↑ {{#invoke:Citation/CS1|citation |CitationClass=journal }}.
- ↑ {{#invoke:Citation/CS1|citation |CitationClass=journal }}
- ↑ {{#invoke:Citation/CS1|citation |CitationClass=journal }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }}
- ↑ Mehryar Mohri, "Semiring frameworks and algorithms for shortest-distance problems", Journal of Automata, Languages and Combinatorics, Volume 7 Issue 3, January 2002, Pages 321 - 350
- ↑ http://www.iam.unibe.ch/~run/talks/2008-06-05-Bern-Jonczy.pdf
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }}
- {{#invoke:Citation/CS1|citation
|CitationClass=journal }}
- Template:Introduction to Algorithms
- {{#invoke:Citation/CS1|citation
|CitationClass=journal }}
- {{#invoke:citation/CS1|citation
|CitationClass=conference }}
- {{#invoke:Citation/CS1|citation
|CitationClass=journal }}
- {{#invoke:citation/CS1|citation
|CitationClass=book }}
- {{#invoke:citation/CS1|citation
|CitationClass=conference }}
- {{#invoke:Citation/CS1|citation
|CitationClass=journal }}
Further reading
- {{#invoke:citation/CS1|citation
|CitationClass=conference }}