简体   繁体   English

Boost中的自定义图形距离dijkstra_shortest_paths

[英]Custom graph distance in Boost dijkstra_shortest_paths

I know other people have asked similar questions but this one is slightly different. 我知道其他人也曾问过类似的问题,但这一问题略有不同。

I need to calculate distance as a combination of weight and number of nodes away from root. 我需要计算重量和距离根节点数的组合。

So if the graph is A-> 20 ft ->B-> 10 ft ->C then normally you would calculate the distance between A->B to be 20 ft and A->C to be 30 feet, but I want to magnify the cost of hopping through another node. 因此,如果图形为A-> 20 ft- > B-> 10 ft- > C,那么通常您会计算A-> B为20 ft和A-> C为30英尺之间的距离,但是我想放大了跳到另一个节点的成本。

So let's say every time you jump through another node, the cost is doubled, so A->B distance is 20 ft and B->C distance is 10 ft, but A->C is 20 ft + 2*10 ft = 40 ft 假设每次您跳到另一个节点时,成本都会翻倍,因此A-> B距离为20英尺, B-> C距离为10英尺,但A-> C为20英尺+ 2 * 10 ft = 40 FT

Is this possible with boost's Dijkstra's shortest path? boost的Dijkstra的最短路径有可能吗?

You can do this with customizing your distance. 您可以通过自定义距离来做到这一点。

For example, you could double the cost of every edge except those originating at "source". 例如,除了起源于“源”的那些边缘之外,您可以将每个边缘的成本加倍。 It can be achieved "on the fly" with a simple inline class which has operator[](edge_descriptor e) const . 可以使用具有operator[](edge_descriptor e) const的简单内联类“即时”实现它。 You then pass this class as a distance map to Dijkstra or another shortest path algorithm. 然后,将该类作为距离图传递给Dijkstra或其他最短路径算法。

For some applications you would like to have a fixed cost at every node (eg "expected weighting time at a stop-light"). 对于某些应用程序,您希望每个节点都有固定的成本(例如“交通信号灯的预期加权时间”)。 Here again, you keep these node weights somewhere. 再次在这里,将这些节点权重保留在某个位置。 Then you define an inline class which in its operator[](edge e) const adds the edge weight and this edge source weight unless the edge starts at the Dijkstra "source". 然后,定义一个内联类,除非该边缘以Dijkstra“源”开头,否则它将在其operator[](edge e) const添加边缘权重和该边缘源权重。 Finally, you pass an object of this class as Dijkstra distance map to your favorite BGL routine. 最后,将此类的对象作为Dijkstra距离图传递给您喜欢的BGL例程。

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

相关问题 用boost :: graph包装我的自定义图并计算dijkstra_shortest_paths - Wrap my custom graph with boost::graph and calculate dijkstra_shortest_paths dijkstra_shortest_paths Boost Graph Lib 1.57.0失败 - dijkstra_shortest_paths Boost Graph Lib 1.57.0 fails 增强图:dijkstra_shortest_paths:无法形成对“ void”的引用 - Boost graph: dijkstra_shortest_paths: cannot form a reference to 'void' boost :: dijkstra_shortest_paths覆盖内部图形权重? - boost::dijkstra_shortest_paths overwriting internal graph weights? 当特定节点对之间存在多条最短路径时,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的dijkstra_shortest_paths中的负边权重检查 - Negative edge weight check in boost's dijkstra_shortest_paths 如何从 GraphML 获取边权重到 boost::dijkstra_shortest_paths? - How do I get edge weights from GraphML into boost::dijkstra_shortest_paths? 我可以在“循环”有向图的 BGL 中使用 dijkstra_shortest_paths - Can I use dijkstra_shortest_paths in BGL on "cyclic" directed graph 在dijkstra_shortest_paths中使用捆绑属性作为权重映射 - Using bundled properties as the weight map in dijkstra_shortest_paths 提升BGL Dijkstra最短路径 - Boost BGL Dijkstra Shortest Paths
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM