Class TOUR – Solution to a traveling salesperson problem
Class to store the solution of a TSP. Objects of this class are returned by
TSP solvers in this package. Essentially, an object of class TOUR is
a permutation vector containing the order of cities to visit.
## conctructor TOUR(x, method=NA, tsp=NULL) ## coercion as.TOUR(object) ## methods ## S3 method for class 'TOUR' print(x, ...)
x |
an integer permutation vector or, for the methods
an object of class |
.
object |
data (an integer vector) which can be coerced to |
.
method |
character string; method used to create the tour. |
tsp |
|
... |
further arguments are passed on. |
Since an object of class TOUR is an integer vector, it can be subsetted
as an ordinary vector or coerced to an integer vector using
as.integer(). It also contains the names of the objects as labels.
Additionally, TOUR has the following attributes:
"method", "tour_length".
For most functions, e.g., tour_length or image, the
TSP/ATSP object used to find the tour is still needed, since the tour
does not contain the distance information.
Michael Hahsler
TSP,
ATSP,
tour_length,
image.
TOUR(1:10)
## calculate a tour
data("USCA50")
tour <- solve_TSP(USCA50)
tour
## get permutation vector
as.integer(tour)
## get tour length directly from tour
attr(tour, "tour_length")
## show labels
labels(tour)Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.