Qurak

Enhanced cycle and tour functionality

Example 8 steps, run in order in one session. Every step was executed against the engine and the output below is what it produced.

Step 1
africa = CountryData["Africa"];

No output - this step sets something up for the next one.

Step 2
borderQ[cont1_, cont2_] :=
  MemberQ[CountryData[cont1, "BorderingCountries"], CountryData[cont2]];

No output - this step sets something up for the next one.

Step 3
adjm = Table[If[borderQ[u, v] || borderQ[v, u], 1, 0], {u, africa}, {v, africa}];

No output - this step sets something up for the next one.

Step 4
coords = Reverse[CountryData[#, "CenterCoordinates"]& /@ africa, 2];

No output - this step sets something up for the next one.

Step 5
southgraph = AdjacencyGraph[africa, adjm, VertexCoordinates -> coords, EdgeStyle -> Directive[Thickness[.003], White], VertexStyle -> Directive[EdgeForm[GrayLevel[.8]], GrayLevel[.7]], VertexSize -> .8];

No output - this step sets something up for the next one.

Step 6
tour = FindPostmanTour[southgraph];

No output - this step sets something up for the next one.

Step 7
path = tour[[1, All, 1]];
vrule = Thread[VertexList[southgraph] -> Range[VertexCount[southgraph]]];
route = GraphEmbedding[southgraph][[Join[path, {path[[1]]}] /. vrule]];

No output - this step sets something up for the next one.

Step 8
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]]}]}]
Output
-Graphics-

Functions used

Related recipes

All recipes · Function reference · Use this from an MCP client