Jump to content

Contraction hierarchies: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
The algorithm: better wording
general editorial tweaks
Line 1: Line 1:
{{Expert-subject}}
{{Expert-subject}}


In applied mathematics, the method of '''contraction hierarchies''' is a technique to simplify [[shortest-path routing]] by first creating [[precomputed]] "contracted" versions of the [[connection graph]]. It can be regarded as a special case of [[highway-node routing]].<ref>{{cite web|url=http://algo2.iti.kit.edu/documents/routeplanning/geisberger_dipl.pdf|title=Contraction Hierarchies: Faster and Simpler Hierarchical Routing in Road Networks|author=Robert Geisberger|publisher=Institut für Theoretische Informatik Universität Karlsruhe|date=1 July 2008|accessdate=2010-12-27}}</ref>
In applied mathematics, the method of '''contraction hierarchies''' is a technique to simplify [[shortest-path routing]] by first creating [[precomputed]] "contracted" versions of the [[connection graph]]. It can be regarded as a special case of [[highway-node routing]].<ref name="geisberger">{{cite thesis|url=http://algo2.iti.kit.edu/documents/routeplanning/geisberger_dipl.pdf|title=Contraction Hierarchies: Faster and Simpler Hierarchical Routing in Road Networks|author=Robert Geisberger|publisher=Institut für Theoretische Informatik Universität Karlsruhe|date=1 July 2008|accessdate=2010-12-27}}</ref>


Contraction hierarchies can be used to generate shortest-path routes much more efficiently than [[Dijkstra's algorithm]] or previous highway-node routing approaches,{{fact|date=December 2010}} and is used in open source software.<ref>{{cite web|url=http://project-osrm.org/|title=OSRM - Open Source Routing Machine}}</ref><ref>{{cite web|url=http://www.opentripplanner.org|title=Wiki - OpenTripPlanner}}</ref><ref>{{cite web|url=http://graphhopper.com|title=Web - GraphHopper}}</ref>
Contraction hierarchies can be used to generate shortest-path routes much more efficiently than [[Dijkstra's algorithm]] or previous highway-node routing approaches,<ref name="geisberger"/> and is used in open source software.<ref>{{cite web|url=http://project-osrm.org/|title=OSRM - Open Source Routing Machine}}</ref><ref>{{cite web|url=http://www.opentripplanner.org|title=Wiki - OpenTripPlanner}}</ref><ref>{{cite web|url=http://graphhopper.com|title=Web - GraphHopper}}</ref>


==The algorithm==
==The algorithm==
''Note: this description is based on tutorial material by Ivan Škugor.<ref>{{cite web |url=http://into-the-zen.blogspot.co.uk/2011/01/contraction-hierarchies-part-1.html |title=Contraction hierarchies |author=Ivan Škugor |date=2012 |accessdate=10 February 2013}} (CC-BY)</ref>''
''Note: this description is based on tutorial material by Ivan Škugor.<ref>{{cite web |url=http://into-the-zen.blogspot.co.uk/2011/01/contraction-hierarchies-part-1.html |title=Contraction hierarchies |author=Ivan Škugor |date=2012 |accessdate=10 February 2013}} (CC-BY)</ref>''


In general, scalable map routing algorithms have two distinct phases: preprocessing of original graph (usually it takes more than a hour to finish) and queries (less than a second).
In general, scalable map [[routing]] algorithms have two distinct phases: preprocessing of the original graph (usually it takes more than a hour to finish) and queries (less than a second). Contraction hierarchy is extreme case of "hierarchy" approach, which generates a node hierarchy in the preprocessing stage. In CH every node in the graph is represented as its own level of hierarchy. This can be achieved in many ways, but one way is obvious and simple. If |N| is number of nodes in the graph, every node is enumerated from 1 to |N|. That way in hierarchy every node is represented as distinct level.


Levels/order of nodes in CH can be arbitrary. The main point is that shorcuts are introduced when necessary. To understand when a shortcut is necessary, one has to understand the searching algorithm. The searching algorithm (bidirectional Dijkstra's algorithm) only relaxes edges that are connected to the nodes that are higher in CH than current node in one direction, and vice versa. That way, the algorithm wouldn't find shortest paths and because of that we need to introduce new edges to the graph that represents existing shortest paths that algorithm doesn't take into consideration. Not all shortest paths needs to be restored as new shortcut edges, it's enough to take in consideration adjacent nodes of some node that are higher in CH (sub-path of some shortest path is shortest path himself).
Contraction hierarchy is extreme case of hierarchy approach. Every node in the graph is represented as its own level of hierarchy. This can be achieved in many ways, but one way is obvious and simple. If |N| is number of nodes in the graph, every node is enumerated from 1 to |N|. That way in hierarchy every node is represented as distinct level.

For the searching algorithm, bidirectional Dijkstra's algorithm is used. It is classical [[Dijkstra's algorithm]] with some modifications. The algorithm searches from starting node in one direction and from ending node in other direction (this is classical bidirectional Dijkstra's algorithm), but it relaxes edges that are directed toward higher hierarchy nodes in one direction (essentially it expands towards higher hierarchy nodes) and edges that are directed toward lower hierarchy nodes in other direction. That way, the searching algorithm wouldn't find all shortest paths, because it doesn't take in consideration shortest paths that aren't directed in a way the algorithm searches. To restore shortest paths that aren't taken into consideration, a new edge is added to the graph. That edges are called shortcut edges and they represents existing shortest paths between two nodes in the graph.

Levels/order of nodes in CH can be arbitrary. The main point is that shorcuts are introduced when necessary. To understand when shortcut is necessary, one has to understand the searching algorithm. Searching algorithm (bidirectional Dijkstra's algorithm) only relaxes edges that are connected to the nodes that are higher in CH than current node in one direction, and vice versa. That way, algorithm wouldn't find shortest paths and because of that we need to introduce new edges to the graph that represents existing shortest paths that algorithm don't takes into consideration. Not all shortest paths needs to be restored as new shortcut edges, it's enough to take in consideration adjacent nodes of some node that are higher in CH (sub-path of some shortest path is shortest path himself).


Algorithmically:
Algorithmically:
Line 21: Line 17:
* For each node, respecting order, get its adjacent nodes of higher order and find if shortest path between each pair of them goes through current node and if it is, add shortcut edge
* For each node, respecting order, get its adjacent nodes of higher order and find if shortest path between each pair of them goes through current node and if it is, add shortcut edge


===Preprocessing===
Let's say that we take in cosideration just 2 adjacent nodes (from, in general, "n" of them):
Let's say that we take in cosideration just 2 adjacent nodes (from, in general, "n" of them):


Line 32: Line 29:


When preprocessing of the original graph is is done, we need to build CH graph which consists of node order and original graph with shortcut edges introduced in preprocessing stage.
When preprocessing of the original graph is is done, we need to build CH graph which consists of node order and original graph with shortcut edges introduced in preprocessing stage.

===Querying===
For the searching algorithm, bidirectional [[Dijkstra's algorithm]] is used. It is classical [[Dijkstra's algorithm]] with some modifications. The algorithm searches from starting node in one direction and from ending node in other direction (this is classical bidirectional Dijkstra's algorithm), but it relaxes edges that are directed toward higher hierarchy nodes in one direction (essentially it expands towards higher hierarchy nodes) and edges that are directed toward lower hierarchy nodes in other direction. That way, the searching algorithm wouldn't find all shortest paths, because it doesn't take in consideration shortest paths that aren't directed in a way the algorithm searches. To restore shortest paths that aren't taken into consideration, a new edge is added to the graph. That edges are called shortcut edges and they represents existing shortest paths between two nodes in the graph.


On CH graph we can make queries to find shortest paths with modified bidirectional Dijkstra's algorithm - algorthm performs forward search from starting node s expanding to the nodes that have higher order and backward search from target node t to the nodes that have lower order. If the shortest path exists, those two searches will meet at some node v. A shortest path from s to t consists from paths from s to v and from v to t.
On CH graph we can make queries to find shortest paths with modified bidirectional Dijkstra's algorithm - algorthm performs forward search from starting node s expanding to the nodes that have higher order and backward search from target node t to the nodes that have lower order. If the shortest path exists, those two searches will meet at some node v. A shortest path from s to t consists from paths from s to v and from v to t.
Line 61: Line 61:
{{algorithm-stub}}
{{algorithm-stub}}


[[Category:Network theory]]
[[Category:Routing algorithms]]
[[Category:Graph algorithms]]
[[Category:Graph algorithms]]

Revision as of 13:46, 12 February 2013

In applied mathematics, the method of contraction hierarchies is a technique to simplify shortest-path routing by first creating precomputed "contracted" versions of the connection graph. It can be regarded as a special case of highway-node routing.[1]

Contraction hierarchies can be used to generate shortest-path routes much more efficiently than Dijkstra's algorithm or previous highway-node routing approaches,[1] and is used in open source software.[2][3][4]

The algorithm

Note: this description is based on tutorial material by Ivan Škugor.[5]

In general, scalable map routing algorithms have two distinct phases: preprocessing of the original graph (usually it takes more than a hour to finish) and queries (less than a second). Contraction hierarchy is extreme case of "hierarchy" approach, which generates a node hierarchy in the preprocessing stage. In CH every node in the graph is represented as its own level of hierarchy. This can be achieved in many ways, but one way is obvious and simple. If |N| is number of nodes in the graph, every node is enumerated from 1 to |N|. That way in hierarchy every node is represented as distinct level.

Levels/order of nodes in CH can be arbitrary. The main point is that shorcuts are introduced when necessary. To understand when a shortcut is necessary, one has to understand the searching algorithm. The searching algorithm (bidirectional Dijkstra's algorithm) only relaxes edges that are connected to the nodes that are higher in CH than current node in one direction, and vice versa. That way, the algorithm wouldn't find shortest paths and because of that we need to introduce new edges to the graph that represents existing shortest paths that algorithm doesn't take into consideration. Not all shortest paths needs to be restored as new shortcut edges, it's enough to take in consideration adjacent nodes of some node that are higher in CH (sub-path of some shortest path is shortest path himself).

Algorithmically:

  • Add order/levels to the graph nodes
  • For each node, respecting order, get its adjacent nodes of higher order and find if shortest path between each pair of them goes through current node and if it is, add shortcut edge

Preprocessing

Let's say that we take in cosideration just 2 adjacent nodes (from, in general, "n" of them):

From this picture, if shortest path from v to w goes through node u that is lower in CH, new egde has to be added the CH graph so that shortest paths that searching algorithm takes in consideration are preserved.

Weight of new egde is equal to path distance from v to w.

When preprocessing of the original graph is is done, we need to build CH graph which consists of node order and original graph with shortcut edges introduced in preprocessing stage.

Querying

For the searching algorithm, bidirectional Dijkstra's algorithm is used. It is classical Dijkstra's algorithm with some modifications. The algorithm searches from starting node in one direction and from ending node in other direction (this is classical bidirectional Dijkstra's algorithm), but it relaxes edges that are directed toward higher hierarchy nodes in one direction (essentially it expands towards higher hierarchy nodes) and edges that are directed toward lower hierarchy nodes in other direction. That way, the searching algorithm wouldn't find all shortest paths, because it doesn't take in consideration shortest paths that aren't directed in a way the algorithm searches. To restore shortest paths that aren't taken into consideration, a new edge is added to the graph. That edges are called shortcut edges and they represents existing shortest paths between two nodes in the graph.

On CH graph we can make queries to find shortest paths with modified bidirectional Dijkstra's algorithm - algorthm performs forward search from starting node s expanding to the nodes that have higher order and backward search from target node t to the nodes that have lower order. If the shortest path exists, those two searches will meet at some node v. A shortest path from s to t consists from paths from s to v and from v to t.

The shortest paths found by this algorithm have particular form:

A path found by a query is the shortest path because of preprocessing stage. In preprocessing stage we transformed graph introducing shortcut edges,which represents the shortest paths that algorithm does not take into consideration.

In order to demonstrate that this algorithm retrieves shortest paths, consider it by contradiction: let's assume (for forward search, identical thing stands for backward search) that there exists a path that is shorter than the one we found with this algorithm:

Let's say that at some point there exists a subpath that is shorter than path. Because algorithm expands towards nodes that have higher order, order of node must be lower than order of and nodes. Because of that fact, in preprocessing stage that path would be represented as shortcut edge with equal length, and therefore no such path that is shorter than the one algorithm found can exists.

References

  1. ^ a b Robert Geisberger (1 July 2008). Contraction Hierarchies: Faster and Simpler Hierarchical Routing in Road Networks (PDF) (Thesis). Institut für Theoretische Informatik Universität Karlsruhe. Retrieved 2010-12-27.
  2. ^ "OSRM - Open Source Routing Machine".
  3. ^ "Wiki - OpenTripPlanner".
  4. ^ "Web - GraphHopper".
  5. ^ Ivan Škugor (2012). "Contraction hierarchies". Retrieved 10 February 2013. (CC-BY)

Further reading