Learn R Programming

TSP (version 0.1-2)

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)

## 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, \ldots) ## S3 method for class 'TSP': print(x, \ldots)

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.
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.

Value

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

    n_of_cities() returns an the number of cities in x.

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

Details

Objects of class TSP are internally represented as dist objects.

See Also

TOUR, insert_dummy, tour_length, solve_TSP.

Examples

Run this code
data("iris")
d <- dist(iris[1:4])

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

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

Run the code above in your browser using DataLab