TOUR: Class TOUR - Solution to a traveling salesperson problem

View source: R/TOUR.R

TOURR Documentation

Class TOUR – Solution to a traveling salesperson problem

Description

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.

Usage

TOUR(x, method = NA, tsp = NULL)

as.TOUR(object)

## S3 method for class 'numeric'
as.TOUR(object)

## S3 method for class 'integer'
as.TOUR(object)

## S3 method for class 'TOUR'
print(x, ...)

Arguments

x

an integer permutation vector or, for the methods an object of class TOUR.

method

character string; method used to create the tour.

tsp

TSP object the tour applies to. If available then the tour will include the tour length. Also the labels of the cities will be available in the tour (otherwise the labels of x are used).

object

data (an integer vector) which can be coerced to TOUR.

...

further arguments are passed on.

Details

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.TSP(), the TSP/ATSP object used to find the tour is still needed, since the tour does not contain the distance information.

Author(s)

Michael Hahsler

See Also

Other TOUR: cut_tour(), solve_TSP(), tour_length()

Examples

TOUR(1:10)

## calculate a tour
data("USCA50")
tour <- solve_TSP(USCA50)
tour

## get tour length directly from tour
tour_length(tour)

## get permutation vector
as.integer(tour)

## show labels
labels(tour)

TSP documentation built on April 4, 2023, 5:13 p.m.