0

I'm using TSP package built by Professor M. Hahsler in R. The function is giving the results but when converted to a data frame, it's shuffling the results. How do I save the results in a dataframe?

data <- data.frame(
  "lat" = c(13.11256,13.11293,13.11209,13.11225,13.11281, 13.11229),                    
  "lon" = c(77.52533,77.52480,77.52548,77.52532,77.52485,77.52537),
  "id" = 1:6
)

big_data <- round(distancematrix(data))
tsp <- TSP(big_data)
methods <- c("nn")
tours <- methods %>% map(function(methods) { solve_TSP(tsp, methods)})
cl <- as.data.frame(tours)
Shree
  • 10,835
  • 1
  • 14
  • 36
Shanks07
  • 1
  • 2
  • It'd help if you share a small (say 5 sites) reproducible example. See [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Make sure your code includes dummy data and your code such that problem can be reproduced by others. – Shree Aug 21 '19 at 17:13
  • 1
    I am not quite sure what you mean by "shuffle." Please provide an example that creates the result you get and shows what you would expect as the correct answer. – Michael Hahsler Aug 23 '19 at 16:08
  • @MichaelHahsler I am guessing OP is referring to thedifferent solutions one gets with same algorithm and same data. I believe that variation or *"shuffling"* happens due to random starting node at every run, right? – Shree Aug 23 '19 at 22:57
  • @Shree the starting node is randomly chosen unless you set the starting note with the control argument start. – Michael Hahsler Aug 26 '19 at 21:36

0 Answers0