0

I know how to get distance between 2 locations using

 var distance = require("google-distance-matrix");
 distance.key('API-KEY');
 distance.mode('driving');
 distance.units('imperial');
 var origins = [platlong.toString()];
 var destinations = [dlatlong.toString()];
 distance.matrix(origins, destinations, function(err,Data){
         console.log(Data.rows[0].elements[0].distance.value);
 }};

But how to get Cost Distance matrix of 3 or more locations

[
    [0, 2, 3],
    [2, 0, 4],
    [3, 4, 0]
]

For using VRP Algorithm i need Cost Distance Matrix as of Above.

There is only one way i know to create the Cost Distance matrix is by looping m x n times, i.e for 3 locations 3 x 3 = 9 times.

In real time scenario for 15 locations i have to loop 15 x 15 = 225 times

So i need to provide the API-Key for 225 times which will be very costly.

Is there any way for finding the Cost Distance Matrix cheaply instead of looping m x n times by google distance matrix

Ratan Uday Kumar
  • 5,738
  • 6
  • 35
  • 54

2 Answers2

0

You could reduce your look ups under the presumption, that the distance A->B is the same a B->A and not doing A->A loop ups. This means for 15 location you could get away with 15*14/2 = 105. This is still quite a lot, but less than half than before.

  • in real time scenario A->B and B->A are not same – Ratan Uday Kumar Jan 17 '19 at 07:06
  • from my home to office it is 14 kms and from office to home it is 17 kms because while going from office to home. On between i cant go in same way like of home to office because it is one way road for 2 kms. so i need to take another way in between for going from office to home. So practically in enterprise solution, your answer will not work. – Ratan Uday Kumar Jan 17 '19 at 07:11
0

Host your own routing engine, I use this a lot https://github.com/Project-OSRM/osrm-backend

This option is only useful when there is no need for live data.

Klaas
  • 243
  • 1
  • 3
  • 12