Algorithms to find the number of Hamiltonian paths in a graph

大憨熊 提交于 2019-11-29 10:45:23

According to Wolfram Alpha,

... the only known way to determine whether a given general graph has a Hamiltonian path is to undertake an exhaustive search

I believe you would want to start by finding a single hamiltonian path, and then splitting it into two paths, making the split point one that clearly separates the two paths as much as possible. Then you can find the permutations in the subgraphs (and recurse, of course!)

I don't know the exact algorithm, but that sort of divide and conquer method is where I would start.

Gareth McCaughan

Someone asked a question very similar to yours over on Math Overflow at https://mathoverflow.net/questions/36368/efficient-way-to-count-hamiltonian-paths-in-a-grid-graph-for-a-given-pair-of-vert and (1) they didn't get a deluge of "here's how to do it efficiently" responses (which probably means there isn't an easy way), (2) Mathematica apparently takes 5 hours to count the paths between opposite corners on a 7x7 grid, so you may well not be doing anything very wrong, and (3) there are a few interesting pointers among the answers.

You could still use a bidirectional search, just add a constraint to the search so that previously seen nodes will not be candidates for searching.

Another approach you could take which would lend itself to a paralellizable solution is to break the search into smaller searches.

For example, try to solve your original problem by solving:

For each node, n, which is not a start or end node, find all paths from the start to n (set1) and from n to the end (set2).

After you find set1 and set2, you can discard all elements of their cross product which have a common node other than node n.

On a 7x7 array (i.e. a total of 7*7=49 nodes), having either a O(n!) algorithm or a O(2^n*n^2) algorithm will both take way too much time.

Perhaps there is some way speeding this up taking into account the special characteristics of this particular graph (e.g. each node has at most 4 edges), but a fast solution seems improbable (unless someone incidentally finds a polynomial time algorithm for the Hamiltonian Path problem itself).

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