javascript - Optimize route by distance -
i building here maps based web application. main features include ability upload spreadsheet file (.xls, .xlsx) server , plan route addresses in file, 500 waypoints.
of course, these waypoints aren't way in optimized order, i'd let user click on "optimize route" button , optimize distance.
for example if file has these 3 addresses:
- new york
- san francisco
- long island
the route default go ny sf, li.
the application check distances , reorder waypoints array in way this:
ny -> li -> sf
my question: there built in route optimization function in here maps, or should write own?
you should take @ matrix routing api (sign-in required). calculate "real" distance between each of n x m locations. information, have reduced issue travelling salesman problem. of course, tsp np-complete, can't you've got optimal answer unless use brute force algorithm.
personally i'd @ nearest neighbour solution - quick, simple code , returns "reasonable", if not optimal solution. can update more complex algorithms necessary:
pseudo-code below:
- start @ point a
- matrix routing request remaining points.
- find nearest, becomes next waypoint
- repeat step 2.
Comments
Post a Comment