Skip to content
Advertisement

How to create a vehicle route optimization problem using or-tools and google-distance matrix while nullifying the end location only?

I am trying to create a vehicle routing problem for multi-drivers with pickup and drop-off locations. The starting point for each driver is their current location and the ending point would be anywhere they end.

The input to my algorithm is a series of lot/long locations. The final output would be the best(shortest) route decided for the driver starting from his location and ending at any location. My actual final output is a route that starts at the driver location and ends at the driver location.

My problem is how can I create the distance matrix while nullifying the end location (the distance from the end node to any other node would be zero).

These are the functions that convert the lat/long locations to distance matrix >>

JavaScript

Then the distance matrix would look like this >>

JavaScript

In the Google OR-tools it mentions if I wanted to have arbitrary start and end locations I should add a row and column of zeros to my distance matrix. But for me that would create a problem because I wouldnt be able to map back the indices to lat/long locations. Also same solution I found in a post here but still the same problem because I use the indices to map back to the lat/long locations.

This is my exact algorithm >> https://developers.google.com/optimization/routing/routing_tasks#setting-start-and-end-locations-for-routes only start and end locations are the deliverer current location and this is the extra part of mapping back the routes to the actual locations which is causing the problem of mapping back indices to lat/long loc

JavaScript

Advertisement

Answer

Apparently, it is as simple as it is answered in the other question. I added a row of zeros and an additional zero at the start of every row after creating the distance matrix > this will tell the algorithm that the distance between the point at index zero and any other point is 0. And I set my end point data["ends"] = 0. So in my case the distance matrix would look like this >>

JavaScript

This code for doing so is as follows >>

JavaScript

p.s. if anyone needs clarifying feel free to reach out :)

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement