data("iris")
tsp <- TSP(dist(iris[1:4]))
## insert 2 dummy cities (as object 1 and 2)
tsp <- insert_dummy(tsp, n = 2)
## get a solution for the TSP
tour <- solve_TSP(tsp, method = "nearest")
## plot the distance matrix
image(tsp, tour)
## draw lines where the dummy cities are located
abline(h=sapply(1:2, FUN = function(i) which(tour == i)), col = "red")
abline(v=sapply(1:2, FUN = function(i) which(tour == i)), col = "red")
Run the code above in your browser using DataLab