简体   繁体   English

提升BGL Dijkstra最短路径

[英]Boost BGL Dijkstra Shortest Paths

I'm not familiar with boost libraries and trying to learn. 我不熟悉boost库并试图学习。 I have used boost graphics library to call dijstra's shortest paths function to find a path to destination in a map. 我使用了boost图形库调用dijstra的最短路径函数来查找地图中目的地的路径。 Vertices are intersections and edges are street segments. 顶点是交叉点,边缘是街道段。

I am finding the shortest path by minimum time. 我发现最短时间的最短路径。 For that I have edge weights defined as time, time = st segment length * its speed/limit. 为此,我将边权重定义为时间,时间= st段长度*其速度/限制。 This indeed does give me the shortest path (by time). 这确实给了我最短的路径(按时间)。 However, I'm to also account for a turn and add 15 seconds to total time for each. 但是,我还要考虑转弯并为每个转弯增加15秒。 How I detect a turn is given two street segments (edges), if the st name of second is not equal to st name of first, it's a turn. 我如何检测一个转弯被给出两个街道段(边缘),如果第二个的st名称不等于第一个的st名称,则它是转弯。

Basically, I want to assign weights dynamically (not just setting them in the beginning like I'm doing here). 基本上,我想动态分配权重(不只是在开头设置它们就像我在这里做的那样)。 When the program visits an edge during the search, I'd like it to check the parents (or predecessors here) at this stage. 当程序在搜索期间访问边缘时,我希望在此阶段检查父项(或此处的前辈)。 How do I pass in a function or something in the arguments that can do it? 如何在可以执行此操作的参数中传递函数或其他内容?

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.
}

Where my_graph is a type Graph and Graph , Vertex, Edge, IndexMap, PredecessorMap and DistanceMap are type defined as following: my_graph是一种类型图形图形,其中Vertex,Edge,IndexMap,PredecessorMapDistanceMap的类型定义如下:

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;

One way you can do this is to use a differential graph. 一种方法是使用差分图。 In that case each vertex in the differential graph would be equivalent to an edge in your current graph. 在这种情况下,差分图中的每个顶点都等于当前图中的边。 So a vertex would encapsulate a turn for example. 因此,例如,顶点将封装转弯。 Then you can add the turn weights to the edges which involve a change in street name (or whatever mechanism you use to determine turns.) 然后,您可以将转弯权重添加到边缘,这涉及街道名称的更改(或用于确定转弯的任何机制。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 BGL Dijkstra具有捆绑属性的最短路径 - BGL Dijkstra Shortest Paths with Bundled Properties 我可以在“循环”有向图的 BGL 中使用 dijkstra_shortest_paths - Can I use dijkstra_shortest_paths in BGL on "cyclic" directed graph Boost中的自定义图形距离dijkstra_shortest_paths - Custom graph distance in Boost dijkstra_shortest_paths 增强图:dijkstra_shortest_paths:无法形成对“ void”的引用 - Boost graph: dijkstra_shortest_paths: cannot form a reference to 'void' dijkstra_shortest_paths Boost Graph Lib 1.57.0失败 - dijkstra_shortest_paths Boost Graph Lib 1.57.0 fails boost :: dijkstra_shortest_paths覆盖内部图形权重? - boost::dijkstra_shortest_paths overwriting internal graph weights? boost的dijkstra_shortest_paths中的负边权重检查 - Negative edge weight check in boost's dijkstra_shortest_paths 当特定节点对之间存在多条最短路径时,boost graph dijkstra_shortest_paths 如何选择最短路径? - How does boost graph dijkstra_shortest_paths pick the shortest path when there are multiple shortest paths between a specific pair of nodes? 用boost :: graph包装我的自定义图并计算dijkstra_shortest_paths - Wrap my custom graph with boost::graph and calculate dijkstra_shortest_paths 如何从 GraphML 获取边权重到 boost::dijkstra_shortest_paths? - How do I get edge weights from GraphML into boost::dijkstra_shortest_paths?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM