Offering effective directions for pedestrians, cyclists or drivers is much more than simply computing the most direct connection in the road network. The open source routing engine Project OSRM powering our upcoming Directions API implements an enhanced and detailed graph model that captures many features beyond the basic topology. With OSRM, you not only get the shortest or fastest route, but one that takes into account turn restrictions and cost like waiting at traffic lights, braking and accelerating at sharp turns, or steep hills for bicycle riders.

为行人,骑自行车者或司机提供有效的指示不仅仅是计算道路网中最直接的连接。 开放源代码路由引擎项目OSRM为即将推出的Directions API提供动力,实现了增强和详细的图形模型,可捕获基本拓扑之外的许多功能。 使用OSRM,您不仅获得最短或最快的路线,而且考虑到转弯限制和成本,如在交通灯等待,急转弯制动和加速,或骑自行车的人的陡峭山坡。

An OSRM route respecting turn restrictions using the OSRM graph model.(使用OSRM图模型遵守转弯限制的OSRM路线。)

A graph is a mathematical tool for representing entities and the connections between them. In a simple graph model of a road network, the entities are intersections and the roads between them form the connections. Excess edges are added to model the curvature of the road, i.e. its geometry.The so-called weight of an edge denotes the cost to traverse it in the chosen mode of transport, for instance travel time for car routing, distance for walking directions, or a combination of time and energy-consumption for electric vehicles.

图形是用于表示实体及其之间的连接的数学工具。 在道路网络的简单图形模型中,实体是交叉路口,并且它们之间的道路形成连接。 添加过多的边缘以模拟道路的曲率,即其几何形状。边缘的所谓重量表示在所选择的运输模式中穿过它的成本,例如用于汽车路线的行进时间,用于步行方向的距离, 或电动车辆的时间和能量消耗的组合。

One of the basic algorithms for routing is Dijkstra’s Algorithm, which solves the problem of finding a shortest path, i. e. a path of minimum weight. In essence, it works like this: to route from A to B, start from a source A, and in each iteration, find and settle the nearest unsettled intersection.Settling means assigning a definitive distance. And this is the closest intersection to any previously settled ones which is still not settled itself Intersections adjacent to settled ones are assigned a tentative distance that may decrease if a lower distance — a better path — is found during the search. In a sense, the algorithm searches radially around the source until it finds the destination.

路由的基本算法之一是Dijkstra的算法,它解决了找到最短路径的问题,  e。 最小重量的路径。 本质上,它的工作原理是:从A到B,从源A开始,并且在每次迭代中,找到并且确定最近的未决交集。分层意味着分配确定的距离。 并且这是与任何先前确定的交叉的最接近的交叉,其本身仍然没有解决。与确定的交叉相邻的交叉被分配临时距离,如果在搜索期间找到较低距离 - 更好的路径,则该临时距离可以减小。 在某种意义上,算法在源周围径向搜索,直到找到目的地。

This looks like a decent way to find a path from A to B, but at a closer look it has major short-comings. First, it does not account for turn restrictions, a common occurrence in the road network.Even worse, this shortcoming is by design. Let’s look at a real-world example and its graph representation:

这看起来像一个体面的方式找到一条从A到B的路径,但是仔细看看它有重大的缺陷。 首先,它不考虑转弯限制,在道路网络中的常见事件。更糟的是,这个缺点是通过设计。 让我们看看一个真实世界的例子和它的图形表示

intraversible p-loop

A typical routing scenario navigating a turn restriction.(导航转弯限制的典型路线情景。)

Assume we are trying to find a path from a to b. The search settles nodes a and subsequently f. The link to b is not explored as it is forbidden, and the search continues on the loop c, d, e. And then it is stopped, because node f is already settled previously with a lower weight. The bypass road is never found as a viable path. And if you allow the search to revisit the intersection after it is settled, you sacrifice efficiency and therefore practicality.

假设我们试图找到一个从a到b的路径。 搜索确定节点a和随后的f。 到b的链接不被探索,因为它被禁止,并且搜索在循环c,d,e上继续。 然后停止,因为节点f已经预先用较低的权重来建立。 旁路道路从来都不是可行的路径。 如果允许搜索在设置后重新访问十字路口,则会牺牲效率,从而降低实用性。

Our Detailed Model(我们的详细模型)

The takeaway is that the simple model does not guarantee path finding when turn restrictions are involved. To solve this, OSRM transforms the road network graph. Instead of modeling intersections and the roads connecting them, it models roads and turns from one to the other. This is called the edge-expanded model. In the edge-expanded model we think of links between street when it is possible to turn from one street to other. In other words, roads are now our entities of interest and turns are the connections that we would like to model. Take a look at the following illustration of the edge expansion:

