GitHub - mhahsler/TSP: Traveling Salesperson Problem - R package (original) (raw)

R package TSP - Infrastructure for the Traveling Salesperson Problem

r-universe status Package on CRAN CRAN RStudio mirror downloads Anaconda.org

Introduction

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 solverand its implementation of the Chained-Lin-Kernighan heuristic.

The following R packages use TSP:archetypes,cholera,colorpatch,condvis,CRTspat,ForagingOrg,isocir,jocre,MLCOPULA,nilde,nlnet,PairViz,pencopulaCond,SCORPIUS,sensitivity,seriation,sfnetworks,tspmeta,VineCopula,vines

To cite package ‘TSP’ in publications use:

Hahsler M, Hornik K (2007). “TSP - Infrastructure for the traveling salesperson problem.” Journal of Statistical Software, 23(2), 1-21. ISSN 1548-7660, doi:10.18637/jss.v023.i02https://doi.org/10.18637/jss.v023.i02.

@Article{,
  title = {TSP -- {I}nfrastructure for the traveling salesperson problem},
  author = {Michael Hahsler and Kurt Hornik},
  year = {2007},
  journal = {Journal of Statistical Software},
  volume = {23},
  number = {2},
  pages = {1--21},
  doi = {10.18637/jss.v023.i02},
  month = {December},
  issn = {1548-7660},
}

Installation

Stable CRAN version: Install from within R with

Current development version: Install fromr-universe.

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

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: 40959

Show the first few cities in the tour.

##   Bakersfield, CA        Fresno, CA      Stockton, CA      Berkeley, CA 
##                17                99               268                26 
##       Oakland, CA San Francisco, CA      San Jose, CA    Santa Cruz, CA 
##               186               241               242               245 
##          Hilo, HI      Honolulu, HI 
##               119               120

An online example application of TSP can be found onshinyapps.

Help and Bug Reports

You can find Q&A’s and ask your own questions athttps://stackoverflow.com/search?q=TSP+R

Please submit bug reports to https://github.com/mhahsler/TSP/issues

References