The TSP package for R

Introduction

The traveling salesperson problem (TSP) is a well known and important combinatorial optimization problem. The goal is to find the shortest tour that visits each city in a given list exactly once and then returns to the starting city.

The TSP package offers a simple infrastructure to handle and solve TSPs.

Features

Example

A simple example using the data set of 312 cities in North America (USA and Canada) which comes with the package. The result is visualized with the R-package map (code is available in the introductory paper below).

> ## load library and read data
> library("TSP")
> data("USCA312")
 
> ## create a TSP object from the data 
> tsp <- TSP(USCA312)
> tsp
 
object of class 'TSP'
312 cities (distance   'euclidean')
 
> ## find a 2-optimal solution 
> tour <- solve_TSP(tsp, method = "2-opt")
> tour
 
object of class 'TOUR'
result of method '2-opt' for 312 cities
tour length: 41381

Downloads and further information

Michael Hahsler.