Go to homepage
About me

Around the World, and Back

Martins Dogo
 January 27th, 2015   ・   1 min read

The Travelling Salesman Problem (TSP) is a graph theory problem that requires the most efficient, i.e. shortest, closed-loop path through which a salesman can travel to each of n cities, exactly once [1]. Such a loop is called a Hamiltonian cycle [2] and there is no known general solution to the TSP. Practical applications to the solution of the TSP include the scheduling of tasks on a computer and ordering of genome features [3]. Inspired by the last example on this page, I tried projecting the shortest path through every country on the planet and visualising it on a map. To do this, I used the FindShortestTour function, which tries to find the shortest path through all the countries—going through each country once.

I used the following code to gather the names of the countries in the world and to find the shortest path going through the centre of each country.

1c = CountryData["Countries"];
2geocen = Map[CountryData[#, "CenterCoordinates"] &, c];
3{dis, path} = FindShortestTour[geocen];

Next, I visualised the results on a map using the following code.

1Export["mapflat.svg",
2 GeoGraphics[{
3 FaceForm[White],
4 EdgeForm[{Thin, Gray}],
5 Polygon[c],
6 GeoPath[c[[path[[1 ;; Length@c]]]]]
7 }, GeoRange -> "World", GeoBackground -> None, ImageSize -> 700]
8]
flatmap
Default projection

To view the path using an orthographic projection:

1GeoGraphics[{
2 FaceForm[White], EdgeForm[{Thin, Gray}], Polygon[c],
3 GeoPath[c[[path[[1 ;; Length@c]]]]]},
4 GeoRange -> "World",
5 GeoProjection -> {"Orthographic", "Centering" -> CountryData["World", "CenterCoordinates"]},
6 GeoBackground -> None, ImageSize -> 700]
orthomap
Orthographic projection

I then created an animation of the travelling salesman going around the globe.

1Export["animation.gif",
2 GeoGraphics[{GeoStyling[FaceForm[White], EdgeForm[{Thin, Gray}]], Polygon[CountryData["Countries"]], GeoStyling[FaceForm[Orange]], Polygon[c[[path[[#]]]]], {Gray, GeoPath[geocen[[path[[1 ;; #]]]]]}},
3 GeoRange -> "World", GeoProjection -> {"Orthographic", "Centering" -> geocen[[path[[#]]]]}, GeoBackground -> None, ImageSize -> 300] & /@ Range@(c+1),
4 ImageResolution -> 300, "DisplayDurations" -> 1.5]
This animation can also be found here.

As the travelling salesman moves to the next country, the centre of projection also moves to that country. The animation begins with Afghanistan because the list of countries CountryData["Countries"] returned was arranged in alphabetical order. Bear in mind that this is an attempt at finding the shortest path, going through the geographic centre of each country, which results in a distance of about 112,312 miles. This distance can be reduced in a few ways -- taking a different route for instance, or, starting from a different country.

— MS

[1] Weisstein, Eric W. "Traveling Salesman Problem." MathWorld.

[2] Weisstein, Eric W. "Hamiltonian Cycle." MathWorld.

[3] Erica Klarreich (2013)

More articles from Martins Dogo

Wolfram Notebooks

Think of a Wolfram Notebook, firstly, simply as a tool for writing and executing code. Now, how does one write code? You would normally type it, and often copy and paste it.

February 15th, 2021 · 15 min read

Exploring Thematic Coherence in Fake News

I presented recent work on exploring the coherence of topics in fake news articles, at this year's International Workshop on News Recommendation and Analytics (INRA) (held in conjunction with ECML PKDD). This post summarises the work, its results and its potential impact.

September 15th, 2020 · 4 min read

© 2021 Martins Dogo


"Everything new is on the rim of our view, in the darkness, below the horizon, so that nothing new is visible but in the light of what we know." — Zia Haider Rahman

Link to $https://github.com/m-artiLink to $https://www.linkedin.com/in/martins-dogoLink to $https://twitter.com/m_arti