perliedman / leaflet-routing-machine

Control for routing in Leaflet
https://www.liedman.net/leaflet-routing-machine/
Other
1.06k stars 347 forks source link

Is possible to route based on a shortest path but by prioritizing which points to pass first? #692

Open GabrieleT0 opened 1 year ago

GabrieleT0 commented 1 year ago

Hi there, I'm currently working on a small university project, I'm building a system for garbage collection where the bin are placed as pins on the map. I want to calculate the route that pass between these bins, but by prioritizing those that are full. Thank you for your help in advice.

curtisy1 commented 1 year ago

Hey there!

The question is, how much of the data you actually have and how efficient does the route have to be? If you have the coordinates of the bins and information on how full they are, you might be able to do a very naive optimization at first:

const waypoints = bins.sort(b => b.fullness).map(b => b.coordinate);

if you pass this into LRM via setWaypoints(), you should get a route where the fullest bin will be the first stop on your route.

However, that might not always be the most efficient solution, since your starting point might be in the south while the fullest bin is far north. In this case, it would be better to empty all the bins along the way. That is similar to a VRP (vehicle routing problem) with one or possibly more constraints, something that a few providers like Valhalla can probably solve for you. After you have your optimized route though, it should be as simple as feeding the waypoints into LRM.