The Traveling Salesman with Simulated Annealing, R, and Shiny

September 17, 2014

(This article was first published on Category: R | Todd W. Schneider, and kindly contributed to R-bloggers)

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, 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:

install.packages(c(&ldquo;shiny&rdquo;, &ldquo;maps&rdquo;, &ldquo;geosphere&rdquo;), repos=&ldquo;<a href="">>&rdquo;)
runGitHub(&ldquo;shiny-salesman&rdquo;, &ldquo;toddwschneider&rdquo;)

Code on GitHub

The full code is available at

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!

To leave a comment for the author, please follow the link and comment on their blog: Category: R | Todd W. Schneider. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)