How do I stop the breadth-first search using Boost Graph Library when using a custom visitor?

纵饮孤独 提交于 2019-12-10 02:34:54

问题


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


回答1:


The solution is to throw an exception of your known type - then catch it on the calling side. From the 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.



来源:https://stackoverflow.com/questions/1500709/how-do-i-stop-the-breadth-first-search-using-boost-graph-library-when-using-a-cu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!