Travel All Capitals of the Conterminous US States
Obtain the list of the capitals of the 48 conterminous US states.
In[1]:=
![Click for copyable input](assets.en/travel-all-capitals-of-the-conterminous-us-states/In_49.png)
capitals =
EntityValue[
EntityClass["AdministrativeDivision", "ContinentalUSStates"],
"CapitalCity"]
Out[1]=
![](assets.en/travel-all-capitals-of-the-conterminous-us-states/O_38.png)
Download their GeoPosition coordinates.
In[2]:=
![Click for copyable input](assets.en/travel-all-capitals-of-the-conterminous-us-states/In_50.png)
GeoPosition[capitals]
Out[2]=
![](assets.en/travel-all-capitals-of-the-conterminous-us-states/O_39.png)
Compute the order in which the cities should be visited to minimize the total geodetic distance.
In[3]:=
![Click for copyable input](assets.en/travel-all-capitals-of-the-conterminous-us-states/In_51.png)
GeoPosition[capitals];
{d, perm} = FindShortestTour[%]
Out[3]=
![](assets.en/travel-all-capitals-of-the-conterminous-us-states/O_40.png)
Represent that path on a map.
In[4]:=
![Click for copyable input](assets.en/travel-all-capitals-of-the-conterminous-us-states/In_52.png)
GeoGraphics[{GeoPath[capitals[[perm]]], Red, PointSize[Medium],
Point[capitals]}]
Out[4]=
![](assets.en/travel-all-capitals-of-the-conterminous-us-states/O_41.png)
Now compute travel directions to drive through the same cities in the same order.
In[5]:=
![Click for copyable input](assets.en/travel-all-capitals-of-the-conterminous-us-states/In_53.png)
td = TravelDirections[capitals[[perm]]];
Represent the corresponding path on a map.
In[6]:=
![Click for copyable input](assets.en/travel-all-capitals-of-the-conterminous-us-states/In_54.png)
GeoGraphics[{td["TravelPath"], Red, PointSize[Medium],
Point[capitals]}]
Out[6]=
![](assets.en/travel-all-capitals-of-the-conterminous-us-states/O_42.png)
The total distance to drive is shown.
In[7]:=
![Click for copyable input](assets.en/travel-all-capitals-of-the-conterminous-us-states/In_55.png)
td["TravelDistance"]
Out[7]=
![](assets.en/travel-all-capitals-of-the-conterminous-us-states/O_43.png)
Compare with the geodetic distance.
In[8]:=
![Click for copyable input](assets.en/travel-all-capitals-of-the-conterminous-us-states/In_56.png)
d
Out[8]=
![](assets.en/travel-all-capitals-of-the-conterminous-us-states/O_44.png)