m <- 10 # Generate some points in the plane
z <- cbind(c(rep(0,m), rep(2,m), rep(5,m), rep(7,m)), rep(seq(0,m-1),4))
n <- nrow(z)
d <- compute_distance_matrix(z)
b <- build_tour_nn_best(d, n)
b$distance # Distance 48.6055
bi <- improve_tour_2opt(d, n, b$tour)
bi$distance # Distance 48 (optimum)
compute_lower_bound_HK(d,n,U=48.61) # 45.927
compute_lower_bound_HK(d,n,U=48.61,it=20,tsmall=1e-6) # 45.791
## Random points
set.seed(1)
n <- 25
z <- cbind(runif(n,min=1,max=10),runif(n,min=1,max=10))
d <- compute_distance_matrix(z)
bn <- build_tour_nn_best(d,n)
b3 <- improve_tour_3opt(d,n,bn$tour)
b3$distance # 35.08155
compute_lower_bound_HK(d, n, U=35.1) # 34.80512
compute_lower_bound_HK(d, n, U=35.0816, it=20) # 35.02892
compute_lower_bound_HK(d, n, U=35.0816, tsmall = 1e-5) # 34.81119
compute_lower_bound_HK(d, n, U=35.0816, it=50, tsmall = 1e-9) # 35.06789
Run the code above in your browser using DataLab