提升BGL Dijkstra最短路径

Boost BGL Dijkstra Shortest Paths

本文关键字:最短路径 Dijkstra BGL 提升      更新时间:2023-10-16

我不熟悉提升库,也不想学习。我使用boost图形库来调用dijstra的最短路径函数,以在地图上找到到达目的地的路径。折点是交叉点,边是街段。

我正在以最短的时间找到最短的路径。为此,我将边缘权重定义为时间,时间 = st 段长度 * 其速度/限制。这确实给了我最短的路径(按时间)。然而我还要考虑一个转弯,每个回合的总时间增加 15 秒。我如何检测转弯给定两个街段(边缘),如果秒的 st 名称不等于第一个的 st 名称,则为转弯。

基本上,我想动态分配权重(而不是像我在这里所做的那样在开始时设置它们)。当程序在搜索过程中访问边缘时,我希望它在此阶段检查父项(或此处的前辈)。如何在参数中传入函数或可以做到这一点的东西?

vector<unsigned>  OurGraph::find_awesome_path(unsigned start, unsigned finish)
{
    // start and finish are intersection IDs,
    // Get the corresponding Vertices in the graph. 
    Vertex start_node = vertex_map[start]; 
    Vertex dest_node = vertex_map[finish];   
    std::vector<Vertex> predecessors(boost::num_vertices(my_graph)); // To store parents
    std::vector<float> distances(boost::num_vertices(my_graph)); // To store dijkstra distances
    IndexMap indexMap = boost::get(boost::vertex_index, my_graph);
    PredecessorMap predecessorMap(&predecessors[0], indexMap);
    DistanceMap distanceMap(&distances[0], indexMap);
    boost::dijkstra_shortest_paths(my_graph, start_node, boost::distance_map(distanceMap).predecessor_map(predecessorMap));
vector<Edge> path;
    path = get_edge_path(dest_node, predecessorMap);    // Extracts edges from edge descriptors in predecessor map
                                                    // and piles them in a vector of Edge. 
    return segment_list_from_edges(path);           // Convert edges to street segment IDs and return.
}

其中my_graph图的类型,顶点,边,索引图,前置图距离图的类型定义如下:

typedef boost::property<boost::edge_weight_t, float> WeightProperty;
typedef boost::property<boost::vertex_name_t, unsigned> IntersectionProperty;  
typedef boost::adjacency_list < boost::listS, boost::vecS, boost::directedS,
  IntersectionProperty, WeightProperty > Graph;
typedef boost::graph_traits < Graph >::vertex_descriptor Vertex;
typedef boost::graph_traits < Graph >::edge_descriptor Edge;
typedef boost::property_map < Graph, boost::vertex_index_t >::type IndexMap;
typedef boost::iterator_property_map < Vertex*, IndexMap, Vertex, Vertex& > PredecessorMap;
typedef boost::iterator_property_map < float*, IndexMap, float, float& > DistanceMap;

一种方法是使用差分图。在这种情况下,差分图中的每个顶点将等效于当前图中的边。因此,例如,顶点将封装转弯。然后,您可以将转弯权重添加到涉及街道名称更改的边(或用于确定转弯的任何机制)。