简单的图中循环删除算法
来源:互联网 发布:天正制图软件 编辑:程序博客网 时间:2024/05/22 17:16
原文出处
问题:
My problem should be pretty simple, given a graph (BGL adjacency_list) is there a simple algorithm to remove cycles? My first attempt was to use the DFS visitor to detect an edge that'd close the cycle and then remove it but I was unable to implement it correctly.
我的问题应该很简单,给定一个图(BGL adjacency_list)有一个简单的算法来消除周期?我的第一次尝试是使用DFS来检测边缘,会关闭周期,然后删除它,但我却无法正确实施。
Any suggestions? Code samples would be best.
有什么建议吗?代码示例将是最好的。
回答1:
Boost is great. It has a depth_first_search
method that accepts a visitor.You can see more information about it here.
提升是伟大的。它有一个depth_first_search方法接受一个访客。你可以看到更多关于它的信息。
All you need to do is implement a visitor like this:
你所需要做的就是实现一个这样的访问者:
class CycleTerminator : public boost::dfs_visitor<> { template <class Edge, class Graph> void back_edge(Edge e, Graph& g) { //implement }};
remembering of course that a back edge is an edge that closes a cycle in the graph.
记住,一个后边缘是一个在图中关闭一个周期的边缘。
回答2:
It's a simple DFS, as you said. Each time you come to a node you visited before, there's a cycle. Just remove the last edge.
这是一个简单的DFS,正如你所说的。每次你来到一个你访问过的节点之前,都有一个周期。刚刚删除最后一个边缘。
A pseudocode in no particular language.
在没有特定语言的伪代码。
void walk(current_node, previous_node) if visited[current_node] remove edge between current_node and previous_node return end visited[current_node] = true for (each adjacent node) walk(adjacent_node, current_node) endend
- 简单的图中循环删除算法
- 纠结的循环中删除
- 算法 - n个数字形成的圆圈中循环删除第m个数字(C++)
- for循环中删除精灵的处理
- 循环遍历中删除集合的元素
- 在循环中删除集合的元素
- 循环删除list中元素的方法
- JS中对象的循环删除问题
- 2.一些利用循环的简单算法
- vector中循环删除
- CrackMe3(简单循环算法)
- java简单算法循环
- 双向循环链表删除算法的C++程序实现
- 算法--循环单链表删除数值相同的元素
- 单向循环链表的创建/插入/删除/输出算法
- C语言中简单的循环
- JAVA中循环删除list中元素的方法总结
- JAVA中循环删除list中元素的方法总结
- tensorflow 保存和加载模型 -2
- Python中的 .join()用法
- 开源软件,自由软件,免费软件三者的区别
- 隐藏软键盘出现的error
- 最佳实践:更好的设计你的 REST API
- 简单的图中循环删除算法
- Mac 如何配置使用ADB
- 滑动冲突处理
- retrofit合理的处理response
- 【b601】能量项链
- Java代理模式1 - 静态代理、动态代理
- 更新libcurl后yum命令报错
- oracle_事务
- 嵌入式物联网