Modeling & Storing Spatial Networks
- Modeling spatial networks
- Adjacency matrix
- Dense graphs
- Adjacency list
- Sparse graphs
- Suitable for spatial networks
- Adjacency matrix
- Storing large spatial networks
- Partition adjacency lists to disk block based on proximity
- Create B+-tree index on top of partitions based on node-id
Shortest Path Search
Given 2 nodes s
, t
in graph G(V, E)
, find shortest path from s
to t
.
- Non-negative edge weights
- Variations of Dijkstra's
- Negative edges
- Bellman-Ford
s
,t
on edges- Introduce 2 more nodes
Dijkstra's Algorithm
dijkstra(G, s, t):
# init
for v in G:
spd(s, v) = inf # shortest path distance
path(s, v) = null
v.visited = false
priority_queue q
spd(s, s) = 0
q.add(s)
# progress
while not q.empty():
v = q.top() # smallest spd
q.pop()
v.visited = true
if v == t:
return path(s, t)
else:
for u in v.neighbors:
if spd(s, u) > spd(s, v) + weight(v, u):
spd(s, u) = spd(s, v) + weight(v, u)
path(s, u) += (v, u)
q.add_or_update(u)
Worst case cost: O(|E| + |V| log|V|)
A*-Search
Directing search towards t
. Visit nodes in increasing SPD(s, v) + dist(v, t)
order. dist
should be lower distance bounds.
Bi-Directional Search
Maintain 2 queues for both s
and t
. Terminate when they meat.
Can be combined with A*-search.
Spatial Queries over Spatial Networks
Spatial Selections
Find all objects in spatial relation R
within network distance ε
from location q
.
- Store & index spatial network
- Spatial component (e.g. nodes, edges)
- Graph component (e.g. connectivity)
- Store & index sets of spatial objects
- Given spatial location
p
, use spatial component to find network edge containingp
- Given network edge, use network component to traverse neighboring edges
- Given neighboring edges, use spatial indexes to find objects on them
Method 1: Network Browsing
- Find network edge containing
q
- Use spatial index of network (spatial component) i.e. edge R-tree
- Find all edges (subnetwork) within distance
- Use adjacency index (graph component) of network
- Apply Dijkstra's algorithm
- For all edges, find objects that intersect them (spatial selection)
- Use object R-tree
Method 2: Euclidean Bounds
Assume dist(v, u) <= SPD(v, u)
for any v
, u
.
- Find all objects within distance
- Use object R-tree
- Use e.g. Euclidean distance
- For each object
o
found, computeSPD(q, o)
and see if real distance is within distance- Use network R-tree to find where
o
is - Compute
SPD(q, o)
- Check if
SPD(q, o) <= ε
- Use network R-tree to find where
NN Search
Find the nearest object in spatial relation R
to location q
.
- Network browsing
- Fast if edges densely populated with points of interest
- Euclidean bounds
- Fast if edges sparsely populated with points of interest
Method 1: Network Browsing
- Find network edge containing
q
- Use spatial index of network (spatial component) i.e. edge R-tree
- Retrieve edges in order of their distance to
q
- Use adjacency index (graph component) of network
- Apply Dijkstra's algorithm
- For each edge, find objects that intersect them (spatial selection)
- Use object R-tree
- Keep track of nearest object found so far, terminate network browsing with its SPD
Method 2: Euclidean Bounds
Assume dist(v, u) <= SPD(v, u)
for any v
, u
.
- Find Euclidean NN of
q
in order of their distance toq
- Use object R-tree
- Keep track of
currentNN
&bound = SPD(q, currentNN)
- For each NN
- If
dist(q, v) >= bound
- Terminate, report
currentNN
&bound
- Terminate, report
- If
SPD(q, v) < bound
- Set
currentNN = v
&bound = SPD(q, currentNN)
- Keep iterating
- Set
- If
Spatial Join Queries
Find all pairs (r, s)
in spatial relation R
& S
s.t. SPD(r, s)
is within network distance ε
from location q
.
- Index nested loop of ε-distance selection (Euclidean distance) on each object in
R
for objects inS
- For each pair
(r, s)
, computeSPD(r, s)
and verifySPD(r, s) <= ε
Advanced Indexing Techniques for Spatial Networks
- Problem
- Dijkstra's algorithm & related methods can be very expensive on large graphs
- Solution
- (Partial) materialization of shortest paths in static graphs
Hierarchical Path Materialization
- Partition graph
G
intoG1, G2, G3, ...
based on connectivity & proximity of nodes- Each edge in one
Gi
- Border nodes in more than one
Gi
- Each edge in one
For each
Gi
- Compute & materialize SPs between every pair of nodes
- Compute & materialize SPs between every pair of border nodes
- May hierarchically partition them into another level
Good partitioning if:
- small partitions
- few combinations examined for SP search
Shortest Path Search
- If
s
&t
border- Use matrix
B
- Use matrix
- If one of
s
&t
borderSP(s, t) = min{p(s, u) + p(u, t) | (u in B) ∩ (u in Gt or Gs)}
- If
s
&t
not border- If
s
&t
in sameG
- Use matrix
Mst
- Use matrix
- If not
SP(s, t) = min{p(s, u} + p(u, v) + p(v, t) | u, v, in B, u in Gs, v in Gt}
- If
Compressing Materialized Paths
Distance Matrix with Successors
Space Partitioning
- For each node
s
, index a set of(succ, R)
pairs with spatial indexIs
succ
: successor ofs
R
: continuous region s.t. each nodet
in R hassucc
as the successor ofs
inSP(s, t)
- Compute
SP(s, t)
- Init
SP = s
- Find
(succ, R)
withIs
s.t.t
inR
SP += (s, succ)
- If
succ
ist
, reportSP
- Else,
s = succ
, keep iterating
- Init