Try now in the
Open Cloud »
(no sign-in required)

Shortest City Tours

In which order should you visit cities so as to travel the shortest distance?

Run the code to get a list of the capitals of Africa. Try other regions, like northern europe or the caribbean:

SHOW/HIDE DETAILS

Get a list of capitals of countries in Africa. Type += to get a natural language input box, and type capitals of africa into it. Run the code with +:

In[1]:=
X
Out[1]=
HIDE DETAILS
In[1]:=
X
Out[1]=

Get the geographic positions of the capitals. Try getting other properties, like "Population" or "Elevation":

SHOW/HIDE DETAILS

Get the geographic position of Paris. The result contains {latitude,longitude} coordinates:

In[1]:=
X
Out[1]=

Get the geographic positions of the capitals of Africa, and give the result the name positions:

In[2]:=
X
Out[2]=
HIDE DETAILS
In[1]:=
X
Out[1]=

Find the order of capitals that gives the shortest route:

Note: run the code in the previous step first.

SHOW/HIDE DETAILS

Find the length of the shortest tour through all the capitals, and the order of the capitals along the route:

In[1]:=
X
Out[1]=

Extract just the order of the capitals on the shortest tour:

In[2]:=
X
Out[2]=
HIDE DETAILS
In[1]:=
X
Out[1]=

Show the order of the capitals along the shortest route:

Note: run the code in the previous step first.

SHOW/HIDE DETAILS

Reorder the elements of a list. Put the second element first, then the fourth and so on:

In[1]:=
X
Out[1]=

Order the capitals of Africa along the shortest tour route:

In[2]:=
X
Out[2]=
HIDE DETAILS
In[1]:=
X
Out[1]=

Make a map of the shortest tour:

SHOW/HIDE DETAILS

Get the positions of the capitals in their order along the shortest tour route:

In[1]:=
X
Out[1]=

Make a map with a thick red line showing the shortest capital tour:

In[2]:=
X
Out[2]=
HIDE DETAILS
In[1]:=
X
Out[1]=

Share ItMake a website that shows the shortest route through cities that you specify:

SHOW/HIDE DETAILS

Deploy a form that asks for a list of cities and makes a map showing the shortest route through them. GeoRangePadding is used to add a margin around the route:

In[1]:=
X
Out[1]=

Click the link in the output to visit the site. Separate the cities you enter with semicolons (;) rather than spaces or commas, since both of those can occur in city names.

Tell the world about your creation by sharing the link via email, tweet or other message.

HIDE DETAILS
In[1]:=
X
Out[1]=