HamiltonianCycles[g, n]
n 個のハミルトン閉路のリストを与える.
HamiltonianCycles[g]
1つのハミルトン閉路のリストを与える.
HamiltonianCycles
HamiltonianCycles[g, n]
n 個のハミルトン閉路のリストを与える.
HamiltonianCycles[g]
1つのハミルトン閉路のリストを与える.
詳細とオプション
- HamiltonianCyclesの機能はWolfram言語の組込み関数FindHamiltonianCycleで利用できるようになった.
- HamiltonianCyclesを使うためには,まずグラフユーティリティパッケージをロードしなくてはならない.それにはNeeds["GraphUtilities`"]を実行する必要がある.
- HamiltonianCycles[g,n]は,ハミルトン閉路が存在しない場合は,空のリストを返す.
- HamiltonianCyclesは入力グラフを無向グラフとみなす.
- このアルゴリズムは複雑なため,大きいグラフのハミルトン閉路をすべて見付けるにはかなりの時間がかかる可能性がある.
例題
すべて開く すべて閉じる例 (2)
Needs["GraphUtilities`"]以下で小さいグラフを定義し,そのグラフのハミルトン閉路を見付ける:
g = {1 -> 3, 1 -> 2, 1 -> 4, 2 -> 3, 2 -> 4};GraphPlot[g, VertexLabeling -> True]HamiltonianCycles[g]HamiltonianCyclesの代わりにFindHamiltonianCycleが使われるようになった:
g = UndirectedGraph[Graph[{1 -> 3, 1 -> 2, 1 -> 4, 2 -> 3, 2 -> 4}]]FindHamiltonianCycle[g][[All, All, 1]]スコープ (1)
Needs["GraphUtilities`"]以下で小さいグラフを定義し,そのグラフのハミルトン閉路を見付ける:
g = {0 -> 1, 2 -> 3, 2 -> 1, 3 -> 0, 4 -> 5, 4 -> 7, 4 -> 3, 5 -> 6, 5 -> 2, 6 -> 7, 6 -> 1, 7 -> 0};GraphPlot[g, VertexLabeling -> True]c = HamiltonianCycles[g]cs = Transpose[{c[[1]], RotateRight[c[[1]]]}];GraphPlot[g, EdgeRenderingFunction -> (If[MemberQ[cs, #2] || MemberQ[cs, Reverse[#2]], {Red, Thickness[.01], Line[#1]}, {Black, Line[#1]}]&), VertexLabeling -> True]HamiltonianCycles[g, All]アプリケーション (1)
グラフ中の可能なハミルトン閉路が南米の隣接する国々で構成されていることが分かる:
Needs["GraphUtilities`"]g = Flatten[Map[(If[MemberQ[CountryData["SouthAmerica"], #[[1]]] && MemberQ[CountryData["SouthAmerica"], #[[2]]], #, {}])&, Flatten[Thread[# -> CountryData[#, "BorderingCountries"]]& /@ CountryData["SouthAmerica"]]]];c = HamiltonianCycles[g, All]これら2つの閉路の最初を示す.2つ目は最初の逆になっているだけである:
cs = Transpose[{c[[2]], RotateRight[c[[2]]]}];GraphPlot[g, EdgeRenderingFunction -> (If[MemberQ[cs, #2] || MemberQ[cs, Reverse[#2]], {Red, Thickness[.01], Line[#1]}, {Black, Line[#1]}]&), VertexLabeling -> True, MultiedgeStyle -> False]特性と関係 (1)
Needs["GraphUtilities`"]g = {1 -> 2, 2 -> 3, 3 -> 4, 4 -> 1, 1 -> 5};Bicomponents[g]HamiltonianCycles[g]g = {1 -> 2, 1 -> 4, 1 -> 5, 2 -> 3, 3 -> 6, 4 -> 6, 5 -> 6};Bicomponents[g]HamiltonianCycles[g]GraphPlot[g, VertexLabeling -> True]テクニカルノート
関連するガイド
-
▪
- グラフユーティリティパッケージ ▪
- グラフとネットワーク ▪
- グラフの可視化 ▪
- グラフ上の計算 ▪
- グラフの構築と表現 ▪
- グラフと行列 ▪
- グラフの特性と測定 ▪
- グラフの操作と変更 ▪
- ランダムグラフ ▪
- ソーシャルネットワーク分析 ▪
- グラフの特性 ▪
- 数学データ形式 ▪
- 離散数学
テキスト
Wolfram Research (2007), HamiltonianCycles, Wolfram言語関数, https://reference.wolfram.com/language/GraphUtilities/ref/HamiltonianCycles.html.
CMS
Wolfram Language. 2007. "HamiltonianCycles." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/GraphUtilities/ref/HamiltonianCycles.html.
APA
Wolfram Language. (2007). HamiltonianCycles. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/GraphUtilities/ref/HamiltonianCycles.html
BibTeX
@misc{reference.wolfram_2026_hamiltoniancycles, author="Wolfram Research", title="{HamiltonianCycles}", year="2007", howpublished="\url{https://reference.wolfram.com/language/GraphUtilities/ref/HamiltonianCycles.html}", note=[Accessed: 07-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_hamiltoniancycles, organization={Wolfram Research}, title={HamiltonianCycles}, year={2007}, url={https://reference.wolfram.com/language/GraphUtilities/ref/HamiltonianCycles.html}, note=[Accessed: 07-September-2026]}