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

HamiltonianCycles

HamiltonianCycles[g, n]
gives a list of n Hamiltonian cycles.
HamiltonianCycles[g]
gives a list of one Hamiltonian cycle.
  • HamiltonianCycles[g, n] returns an empty list if no Hamiltonian cycle exists.
  • HamiltonianCycles considers the input graph as undirected.
  • The complexity of the algorithm is such that finding all Hamiltonian cycles for a large graph can take an exponential amount of time.
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 plot the graph and highlight the cycle in red:
In[5]:=
Click for copyable input
Out[5]=
This find all Hamiltonian cycles:
In[6]:=
Click for copyable input
Out[6]=