0
我嘗試使用Mathematica的找漢密爾頓週期在下面的圖:哈密爾頓顯示週期使用Mathematica
g = Graph[{1 \[UndirectedEdge] 2, 1 \[UndirectedEdge] 6,
2 \[UndirectedEdge] 4, 1 \[UndirectedEdge] 3,
3 \[UndirectedEdge] 4, 4 \[UndirectedEdge] 5,
5 \[UndirectedEdge] 6, 3 \[UndirectedEdge] 9,
4 \[UndirectedEdge] 7, 7 \[UndirectedEdge] 8,
8 \[UndirectedEdge] 11, 5 \[UndirectedEdge] 8,
5 \[UndirectedEdge] 12, 6 \[UndirectedEdge] 12,
9 \[UndirectedEdge] 10, 10 \[UndirectedEdge] 11,
11 \[UndirectedEdge] 12, 9 \[UndirectedEdge] 15,
15 \[UndirectedEdge] 16, 16 \[UndirectedEdge] 17,
16 \[UndirectedEdge] 19, 19 \[UndirectedEdge] 20,
20 \[UndirectedEdge] 23, 20 \[UndirectedEdge] 17,
17 \[UndirectedEdge] 18, 15 \[UndirectedEdge] 21,
18 \[UndirectedEdge] 24, 21 \[UndirectedEdge] 22,
22 \[UndirectedEdge] 23, 23 \[UndirectedEdge] 24,
3 \[UndirectedEdge] 15, 14 \[UndirectedEdge] 15,
14 \[UndirectedEdge] 12, 22 \[UndirectedEdge] 15,
12 \[UndirectedEdge] 18, 11 \[UndirectedEdge] 13,
13 \[UndirectedEdge] 14, 13 \[UndirectedEdge] 10,
1 \[UndirectedEdge] 10, 12 \[UndirectedEdge] 24},
VertexLabels -> "Name"]
然後
EdgeList[g, 4 \[UndirectedEdge] _]
可見,4與2,3,5連接, 7
但代碼
First[FindHamiltonianCycle[g]]
收益不對勁,即
{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 4, 4 \[UndirectedEdge] 8,
8 \[UndirectedEdge] 9, 9 \[UndirectedEdge] 6, 6 \[UndirectedEdge] 3,
3 \[UndirectedEdge] 11, 11 \[UndirectedEdge] 21,
21 \[UndirectedEdge] 19, 19 \[UndirectedEdge] 15,
15 \[UndirectedEdge] 14, 14 \[UndirectedEdge] 16,
16 \[UndirectedEdge] 17, 17 \[UndirectedEdge] 18,
18 \[UndirectedEdge] 22, 22 \[UndirectedEdge] 20,
20 \[UndirectedEdge] 13, 13 \[UndirectedEdge] 23,
23 \[UndirectedEdge] 24, 24 \[UndirectedEdge] 10,
10 \[UndirectedEdge] 12, 12 \[UndirectedEdge] 7,
7 \[UndirectedEdge] 5, 5 \[UndirectedEdge] 1}
爲什麼數學採取從4邊緣8,因爲它不存在嗎?算法中有錯誤還是我做錯了?
我正在使用Mathematica 8。
謝謝,我會更新Mathematica。 – Listing
剛剛更新了它,現在結果與您獲得的結果相同。再次感謝。 – Listing