枚举*所有*哈密顿路径
我知道以前有人问过这个问题,但我没有在任何帖子中找到答案。有人可以建议我一个枚举图中所有哈密顿路径的算法吗?
一点背景知识:我正在研究一个问题,其中我必须枚举每个哈密顿路径,进行一些分析并返回结果。为此,我需要能够枚举所有可能的哈密顿路径。
谢谢。
I know this has been asked before, but I did not find its answer in any of the posts. Can someone please suggest me an algorithm which enumerates ALL Hamiltonian paths in a graph?
A little background: I am working on a problem in which I have to enumerate each Hamiltonian path, do some analysis, and return the result. For that, I need to be able to enumerate all the possible hamiltonian paths.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
按照建议使用 BFS/DFS,但不要停留在第一个解决方案上。 BFS/DFS 的主要用途(在本例中)是找到所有解决方案,您需要为其设置一个条件以在第一个解决方案处停止。
Use BFS/DFS as suggested but don't stop at the first solution. BFS/DFS primary use (in this case) will be to find all of the solution, you need to put a condition to it to stop at the first one.
我的java代码:(绝对基于递归方法)
算法:
+从1点开始连接到它可以看到的另一个点(形成路径)。
+删除路径并在最新点递归查找新路径,直到连接图形的所有点。
+如果无法从最新点形成汉密尔顿路径,则删除路径并回溯到初始图
}
My java code: (absolutely based on recursive method)
algorithm:
+Start at 1 point connect to another point it can see(to form a path).
+remove the path and recursively find new path at newest point until connect all points of graph.
+remove the path and backtrack to initial graph if cant form Hamilton path from newest point
}
Python3中的解决方案:
Solution in Python3:
深度优先的详尽搜索将为您提供答案。我刚刚完成了关于此问题的 Java 实现的文章(包括代码):
http://puzzledraccoon.wordpress.com/2012/06/07/how-to-cool-a-data-center/
A depth-first exhaustive search gives you the answer. I just finished a write-up on a Java implementation for this problem (including the code):
http://puzzledraccoon.wordpress.com/2012/06/07/how-to-cool-a-data-center/