简体   繁体   English

深度优先搜索算法

[英]depth-first search algorithm

the depth-first algorithm implemented in the boost library visits each vertex just one time. Boost库中实现的深度优先算法仅访问每个顶点一次。

Is there any work around to deactivate this option. 是否有任何解决方法可以停用此选项。 I want that the vertexes can be visited whenever there is a branch in any vertex. 我希望只要在任何顶点中都有分支,就可以访问这些顶点。

any suggestion... 任何建议...

EDIT: The graph is acyclic. 编辑:该图是非循环的。

want that the vertexes can be visited whenever there is a branch in any vertex. 希望只要顶点中有分支,就可以访问顶点。

What do you propose that an iterator do when it reaches a branch at a vertex? 当迭代器到达顶点的分支时,您建议迭代器做什么?

Depth first search is just one answer this question. 深度优先搜索只是回答这个问题的一个方法。 Here are some others. 是其他一些。

But you have to choose something. 但是你必须选择一些东西。 It's not a matter of turning off DFS. 关闭DFS并不是问题。

I think that is impossible by design. 我认为这是不可能的。 Because if your graph contains cycles (and you have them there, when you say, that the vertex can be visited more than once), the algorithm will end up in endless loop. 因为如果您的图包含循环(并且您在其中有循环,当您说顶点可以被多次访问时),该算法将以无穷循环结束。

If you want to enumerate all paths in an acyclic graph, then I don't think you can easily modify depth-first search to do that. 如果您想枚举非循环图中的所有路径,那么我认为您不能轻松地修改深度优先搜索来做到这一点。 There are algorithms specifically designed for this purpose, in particular: Rubin, F.; 有专门为此目的设计的算法,特别是:Rubin,F .; , "Enumerating all simple paths in a graph," Circuits and Systems, IEEE Transactions on , vol.25, no.8, pp. 641- 642, Aug 1978. ,“枚举图中的所有简单路径”,《电路与系统》,IEEE Transactions,第25卷,第8期,第641-642页,1978年8月。

If you know the Floyd-Warshall algorithm, you can easily modify it to compute a list of paths in each element of the matrix, instead of min distance, which will do the job. 如果您知道Floyd-Warshall算法,则可以轻松地对其进行修改,以计算矩阵每个元素中的路径列表,而不是最小距离,从而完成此工作。 The above article uses some bit operations to make this run a bit faster. 上面的文章使用了一些位操作来使其运行更快。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM