此为 Mathematica 7 文档,内容基于更早版本的 Wolfram 语言
查看最新文档(版本11.1)

FindHamiltonianCycle

FindHamiltonianCycle[g]
attempts to find a Hamiltonian cycle.
  • FindHamiltonianCycle[g] returns an empty list if no Hamiltonian cycle is found.
  • FindHamiltonianCycle considers the input graph as undirected.
  • FindHamiltonianCycle uses heuristic algorithms to find a Hamiltonian cycle, therefore there is no guarantee that a Hamiltonian cycle will be found even if one exists.
Needs["GraphUtilities`"]
This defines a small graph and find a Hamiltonian cycle of the graph:
In[2]:=
Click for copyable input
In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=
This plots the graph and highlights the cycle in red:
In[5]:=
Click for copyable input
Out[5]=