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:

  1. new york
  2. san francisco
  3. 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:

  1. start @ point a
  2. matrix routing request remaining points.
  3. find nearest, becomes next waypoint
  4. repeat step 2.

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -