0

I have an algorithm that currently pulls a few 2Dsphere points (no more than 6) from my database, which are all within a certain radius from one another. Once I have pulled these points, I want to order them in an efficient route and return them in this order (Currently, when I return them, a user could be sent from one point to the point furthest away from it, even if there are points in between on the way). Is there an efficient approach to doing this using MongoDB 2Dsphere points? The brute-force method I have experimented with is not very efficient: I find the point B that is closest to the start point A, then find the point C closest to point B, and so on.

user3802348
  • 2,502
  • 11
  • 36
  • 49

1 Answers1

0

This is the travelling salesman problem. It is extremely computationally expensive to brute force, though there are some algorithms which do a good job of approximating the efficient route.

https://en.wikipedia.org/wiki/Travelling_salesman_problem

The wiki article has some good approximation algorithms to get you started on your googling

https://en.wikipedia.org/wiki/Travelling_salesman_problem#Christofides.27_algorithm_for_the_TSP

Chase Adams
  • 478
  • 3
  • 7
  • For an example of approaching this using MongoDB geospatial queries, see: [The Traveling Santa](https://www.mongodb.com/blog/post/the-traveling-santa) blog post. – Stennie Feb 09 '17 at 05:41