I’ve been testing out some ideas around the Travelling Salesman Problem using TSP and ggmap. For illustration I’ll find the optimal route between the following addresses:
ADDRESSES <span>=</span> <span>c</span><span>(</span>
<span>"115 St Andrew's Drive, Durban North, KwaZulu-Natal, South Africa"</span><span>,</span>
<span>"1 Evans Road, Glenwood, Berea, KwaZulu-Natal, South Africa"</span><span>,</span>
<span>"7 Radar Drive, Durban North, KwaZulu-Natal, South Africa"</span><span>,</span>
<span>"25 Gainsborough Drive, Durban North, KwaZulu-Natal, South Africa"</span><span>,</span>
<span>"77 Armstrong Avenue, Umhlanga, KwaZulu-Natal, South Africa"</span><span>,</span>
<span>"255 Musgrave Road, Berea, KwaZulu-Natal, South Africa"</span><span>,</span>
<span>"11 Cassia Road, Reservoir Hills, Durban, KwaZulu-Natal, South Africa"</span><span>,</span>
<span>"98 Shepstone Road, Berkshire Downs, New Germany, KwaZulu-Natal, South Africa"</span><span>,</span>
<span>"12 Finchley Road, Berea West, Westville, KwaZulu-Natal, South Africa"</span>
<span>)</span>
Load up some packages.
<span>library</span><span>(</span>dplyr<span>)</span>
<span>library</span><span>(</span>ggmap<span>)</span>
<span>library</span><span>(</span>gmapsdistance<span>)</span>
<span>library</span><span>(</span>TSP<span>)</span>
Geocoding
I added the latitude and longitude for each address using the handy ggmap::mutate_geocode(). ...