R Language traveling salesman problem TSP

Original link: http://tecdat.cn/?p=6551

 

Traveling Salesman Problem (TSP) commonly used terms in one of the most complex problems, attributed to a combination of optimization. N travel to cities (vertices) need to check the (n-1)! possibility. 3,000 locations, 4 * 10 ^ 9131 possible solutions.

This paper investigated the performance of the package R: TSP and tspmeta. The results of my use very satisfied.

 

Enter the following code in your TSP225.csv file and output your solution and visualization. Generated 'tour' is a class of objects and TOUR integer; it contains your solution.

 

coords.df <- data.frame(long=TSP225$Long, lat=TSP225$Lat)

coords.mx <- as.matrix(coords.df)

# Compute distance matrix

dist.mx <- dist(coords.mx)

# Construct a TSP object

tsp.ins <- tsp_instance(coords.mx, dist.mx )

#

tour <- run_solver(tsp.ins, method="2-opt")

#Plot

autoplot(tsp.ins, tour)

Compare Solutions: The following figure shows the length of the seven best tourist heuristic solutions Concorde and the exact solution. For Concorde solution, I use the NEOS-Server hosted at UW-Madison.

methods <- c("nearest_insertion" "2-opt")

tours <- sapply(methods  simplify = FALSE)

dotchart( ),

 )

 

In the 2D random vertices # 23000

Clearly, as the number of vertices growth, exact solutions, and other heuristics to resolve the differences between the program significantly increased. 2-opt the solution closest to the optimum. Repeat the 2-opt solutions and choose the smallest value I was very close to the exact solution.

 

 

 

Thank you for reading this article, you have any questions please leave a comment below!

  

Big Data tribe  - Chinese professional third-party data service providers to provide customized one-stop data mining and statistical analysis consultancy services

Statistical analysis and data mining consulting services: y0.cn/teradat (Consulting Services, please contact the official website customer service )

Click here to send me a messageQQ:3025393450

[Service] Scene  

Research; the company outsourcing; online and offline one training; data collection; academic research; report writing; market research.

[Tribe] big data to provide customized one-stop data mining and statistical analysis consultancy

Welcome to elective our R language data analysis will be mining will know the course!

 

Big Data tribe  - Chinese professional third-party data service providers to provide customized one-stop data mining and statistical analysis consultancy services

Statistical analysis and data mining consulting services: y0.cn/teradat (Consulting Services, please contact the official website customer service )

Click here to send me a messageQQ:3025393450

[Service] Scene  

Research; the company outsourcing; online and offline one training; data collection; academic research; report writing; market research.

[Tribe] big data to provide customized one-stop data mining and statistical analysis consultancy

Welcome to elective our R language data analysis will be mining will know the course!

 

Guess you like

Origin www.cnblogs.com/tecdat/p/11515474.html