Learn R Programming

TSP (version 1.2-4)

ETSP: Class ETSP -- Euclidean traveling salesperson problem

Description

Constructor to create an instance of a Euclidean traveling salesperson problem (TSP) represented by city coordinates and some auxiliary methods.

Usage

ETSP(x, labels = NULL)

as.ETSP(x)

# S3 method for matrix as.ETSP(x)

# S3 method for data.frame as.ETSP(x)

# S3 method for ETSP as.TSP(x)

# S3 method for ETSP as.matrix(x, ...)

# S3 method for ETSP print(x, ...)

# S3 method for ETSP n_of_cities(x)

# S3 method for ETSP labels(object, ...)

# S3 method for ETSP image(x, order, col = gray.colors(64), ...)

# S3 method for ETSP plot(x, y = NULL, tour = NULL, tour_lty = 2, tour_col = 2, labels = TRUE, ...)

Value

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

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

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

Arguments

x, object

an object (data.frame or matrix) to be converted into a ETSP or, for the methods, an object of class ETSP.

labels

logical; plot city labels.

...

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.

tour, y

a tour to be visualized.

tour_lty, tour_col

line type and color for tour.

Author

Michael Hahsler

Details

Objects of class ETSP are internally represented as a matrix objects (use as.matrix() to get the matrix object).

See Also

Other TSP: ATSP(), Concorde, TSPLIB, TSP(), insert_dummy(), reformulate_ATSP_as_TSP(), solve_TSP()

Examples

Run this code
## create a random ETSP
n <- 20
x <- data.frame(x = runif(n), y = runif(n), row.names = LETTERS[1:n])
etsp <- ETSP(x)
etsp

## use some methods
n_of_cities(etsp)
labels(etsp)

## plot ETSP and solution
tour <- solve_TSP(etsp)
tour

plot(etsp, tour, tour_col = "red")

Run the code above in your browser using DataLab