Skip to content

Instantly share code, notes, and snippets.

@kandebonfim
Last active February 15, 2019 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kandebonfim/09b1ed8a9fcc3e5e62b389acb3df0ec1 to your computer and use it in GitHub Desktop.
Save kandebonfim/09b1ed8a9fcc3e5e62b389acb3df0ec1 to your computer and use it in GitHub Desktop.
Travelling salesman problem in R
library(TSP)
library(tspmeta)
coords.df <- data.frame(long=runif(40, min=0, max=100), lat=runif(40, min=0, max=100))
coords.mx <- as.matrix(coords.df)
# Compute distance matrix
dist.mx <- dist(coords.mx)
# Construct a TSP object
tsp.ins <- tsp_instance(coords.mx, dist.mx)
tour <- run_solver(tsp.ins, method="2-opt")
#Plot
autoplot(tsp.ins, tour)
@kandebonfim
Copy link
Author

Plot Example

rplot22

@junior-frank-barros
Copy link

Boa tarde, amigo!
Estou aprendendo programar em R. Esse Script do travelling Selasman Problem, aplica-se pra roteamento de veículos?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment