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路線。)
The Simple Model and Path Search(簡單模型和路徑搜索)
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的路徑,但是仔細看看它有重大的缺陷。 首先,它不考慮轉彎限制,在道路網絡中的常見事件。更糟的是,這個缺點是通過設計。 讓我們看看一個真實世界的例子和它的圖形表示
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 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
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中查看以下示例。
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!
最后,我們認為沒有一個路由配置文件適合每個用例,並且人們有多種和主觀的偏好,應該在查詢時可配置。 我們正在致力於提供高度可配置的路由配置文件,我們的第一個結果表明,可以進一步縮短預處理時間和內存需求。 敬請關注!