找出图 g 中总长最短的哈密顿路径.
FindHamiltonianPath[g,s,t]
找出从 s 到 t 的总长度最短的哈密顿路径.
FindHamiltonianPath
找出图 g 中总长最短的哈密顿路径.
FindHamiltonianPath[g,s,t]
找出从 s 到 t 的总长度最短的哈密顿路径.
更多信息和选项
- FindHamiltonianPath 也叫哈密顿路径问题.
- 哈密顿路径恰好通过每个节点一次.
- 如果不存在哈密顿路径则 FindHamiltonianPath 返回列表 {}.
范例
打开所有单元 关闭所有单元基本范例 (1)
g = PolyhedronData["Dodecahedron", "Skeleton"];FindHamiltonianPath[g]HighlightGraph[g, PathGraph[%]]g = PolyhedronData["Dodecahedron", "Skeleton"];FindHamiltonianPath[g, 1, 5]HighlightGraph[g, PathGraph[%]]范围 (3)
FindHamiltonianPath 可用于无向图:
FindHamiltonianPath[[image]]FindHamiltonianPath[[image]]FindHamiltonianPath 可用于大规模图:
g = RandomGraph[{1000, 5000}];Timing[FindHamiltonianPath[g]]//Short选项 (1)
DistanceFunction (1)
d = SparseArray[{{1, 2} -> 1, {2, 1} -> 1, {6, 1} -> 1, {6, 2} -> 1, {5, 1} -> 1, {1, 5} -> 1, {2, 6} -> 1, {2, 3} -> 10, {3, 2} -> 10, {3, 5} -> 1, {5, 3} -> 1, {3, 4} -> 1, {4, 3} -> 1, {4, 5} -> 15, {4, 1} -> 1, {5, 4} -> 15, {5, 2} -> 1, {1, 4} -> 1, {2, 5} -> 1, {1, 6} -> 1}, {6, 6}, Infinity];g = [image];path = FindHamiltonianPath[g, DistanceFunction -> (d[[#1, #2]]&)]HighlightGraph[g, PathGraph[path]]应用 (2)
找到使国际象棋中骑士在8×8的棋盘上恰好经过每个方块依次的一系列移动:
g = KnightTourGraph[8, 8];path = FindHamiltonianPath[g]checkerboard = ArrayPlot[Table[Mod[j + i, 2], {i, 8}, {j, 8}], ColorRules -> {1 -> RGBColor[0, .55, .77], 0 -> RGBColor[.67, .9, .99]}, Frame -> False, DataRange -> {{1, 8}, {1, 8}}];Show[{checkerboard, HighlightGraph[g, PathGraph[path], GraphHighlightStyle -> "DehighlightHide", EdgeStyle -> Directive[Thick, Red]]}]europe = CountryData["Europe"];pos = GeoPosition[CountryData[#, "CenterCoordinates"]]& /@ europe;adj = Table[QuantityMagnitude@GeoDistance[i, j], {i, pos}, {j, pos}] /. Quantity[0., _] -> Infinity;g = WeightedAdjacencyGraph[europe, adj];FindHamiltonianPath[g, Entity["Country", "Greece"], Entity["Country", "Germany"]]//ShallowGeoGraphics[{Thick, Red, GeoPath[%]}]属性和关系 (2)
g = [image];FindHamiltonianPath[g]HamiltonianGraphQ[g]g = GraphData["Foster038A"]HamiltonianGraphQ[g]FindHamiltonianPath[g]文本
Wolfram Research (2015),FindHamiltonianPath,Wolfram 语言函数,https://reference.wolfram.com/language/ref/FindHamiltonianPath.html.
CMS
Wolfram 语言. 2015. "FindHamiltonianPath." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/FindHamiltonianPath.html.
APA
Wolfram 语言. (2015). FindHamiltonianPath. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/FindHamiltonianPath.html 年
BibTeX
@misc{reference.wolfram_2026_findhamiltonianpath, author="Wolfram Research", title="{FindHamiltonianPath}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/FindHamiltonianPath.html}", note=[Accessed: 07-October-2026]}
BibLaTeX
@online{reference.wolfram_2026_findhamiltonianpath, organization={Wolfram Research}, title={FindHamiltonianPath}, year={2015}, url={https://reference.wolfram.com/language/ref/FindHamiltonianPath.html}, note=[Accessed: 07-October-2026]}