TSP | R Documentation |
Constructor to create an instance of a symmetric traveling salesperson problem (TSP) and some auxiliary methods.
TSP(x, labels = NULL, method = NULL)
as.TSP(x)
## S3 method for class 'dist'
as.TSP(x)
## S3 method for class 'matrix'
as.TSP(x)
## S3 method for class 'TSP'
as.dist(m, ...)
## S3 method for class 'TSP'
print(x, ...)
n_of_cities(x)
## S3 method for class 'TSP'
n_of_cities(x)
## S3 method for class 'TSP'
labels(object, ...)
## S3 method for class 'TSP'
image(x, order, col = gray.colors(64), ...)
x, object |
an object (currently |
labels |
optional city labels. If not given, labels are taken from
|
method |
optional name of the distance metric. If |
m |
a TSP object to be converted to a dist object. |
... |
further arguments are passed on. |
order |
order of cities for the image as an integer vector or an object of class TOUR. |
col |
color scheme for image. |
Objects of class TSP
are internally represented as dist
objects (use as.dist()
to get the dist
object).
Not permissible paths can be set to a distance of +Inf
. NA
s are not allowed and -Inf
will lead
to the algorithm only being able to find an admissible tour, but not the best one.
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
.
Michael Hahsler
Other TSP:
ATSP()
,
Concorde
,
ETSP()
,
TSPLIB
,
insert_dummy()
,
reformulate_ATSP_as_TSP()
,
solve_TSP()
data("iris")
d <- dist(iris[-5])
## create a TSP
tsp <- TSP(d)
tsp
## use some methods
n_of_cities(tsp)
labels(tsp)
image(tsp)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.