The TSP package offers a simple infrastructure to handle and solve TSPs.
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 |
|