ETSP: Class ETSP - Euclidean traveling salesperson problem

Description Usage Arguments Details Value Author(s) See Also Examples

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## constructor
ETSP(x, labels = NULL)

## coercion
as.ETSP(x)

## methods
## S3 method for class 'ETSP'
n_of_cities(x)
## S3 method for class 'ETSP'
image(x, order, col = gray.colors(64), ...)
## S3 method for class 'ETSP'
plot(x, y = NULL, tour = NULL, tour_lty = 2, tour_col = 1, ...)
## S3 method for class 'ETSP'
labels(object, ...)
## S3 method for class 'ETSP'
print(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

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

col

color scheme for image.

order

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

tour, y

a tour to be visualized.

tour_lty, tour_col

line type and color for tour.

...

further arguments are passed on.

Details

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

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.

Author(s)

Michael Hahsler

See Also

TOUR, insert_dummy, tour_length, solve_TSP.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
x <- data.frame(x = runif(20), y = runif(20), row.names = LETTERS[1:20])

## create a TSP
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")

Example output

object of class 'ETSP' 
20 cities (Euclidean TSP)
[1] 20
 [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S"
[20] "T"
object of class 'TOUR' 
result of method 'arbitrary_insertion+two_opt' for 20 cities
tour length: 4.259285 

TSP documentation built on May 2, 2019, 6:04 a.m.