可以理解的是,简单模型不保证在转弯限制涉及时的路径查找。 为了解决这个问题,OSRM转换道路网络图。 不是模拟交叉路口和连接它们的道路,而是模拟道路和从一个到另一个的转弯。 这被称为边缘扩展模型。 在边缘扩展模型中,我们认为在街道之间的连接是可能的,从一条街到另一条街。 换句话说,道路现在是我们感兴趣的实体,转弯是我们想要建模的连接。 看看边缘展开的下图

edge-expanded graph

Edge expanded model — OSRM models roads and actually possible turns rather than naively modeling the road network.

边缘扩展模型 - OSRM模拟道路和实际可能的转弯,而不是天真地建模道路网络。

For every edge we add a node representing each direction of travel. The grey edges in the picture now reflect turning from one road to the next. The weight of each (expanded) edge is the cost of its first (original) edge plus the cost of the turn. Now, when going from edge a to b, we simply have to traverse the loop and so find the bypass road.

对于每个边缘,我们添加一个代表每个行进方向的节点。 图片中的灰色边缘现在反映从一条道路转向下一条道路。 每个(扩展)边缘的权重是其第一(原始)边缘的成本加上轮的成本。 现在,当从边缘a到b时,我们只需要遍历循环,从而找到旁路。

 Obviously, we are adding much more detail into graph, which does increase the memory requirements of a factor of 3-4. After careful optimization the data set for planet-wide car routing consumes roughly 32 GB of RAM.

显然,我们在图中添加了更多的细节,这增加了3-4倍的内存需求。 经过仔细优化,用于行星范围汽车路由的数据集消耗大约32 GB的RAM。

The Expressive Power of the Model(模型的表达力)

The detailed edge expanded model is obviously useful for car routing, but is it necessary for bike routes, which have many fewer turn restrictions? It turns out that the model has some features that make it useful for a variety of travel modes. Let’s look at two illustrative examples.

详细的边缘扩展模型显然是有用的汽车路由,但是有必要的自行车路线,有很少的转弯限制? 事实证明,该模型有一些功能,使其有用的各种旅行模式。 让我们看看两个说明性的例子。

First, when traveling on a bike it makes sense to minimize the number of turns on a route. In urban areas with gridded streets there may be several equally long routes, but the best one would prefer long straightaways to stop-and-go turns, especially where a turn would cross traffic. Second, the angle with which you turn from one road to the other is important. The steeper the angle, the more you need to decelerate and accelerate again.

首先,当骑自行车旅行时,最小化路线的匝数是有意义的。 在城市地区,有网格的街道可能有几条相等长的路线,但最好的一个喜欢长直路停车和转弯,特别是在一个转弯交叉的地方。 第二,你从一条道路转到另一条道路的角度很重要。 角度越陡,需要越多的减速和加速。

Second, look at this example of a route optimized for scooters with minimal number of turns and evading streets with an upper speed limit of 40 mph:

其次,看看这个路线的示例,该路线针对具有最小转弯次数和避开街道的踏板车进行优化,限速上限为40 mph

minimized number of turns

Optimized route for scooters through San Francisco avoiding turns and high speed traffic.(滑行车通过旧金山的优化路线,避免转弯和高速交通。)

Turn costs are a factor for scooters, trucks, and bikes as well as cars. By explicitly modeling each turn, OSRM is able to account for the cost associated with each turn. For instance, how hard is the deceleration at a sharp turn, or how long is the average wait at an intersection? Turn angles, stop signs, traffic signals, and other factors are all taken into account.

转弯成本是踏板车,卡车,自行车以及汽车的一个因素。 通过明确建模每个回合,OSRM能够计算与每个回合相关的成本。 例如,在急转弯时的减速有多难,或在十字路口平均等待多长时间? 转角,停止标志,交通信号和其他因素都被考虑在内。

Future Developments(未来发展)

We are gearing up for what’s going to be a set of exciting new and powerful features. One of them is enhanced turn restrictions, like Michigan Lefts that not only forbid traveling over a certain junction, but over multiple ways. See the following example from the OpenStreetMap Wiki.

我们正在努力,将是一个令人兴奋的新的和强大的功能。 其中一个是增强的转弯限制,像密歇根左边,不仅禁止在某个交叉口,但通过多种方式。 从OpenStreetMap Wiki中查看以下示例。

complex turn restriction

Example of a complex intersection not allowing for U-turns.(不允许U形转弯的复杂交叉的示例。)

Finally, we believe that no single routing profile will fit every use case, and that people have diverse and subjective preferences that should be configurable at query time. We are working on delivering highly configurable routing profiles, and our first results indicate that it is possible to cut down preprocessing times and memory requirements even further. Stay tuned!

最后,我们认为没有一个路由配置文件适合每个用例,并且人们有多种和主观的偏好,应该在查询时可配置。 我们正在致力于提供高度可配置的路由配置文件,我们的第一个结果表明,可以进一步缩短预处理时间和内存需求。 敬请关注!