Last active
May 7, 2017 17:39
-
-
Save ytmytm/83b9063869f92dbd8d47120189b3cad9 to your computer and use it in GitHub Desktop.
TSP problem over major cities in Poland
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(readxl) | |
setwd("c:/tmp/obchodpolski/") | |
data <- read_xlsx("miasta.xlsx",sheet = "dist",col_names = TRUE) | |
# drop city names | |
data <- data[,-1] | |
# force distance matrix to be symmetric | |
library(Matrix) | |
ds <- as.matrix(forceSymmetric(as.matrix(data))) | |
library(TSP) | |
tsp <- TSP(as.matrix(ds)) | |
# suboptimal | |
tour <- solve_TSP(tsp) | |
tour_length(tour) | |
names(tour) | |
# probably the best | |
tour2 <- solve_TSP(tsp,method="nn",rep=1000,two_opt=TRUE) | |
tour_length(tour2) | |
names(tour2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment