【问题标题】:Stop boost::depth_first_search along a particular depth if certain criteria is met如果满足某些条件,则沿特定深度停止 boost::depth_first_search
【发布时间】:2011-06-10 08:08:28
【问题描述】:
我正在使用BGL 来存储我的 DAG。顶点有状态。鉴于其中一个顶点的状态发生变化,我想更新相关顶点。我可以使用 boost::depth_first_search 和自定义访问者来做到这一点。
现在的逻辑是,如果顶点处于特定状态,我不想更新搜索到的顶点及其依赖项。基本上我想控制 dfs 或 bfs 中的顶点排队。在 BGL 中实现这一目标的最佳方法是什么。
谢谢。
【问题讨论】:
标签:
c++
boost
graph
boost-graph
depth-first-search
【解决方案1】:
似乎 boost::depth_first_search 不支持这一点,但底层的 boost::depth_first_visit 支持,通过它的第二个重载允许“终止函数”(TerminatorFunc)。
因此,您可以复制 boost::depth_first_search 的实现,并将传递给 boost::depth_first_visit 的 detail::nontruth2() 参数替换为您自己的(非平凡的)终止函数。
【解决方案2】:
深度优先搜索没有终止 - 是我见过的图形库中最愚蠢的事情。
可能,这可能是出路:filtered_graph 上的 depth_first_search。您可以以某种方式标记停止顶点,并且在过滤图的过滤边缘函数中只是隐藏事件边缘