2IMA20 Algorithms for Geographic Data Spring 2016 Lecture 11: - - PowerPoint PPT Presentation
2IMA20 Algorithms for Geographic Data Spring 2016 Lecture 11: - - PowerPoint PPT Presentation
2IMA20 Algorithms for Geographic Data Spring 2016 Lecture 11: Route Planning Vehicle navigation systems Main tasks: positioning : locating the vehicle using GPS and/or dead reckoning with distance and heading sensors routing :
Vehicle navigation systems
Main tasks:
positioning: locating the vehicle using GPS and/or
dead reckoning with distance and heading sensors
routing: determining a good route from a source to a
destination
guidance: providing visual and audio feedback on the
route
Positioning
GPS: works well, except in “urban
canyons”
Urban canyons can give gross
errors in position due to reflections from buildings
Urban canyons can give loss of
signal
Especially problematic when
driving out of parking garages
Positioning
Dead reckoning: determine position from last known
position using distance and heading sensors (relative position)
Use map matching: the shape of the route taken and
where it matches on the map, to correct dead reckoning
Guiding
Top view, perspective view, overview Schematic information on exit lanes Spoken directions largely an Human-Computer-Interaction issue Algorithms for automated map construction
Routing
Routing = “shortest” path computation Dijkstra’s algorithm solves the problem, so we can all go home now
(after O(m + n log n) time for routing)?
Can we do better?
Routing – Basic examples
Based on Dijkstra’s shortest path algorithm Many improvements to deal with huge networks Improvements use preprocessing
Routing – Basic examples
Based on Dijkstra’s shortest path algorithm Many improvements to deal with huge networks Improvements use preprocessing
Routing – Basic examples
Bidirectional search (from Bayreuth and from Erlangen)
Based on Dijkstra’s shortest path algorithm Many improvements to deal with huge networks Improvements use preprocessing
Routing – Basic examples
Bidirectional search (from Bayreuth and from Erlangen)
Based on Dijkstra’s shortest path algorithm Many improvements to deal with huge networks Improvements use preprocessing
Routing – Overview of techniques
Goal-directed A*, ALT: A* with landmarks and triangle inequality Arc Flags Separator-based Hierarchical Highway hierarchies Contraction hierarchies Bounded hop Transit node routing For public transit networks: time-expanded vs time-dependent
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6
∞ ∞ ∞ ∞ ∞
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6
∞ ∞ ∞ ∞ ∞
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6
∞ ∞ ∞
5 10
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6
∞ ∞ ∞
5 10
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6
∞ ∞ ∞
5 10
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 14 7 14
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 14 7 14
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 14 7 14
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 13 7 13
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 13 7 13
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 13 7 13
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 9 7 13
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 9 7 13
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 9 7 13
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 9 7 13
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 9 7 13
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 9 7 13
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 9 7 13
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
10 6 9 1 3 2 5 4 9 7 2 2 6 5 8 9 7 13 shortest path tree
Recap: Dijkstra’s algorithm
Dijkstra’s algorithm takes O(m + n log n) time for a graph
with n nodes and m edges
Every node is handled only once Its outgoing edges are considered only then Considering an edge may lower the cost of its destination node In theory: nodes are stored by distance in a Fibonacci heap (it
allows for a very efficient decrease-value operation)
In practice: use binary heap or generalization e.g. 4-heap:
O((m+n) log n) time
Road networks have m = O(n), so it takes O(n log n) time
A* algorithm
A* is a simple variant of Dijkstra's algorithm
Additionally: for each node u, a value h[u] that estimates
dist(u, t), where t is the target
h is often called the heuristic function of A* Difference to Dijkstra: value of a node u in the priority queue
is not dist[u] but
dist[u] + h[u]
therefore, if h[u] = 0 for all u, then A* = Dijkstra Works if h is admissable and monotone ... later slide Best results when h[u] = dist(u, t) for all u then A* settles only the nodes on a shortest path
A* Example
2 2 1 1 2 10 10 1
A* Example
2 2 1 1 2 10 10 1 h=0 h=1 h=3 h=5 h=7 h=7 h=6
A* Example
2 2 1 1 2 10 10 1 h=0 h=1 h=3 h=5 h=7 h=7 h=6 0 +5
A* Example
2 2 1 1 2 10 10 1 h=0 h=1 h=3 h=5 h=7 h=7 h=6 2 +3 1 +6
A* Example
2 2 1 1 2 10 10 1 h=0 h=1 h=3 h=5 h=7 h=7 h=6 2 1 +6
A* Example
2 2 1 1 2 10 10 1 h=0 h=1 h=3 h=5 h=7 h=7 h=6 2 1 +6 4 +1
A* Example
2 2 1 1 2 10 10 1 h=0 h=1 h=3 h=5 h=7 h=7 h=6 2 1 +6 4
A* Example
2 2 1 1 2 10 10 1 h=0 h=1 h=3 h=5 h=10 h=10 h=9 2 1 +6 4 6 +0
A* Example
2 2 1 1 2 10 10 1 h=0 h=1 h=3 h=5 h=7 h=7 h=6 2 1 +6 4 6
A* algorithm — Conditions on h
The heuristic h must be admissable
For each node u it must hold: h(u) ≤ dist(u, t) Informally: the heuristic must never overestimate
The heuristic h must be monotone
For each arc (u,v) it must hold: h(u) ≤ cost(u,v) + h(v) Informally: heuristic must obey the triangle inequality
How do we compute h?
A* algorithm — Two heuristics
Straight-line distance (also: as-the-crow-flies distance)
Take h(u) = eucl(u, t) / vmax
eucl(u,t) is the Euclidean distance from u to t vmax is the maximum speed
Admissible and monotone because of triangle inequality
Landmark heuristic
Informally: for every node u, precompute distances to a set of
pre-selected nodes, called landmarks
How to obtain a heuristic function from that ... next slides
Consider an arbitrary node ℓ and call it a landmark Our SP distance function dist satisfies the triangle inequality:
dist(u, v) ≤ dist(u, w) + dist(w, v) for all nodes u, v, w
Then, in particular, for all landmarks ℓ and all nodes u, v Hence, for a landmark ℓ, a target node t, and any node u
h(u) := max( dist(u,ℓ)–dist(t,ℓ) , dist(ℓ,t)–dist(ℓ,u) ) ≤ dist(u,t)
For undirected graphs, dist(x,y) = dist(y,x) for all x,y and thus:
h(u) := |dist(ℓ,u)–dist(ℓ,t)| ≤ dist(u,t)
When is this a good bound? How many landmarks?
Precomputation? How to select landmarks?
A* with landmarks
dist(u,ℓ) ≤ dist(u,v)+ dist(v,ℓ)
dist(u,ℓ)–dist(v,ℓ) ≤ dist(u,v) dist(ℓ,v) ≤ dist(ℓ,u)+dist(u,v)
dist(ℓ,v)–dist(ℓ,u) ≤ dist(u,v)
Two heuristics
Random selection Not bad, but suboptimal distribution Greedy farthest node selection Start with a random node, then iteratively add more In each
iteration, pick the node u which maximizes
minℓ ϵ L' dist(ℓ, u), where L' = nodes already selected intuitively: u
is "farthest" from all nodes in L‘
How to compute u with minℓ ϵ L' dist(ℓ, u) for given L' ?
Landmark selection
Arc flags — Basic idea 1/2
Precomputation Divide the map into "compact" regions of about equal size For each arc, compute "direction signs" for each region We call these direction signs arc flags
A B C D E F G H
Arc flags — Basic idea 1/2
At query time Determine the region containing the target node In Dijkstra's algorithm, outside of that region, consider only arcs
with direction signs towards that region
H
source
(outside H)
target
(inside H)
Arc flags
How to perform queries? How to precompute efficiently? Properties of good partition? Space usage?
H
source
(outside H)
target
(inside H)
Routing – Overview of techniques
Goal-directed A*, ALT: A* with landmarks and triangle inequality Arc Flags Separator-based Hierarchical Highway hierarchies Contraction hierarchies Bounded hop Transit node routing For public transit networks: time-expanded vs time-dependent
Hierarchical Approaches – Intuition
Basic intuition
"Far away" from the source and target, consider only "important"
roads ... the further away, the more important
Let's look at the shortest path of some random queries on Google
Maps, typically:
close to source and target: mainly white (residential) roads a bit further away: mainly yellow (national) roads even further away: mainly orange (motorway) roads But not always true
Hierarchical Approaches – Heuristic
This intuition leads to the following heuristic
Indeed consider the types / colors from the road, with an order
between them, e.g. white < yellow < orange
Have a radius for each color > white: Run a bi-directional Dijkstra, with the following constraints at distance ≥ ryellow from source and target, consider only roads
- f type ≥ yellow
at distance ≥ rorange from source and target, consider only roads
- f type ≥ orange
Note: this does not necessarily find the shortest path Still, heuristics of this kind were employed in navigation devices for
a long time ... since no better algo's were known
ryellow, rorange
Highway Hierarchies
Compute a level for each arc Along with a radius for each level: r1, r2, r3, ... Similarly as for the heuristic, run bi-directional Dijkstra constraint now: at distance ≥ ri from the source and target,
consider only arcs of level ≥ I
Note: the basic idea is simple, but the (implementation) details are
quite intricate, in particular hard to get the implementation error- free in practice
Contraction Hierarchies (CHs)
Compute a level for each node At query time again do a bidirectional Dijkstra in the Dijkstra from the source consider only arcs u,v where
level(v) > level(u) ... so called upwards graph
in the Dijkstra from the target, consider only arcs v,u with
level(v) > level(u) ... so called downwards graph
Intuitively, this is like a "continuous" version of highway hierarchies
... and significantly easier to implement
CHs – Precomputation
Basic building block of CH precomputation: contracting a node Idea: take out a node, and add all necessary arcs such that all SP
distances in the remaining graphs are preserved
Formally, a node v is contracted as follows Let { u1,...,ul} be the incoming arcs, i.e. (ui, v) ϵ E Let
{ w1,...,wk} be the outgoing arcs, i.e. (v, wj) ϵ E
For each pair { ui, wj} , if (ui, v, wj) is the only shortest path
from ui to wj, add the shortcut arc (ui, wj)
Then remove v and its adjacent arcs from the graph
Node Contraction
Add a shortcut that replaces the original path Remove the original nodes and edges All nodes except u will have a higher order than u
(we contract them in node order) v w u 3 4 7
Witness
witness: path shorter than potential shortcut don‘t need to add shortcut if there is a witness any order works what is a good order for contracting?
v w u 3 4 x y 2 3 2 7 P
Query - Idea
Perform query on graph with
shortcuts added
Points sorted by order of
contraction
Only relax edges to higher
nodes
Forward search from s Backward search from t
s t
Query - Graphs
Graph G = (V, E) All nodes, original edges and shortcuts Upward graph G↑ Downward graph G↓
2 2 2 3 3 5 8 1
Node
- rder
Query - Algorithm
Run Dijkstra in G↑ from s Shortest paths from s to any other node Run Dijkstra in G↓ from t Backwards Shortest paths from any node to t Combine paths from both searches
2
Query - Example
2 2 2 3 3 5 8 s t ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 1 1 6 Shortest Path with distance 2 + 6 = 8
Upward graph G↑ Downward graph G↓
Routing – Overview of techniques
Goal-directed A*, ALT: A* with landmarks and triangle inequality Arc Flags Separator-based Hierarchical Highway hierarchies Contraction hierarchies Bounded hop Transit node routing For public transit networks: time-expanded vs time-dependent
Highways and other major roads; every shortest path in the
- riginal road network
- f at least 60 km will
use a highway or
- ther major road
60 km
Transit-Node Routing
This relatively small set of nodes is called the set of
transit nodes
Furthermore, for every node, there are (typically) only
few nodes that are the first transit nodes encountered when going far enough (access nodes)
For the USA, the road network has 24 million nodes and
58 million edges
Transit-node routing uses 10,000 transit nodes and for
each node there are ~10 access nodes
Transit-Node Routing
Store all distances between two transit nodes in a table For every node, store the distance to its ~10 access
nodes in a table
Use table look-up to determine shortest paths, if the
distance between source and target is large enough
for the source and target, get the access nodes and distances for every pair [access node of source, access node of target],
determine a candidate path length by 3 table look-ups
If the distance is small, just run Dijkstra bidirectional
V : nodes of the input graph T : transit nodes chosen
transit nodes transit nodes nodes of V i access nodes of i
transit node table access node table/list
Transit-Node Routing
Trade-off:
many transit nodes: fast query time, large storage requirements, high preprocessing time few transit nodes: slower query time, smaller storage requirements, lower preprocessing time
Reported (road network USA):
query time: 5 – 63 µs storage: 21 – 244 bytes/node preprocessing: 59 – 1200 minutes
Transit-Node Routing
Need (for preprocessing):
a way to choose transit-nodes a way to determine access nodes a way to compute the transit node table and access node table
Need (at query time):
a way to decide if a query is local ( use Dijkstra)
- r not ( use table look-up)
a way to retrieve the shortest path itself
Choosing transit nodes
Use grid-based
partition and use intersections of the network and the grid
Choosing transit nodes
Use grid-based
partition and use intersections of the network and the grid
Select nodes from
Vinner based on whether they lie
- n some shortest
path from a node in C to Vouter
C inner
- uter