最短路径算法CH

CH的思路:

Contraction hierarchies

预处理生成一个多层的结构,每个点都处在单独的一层。事先对点进行优先级排序(怎么排都行,但是排序的好坏直接影响到预处理的效率以及搜索的效率。举个例子,邻接点个数)

点的优先级(高低)是人为指定的,根据优先级从低到高依次选点进行contraction.什么是contraction呢,假设拿掉这个点,看看会不会影响图中点对之间的shorstest path。因此只需要看看它邻接的级别比它高的点的两两点对之间的shortest path是否经过这个点,如果经过的话,就在这个点对之间加上一条边存储它们的shortest path,这条边叫做shortcut。为什么只需要看级别比它高的点?这与CH在搜索最短路径时的算法有关。CH采用双向Dijkstra,并且搜的时候只能从级别低的往级别高的搜,两边相碰之后,就保存路径。如果某个点A的两个邻接点B,C的级别都比A低,而且BC之间的最短路径经过A的话,是不需要在BC之间加shorcut的,直接通过双向Dijkstra可以搜索出来。


搜索过程:

双向dijkstra,从低往高搜。停止条件:两边的open队列都为空了

搜完之后,需要将shortcut转化成原始边。 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
# RoutingKit [![Build Status](https://travis-ci.org/RoutingKit/RoutingKit.svg?branch=master)](https://travis-ci.org/RoutingKit/RoutingKit) RoutingKit is a C++ library that provides advanced route planning functionality. It was developed at [KIT](https://www.kit.edu) in the [group of Prof. Dorothea Wagner](https://i11www.iti.kit.edu/). The most prominent component is an index-based data structure called (Customizable) Contraction Hierarchy, that allows to answer shortest path queries within milliseconds or even less on data sets of continental size while keeping the arc weights flexible. Such running times cannot be achieved without indices. One of the main design goals of RoutingKit is to make recent research results easily accessible to people developing route planning applications. A key element is an interface that is a good compromise between usability and running time performance. For example the following code snippet is enough to build and query a basic index given an [OSM](https://www.openstreetmap.org) PBF data export. ```cpp #include <routingkit/osm_simple.h> #include <routingkit/contraction_hierarchy.h> #include <routingkit/inverse_vector.h> #include <routingkit/timer.h> #include <routingkit/geo_position_to_node.h> #include <iostream> using namespace RoutingKit; using namespace std; int main(){ // Load a car routing graph from OpenStreetMap-based data auto graph = simple_load_osm_car_routing_graph_from_pbf("file.pbf"); auto tail = invert_inverse_vector(graph.first_out); // Build the shortest path index auto ch = ContractionHierarchy::build( graph.node_count(), tail, graph.head, graph.travel_time ); // Build the index to quickly map latitudes and longitudes GeoPositionToNode map_geo_position(graph.latitude, graph.longitude); // Besides the CH itself we need a query object. ContractionHierarchyQuery ch_query(ch); // Use the query object to answer queries from stdin to stdout float from_latitude, from_longitude, to_latitude, to
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值