boost-graph - 使用自定义访问者时,如何使用Boost Graph Library停止广度优先搜索?

标签 boost-graph breadth-first-search visitors

假设我找到了符合条件的节点,则需要停止搜索。

最佳答案

解决方案是抛出您已知类型的异常-然后在调用方捕获它。从FAQ:

How do I perform an early exit from an algorithm such as BFS?

Create a visitor that throws an exception when you want to cut off the search, then put your call to breadth_first_search inside of an appropriate try/catch block. This strikes many programmers as a misuse of exceptions, however, much thought was put into the decision to have exceptions has the preferred way to exit early. See boost email discussions for more details.

关于boost-graph - 使用自定义访问者时,如何使用Boost Graph Library停止广度优先搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1500709/

相关文章:

boost - Boost Graph Library 上的最大节点数和边数

c++ - 如何使用 boost::vf2_subgraph_iso 获取边缘映射

在有向图中创建最短路径的数量

unique - 检测到 "unique"匿名用户

c++ - BGL : get vertex descriptor with data

c++ - 在 boost::grid_graph 中将自定义权重 boost 到边缘描述符

c++ - 枚举不是非静态数据成员或类的基类

c++ - 在图上实现 BFS

php - 如何在 php 中制作访客计数器?

javascript - 重定向实时网站访问者而不刷新或单击任何内容?