使用自定义访问者时,如何使用Boost Graph Library停止广度优先搜索? [英] How do I stop the breadth-first search using Boost Graph Library when using a custom visitor?

查看:148
本文介绍了使用自定义访问者时,如何使用Boost Graph Library停止广度优先搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我找到了符合我条件的节点,我需要停止搜索.

Say I found the node that meets my criteria and I need to stop the search.

推荐答案

解决方案是引发您已知类型的异常-然后在调用方捕获它.从常见问题解答:

The solution is to throw an exception of your known type - then catch it on the calling side. From the FAQ:

如何从BFS之类的算法中提前退出?

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

创建一个访问者,当您想中断搜索时会抛出异常,然后将您的调用放在适当的try/catch块内的广度(breadth_first_search)中.这使许多程序员误认为是对异常的滥用,但是,很多人考虑让异常退出的首选方法是早日退出.有关更多详细信息,请参见增强电子邮件讨论.

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 Library停止广度优先搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