Todd W. Schneider

The Traveling Salesman with Simulated Annealing, R, and Shiny

Make your own tour with the interactive Shiny app

Here’s the Shiny app that lets you pick up to 30 cities on the map, set some parameters of the annealing schedule, then run the actual simulated annealing process (or just click ‘solve’ if you’re lazy). Give it a shot below! Bonus points if you recognize where the default list of cities comes from…

The app is hosted at ShinyApps.io, which is currently in alpha testing, so I’m not entirely sure how reliable it will be. If you want to run the app on your local machine, it’s very easy, all you need to do is paste the following into your R console:

1
2
3
install.packages(c("shiny", "maps", "geosphere"), repos="http://cran.rstudio.com/")
library(shiny)
runGitHub("shiny-salesman", "toddwschneider")

Code on GitHub

The full code is available at https://github.com/toddwschneider/shiny-salesman

Around the World in 80,000 Miles

Here’s another animated gif using a bunch of world capitals. The “solution” here is almost certainly not the global optimum, but it’s still fun to watch!