Learn R Programming

R package TSP - Traveling Salesperson Problem (TSP)

This package provides the basic infrastructure and some algorithms for the traveling salesman problems (symmetric, asymmetric and Euclidean TSPs). The package provides some simple algorithms and an interface to the Concorde TSP solver and its implementation of the Chained-Lin-Kernighan heuristic.

Installation

Stable CRAN version: Install from within R with

install.packages("TSP")

Current development version: Install from r-universe.

install.packages("TSP", repos = "https://mhahsler.r-universe.dev")

Usage

Load a data set with 312 cities (USA and Canada) and create a TSP object.

library("TSP")
data("USCA312")

tsp <- TSP(USCA312)
tsp
## object of class 'TSP' 
## 312 cities (distance 'euclidean')

Find a tour using the default heuristic.

tour <- solve_TSP(tsp)
tour
## object of class 'TOUR' 
## result of method 'arbitrary_insertion+two_opt' for 312 cities
## tour length: 41389

Show the first few cities in the tour.

head(tour, n = 10)
##     Jacksonville, FL      Gainesville, FL    Daytona Beach, FL 
##                  127                  101                   72 
##          Orlando, FL            Tampa, FL Saint Petersburg, FL 
##                  190                  275                  234 
##         Sarasota, FL  West Palm Beach, FL            Miami, FL 
##                  247                  296                  164 
##         Key West, FL 
##                  136

An online example application of TSP can be found on shinyapps.

References

Copy Link

Version

Install

install.packages('TSP')

Monthly Downloads

28,451

Version

1.2-4

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

April 4th, 2023

Functions in TSP (1.2-4)

tour_length

Calculate the length of a tour
reformulate_ATSP_as_TSP

Reformulate a ATSP as a symmetric TSP
solve_TSP

TSP solver interface
ETSP

Class ETSP -- Euclidean traveling salesperson problem
TSP-package

TSP: Traveling Salesperson Problem (TSP)
cut_tour

Cut a tour to form a path
Concorde

Using the Concorde TSP Solver
TOUR

Class TOUR -- Solution to a traveling salesperson problem
USCA

USCA312/USCA50 -- 312/50 cities in the US and Canada
insert_dummy

Insert dummy cities into a distance matrix
ATSP

Class ATSP -- Asymmetric traveling salesperson problem
TSP

Class TSP -- Symmetric traveling salesperson problem
TSPLIB

Read and write TSPLIB files