Learn R Programming

TSP (version 0.1-2)

insert_dummy: Insert dummy cities into a distance matrix

Description

Inserts dummy cities into an object of class TSP. A dummy city has constant distance to all other cities and is infinitely far from other dummy cities. Dummy cities can be used together with TSP solvers to find an optimal linear order or to perform rearrangement clustering (Climer and Zhang 2006).

Usage

insert_dummy(x, n = 1, const = max(x), inf = Inf)

Arguments

x
an object of class TSP.
n
number of dummy cities.
const
distance of the dummy cities to all other cities.
inf
distance between dummy cities.

Details

The dummy cities are inserted before the other cities in x.

References

Sharlee Climer, Weixiong Zhang (2006): Rearrangement Clustering: Pitfalls, Remedies, and Applications, Journal of Machine Learning Research 7(Jun), pp. 919--943.

See Also

TSP

Examples

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

## insert 2 dummy cities (as object 1 and 2)
tsp <- insert_dummy(tsp, n = 2)

## get a solution for the TSP
tour <- solve_TSP(tsp, method = "nearest")

## plot the distance matrix
image(tsp, tour)

## draw lines where the dummy cities are located
abline(h=sapply(1:2, FUN = function(i) which(tour == i)), col = "red")
abline(v=sapply(1:2, FUN = function(i) which(tour == i)), col = "red")

Run the code above in your browser using DataLab