-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathREADME.Rmd
More file actions
85 lines (63 loc) · 2.32 KB
/
Copy pathREADME.Rmd
File metadata and controls
85 lines (63 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
output: github_document
bibliography: vignettes/TSP.bib
link-citations: yes
---
```{r echo=FALSE, results = 'asis'}
pkg <- 'TSP'
source("https://raw.githubusercontent.com/mhahsler/pkg_helpers/main/pkg_helpers.R")
pkg_title(pkg)
```
[](https://anaconda.org/conda-forge/r-tsp)
## Introduction
The TSP package [@Hahsler+Hornik2007] provides the
basic infrastructure and some algorithms for the traveling
salesman problems (symmetric, asymmetric and Euclidean TSPs).
The package provides some fast implementations of simple algorithms including:
* __Tour construction heuristics__
* __Insertion algorithms__: nearest insertion, farthest insertion, cheapest insertion, arbitrary insertion [@Rosenkrantz1977]
* __Nearest neighbor methods__: Nearest neighbor and repetitive nearest neighbor [@Rosenkrantz1977]
* __Tour improvement methods__
* __Two-opt heuristic__ [@Croes1958]
* __Simulated annealing__ [@Kirkpatrick1983]
* __State-of-the-art solver interfaces__
* __Concorde TSP solver interface__ [@Applegate2000; @Applegate2006]
* __Concorde Chained-Lin-Kernighan heuristic interface__ [@Applegate2003]
The package can read and write the TSPLIB format [@Reinelt1991] and it can solve many of the
problems in the [TSPLIB95 problem library (local copy of the archive)](https://github.com/mhahsler/TSP/tree/master/TSPLIB95).
```{r echo=FALSE, results = 'asis'}
pkg_usage(pkg)
pkg_citation(pkg, 2L)
pkg_install(pkg)
```
## Usage
Load a data set with 312 cities (USA and Canada) and create a TSP object.
```{r}
library("TSP")
data("USCA312")
tsp <- TSP(USCA312)
tsp
```
Find a tour using the default heuristic.
```{r}
tour <- solve_TSP(tsp)
tour
```
Show the first few cities in the tour.
```{r}
head(tour, n = 10)
```
Visualize the complete tour.
```{r, fig.dim=c(6, 6)}
library(maps)
data("USCA312_GPS")
plot((USCA312_GPS[, c("long", "lat")]), cex = .3)
map("world", col = "gray", add = TRUE)
polygon(USCA312_GPS[, c("long", "lat")][tour,], border = "red")
```
An online example application of TSP can be found on [shinyapps](https://shrinidhee.shinyapps.io/SimpleTSP).
## Help and Bug Reports
You can find Q&A's and ask your own questions at
https://stackoverflow.com/search?q=TSP+R
Please submit bug reports to https://github.com/mhahsler/TSP/issues
## References