When dealing with huge global map data, small imperfections like disconnected roads are unavoidable. We’re handling millions of daily queries with Smart Directions on top of OpenStreetMap data. To ensure robust routing, we’re using smart nearest neighbor search to jump gaps in the road network where connections are missing.

Sometimes streets on a parking lot are not properly connected to the rest of the road network. We isolate these quirks by analyzing the sizes of the strongly connected components (SCC) of the road network, a computer science concept that translates in this case to “if you can enter the street, you should be able to leave it.” Here’s an example, marked in purple:

scc

These spots cause problems if, say, a trip’s origin is on an unconnected road and the destination is elsewhere in the network. Routing via the nearest roads alone won’t work. Maybe you search the first 10, which are disconnected, but need the eleventh. Nor do you want to ignore disconnected roads entirely. Think of a small island with missing data for ferry connections. You definitely want the ability to route within the island’s road network.

Instead of arbitrarily increasing a search radius or applying hacky heuristics to find additional roads, we combined our efficient R-tree-based nearest-neighbor search coupled with our SCC analysis. This powerful combination of algorithms and data structures enables us to incrementally search the vicinity for a useful road segment if we determine that the nearest segments are trapped behind disconnections. And if a trip’s origin and destination are on the island with the missing ferry, Smart Directions still routes just fine. Here’s a shot of Smart Directions making correct decisions between disconnected roads and the main network:

scc