compute_tour_distance {gor} | R Documentation |
Compute the distance of a TSP tour
Description
It computes the distance covered by a tour in a Traveling Salesman Problem
Usage
compute_tour_distance(h, d)
Arguments
h |
A tour specified by a vertex sequence |
d |
Distance matrix to use |
Details
This function simply add the distances in a distance matrix indicated by a vertex sequence defining a tour. It takes into account that, in a tour, the last vertex is joined to the first one by an edge, and adds its distance to the result, unlike compute_path_distance.
Value
The tour distance
d(\{v_1,...,v_n\}) = \sum_{j=1}^n
d(v_j,v_{(j mod n) + 1}).
Author(s)
Cesar Asensio
See Also
build_tour_nn nearest neighbor heuristic with a single starting point, build_tour_nn_best repeats the previous algorithm with all possible starting points, compute_distance_matrix computes a distance matrix, compute_path_distance computes path distances, plot_tour plots a tour.
Examples
set.seed(1)
n <- 25
z <- cbind(runif(n,min=1,max=10),runif(n,min=1,max=10))
d <- compute_distance_matrix(z)
h <- sample(1:n) # A random tour
compute_tour_distance(h, d) # 114.58