範例 共 8 個步驟,在同一個工作階段中依序執行。每一步都在引擎上實際執行過,下方的輸出就是它產生的結果。
africa = CountryData["Africa"];沒有輸出——這個步驟是在為下一步做準備。
borderQ[cont1_, cont2_] :=
MemberQ[CountryData[cont1, "BorderingCountries"], CountryData[cont2]];沒有輸出——這個步驟是在為下一步做準備。
adjm = Table[If[borderQ[u, v] || borderQ[v, u], 1, 0], {u, africa}, {v, africa}];沒有輸出——這個步驟是在為下一步做準備。
coords = Reverse[CountryData[#, "CenterCoordinates"]& /@ africa, 2];沒有輸出——這個步驟是在為下一步做準備。
southgraph = AdjacencyGraph[africa, adjm, VertexCoordinates -> coords, EdgeStyle -> Directive[Thickness[.003], White], VertexStyle -> Directive[EdgeForm[GrayLevel[.8]], GrayLevel[.7]], VertexSize -> .8];沒有輸出——這個步驟是在為下一步做準備。
tour = FindPostmanTour[southgraph];沒有輸出——這個步驟是在為下一步做準備。
path = tour[[1, All, 1]];
vrule = Thread[VertexList[southgraph] -> Range[VertexCount[southgraph]]];
route = GraphEmbedding[southgraph][[Join[path, {path[[1]]}] /. vrule]];沒有輸出——這個步驟是在為下一步做準備。
Show[{Graphics[{LightGray, CountryData[#, "Polygon"] & /@ africa}], HighlightGraph[southgraph, path[[1]], VertexLabels -> "Name"], Graphics[{Arrowheads[Join[{0}, ConstantArray[.018, 45]]], GrayLevel[.3], Arrow[BSplineCurve[route, SplineDegree -> 2]]}]}]-Graphics-所有操作範例 · 函式參考 · 從 MCP 用戶端使用這個