data("USCA50")
## create TSP
tsp <- USCA50
## methods
methods <- c("nearest_insertion", "cheapest_insertion", "farthest_insertion",
"arbitrary_insertion", "nn", "repetitive_nn", "2-opt")
## calculate tours
tours <- lapply(methods, FUN = function(m) solve_TSP(tsp, method = m))
names(tours) <- methods
## use the external solver which has to be installed separately
tours$concorde <- solve_TSP(tsp, method = "concorde")
tours$linkern <- solve_TSP(tsp, method = "linkern")
## show first tour
tours[[1]]
## compare tour lengths
opt <- 14497 # optained by concorde
tour_lengths <- c(sapply(tours, FUN = attr, "tour_length"), optimal = opt)
dotchart(tour_lengths/opt*100-100, xlab = "percent excess over optimum")
Run the code above in your browser using DataLab