Last active
February 15, 2019 14:08
-
-
Save kandebonfim/09b1ed8a9fcc3e5e62b389acb3df0ec1 to your computer and use it in GitHub Desktop.
Travelling salesman problem in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
Plot Example