提升BGL Dijkstra最短路径
Boost BGL Dijkstra Shortest Paths
我不熟悉提升库,也不想学习。我使用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;
一种方法是使用差分图。在这种情况下,差分图中的每个顶点将等效于当前图中的边。因此,例如,顶点将封装转弯。然后,您可以将转弯权重添加到涉及街道名称更改的边(或用于确定转弯的任何机制)。
相关文章:
- 内存效率表示最短路径的方法?
- 用于查找网格中最短路径的算法
- 查找最短路径算法
- 使用 Dijkstra 算法跟踪两个节点之间的最短路径
- 使用优先级队列查找所有与 Dijkstra 相同的最短路径
- 使 c++11 Dijkstra 实现返回最短路径
- Dijkstra 最短路径算法性能 std::p riority_queue VS std::set.
- 在 stl 中使用向量和对的最有效实现 Dijkstra 最短路径C++
- 具有恒定权重的 Dijkstra 最短路径算法
- 使用 Dijkstra 算法计算两个节点之间的最短路径
- 最短路径的dijkstra算法的时间复杂度是否取决于所使用的数据结构?
- Boost dijkstra shortest_path-如何获得最短路径而不仅仅是距离
- 提升BGL Dijkstra最短路径
- 使用具有指定最大距离的 Boost Dijkstra 查找最短路径
- Boost:: Dijkstra 最短路径,如何从路径迭代器获取顶点索引
- 使用 Dijkstra 和最小堆 c++ 查找节点之间的最短路径
- Dijkstra最短路径与VertexList = ListS在boost图
- 具有捆绑性质的BGL-Dijkstra最短路径
- 我在 OpenMP 中实现 Dijkstra 最短路径算法时可能存在的范围问题?
- Dijkstra最小步长最短路径