Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

TSP

Class TSP – Symmetric traveling salesperson problem


Description

Constructor to create an instance of a symmetric traveling salesperson problem (TSP) and some auxiliary methods.

Usage

## constructor
TSP(x, labels = NULL, method = NULL)

## coercion
as.TSP(x)

## methods
## S3 method for class 'TSP'
n_of_cities(x)
## S3 method for class 'TSP'
image(x, order, col = gray.colors(64), ...)
## S3 method for class 'TSP'
labels(object, ...)
## S3 method for class 'TSP'
print(x, ...)

Arguments

x, object

an object (currently dist or a symmetric matrix) to be converted into a TSP or, for the methods, an object of class TSP.

labels

optional city labels. If not given, labels are taken from x.

method

optional name of the distance metric. If x is a dist object, then the method is taken from that object.

col

color scheme for image.

order

order of cities for the image as an integer vector or an object of class TOUR.

...

further arguments are passed on.

Details

Objects of class TSP are internally represented as dist objects (use as.dist() to get the dist object).

Value

TSP() returns x as an object of class TSP.

n_of_cities() returns the number of cities in x.

labels() returns a vector with the names of the cities in x.

Author(s)

Michael Hahsler

See Also

Examples

data("iris")
d <- dist(iris[-5])

## create a TSP
tsp <- TSP(d)
tsp

## use some methods
n_of_cities(tsp)
labels(tsp)
image(tsp)

TSP

Traveling Salesperson Problem (TSP)

v1.1-10
GPL-3
Authors
Michael Hahsler [aut, cre, cph], Kurt Hornik [aut, cph]
Initial release
2020-04-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.