1

Maybe this can be an interesting problem for some people. I need to know how I can include the previous location visited in the getTransportCost function to calculate the previous direction to know where are you coming from? And then I can calculate the distance to the next location.

For example, like this: getTransportTime(Location previus, Location from, Location to, double departureTime, Driver driver, Vehicle vehicle){ return getDistanceFromAPreviusLocation(previus, from, to); } In the next image you can see my problem, you have a pickup point and two delivery points, currently it's calculating the partial distances without considering the previous direction from where is coming the car in the street.

The problem:

The algorithm use exclusively the distances from point to point to compute the route getting as an outcome, the sum of these distances. If you only draw it like the sum of little distances without considered the previus point visited then you have a thing similar to this.

enter image description here

But If you draw the same solution with a unique path to follow then you have this problem. Look the next image

enter image description here

In this image, you can see a possible solution considering the previus location visited.

Possible solution:

enter image description here

Thanks!

1 Answers1

0

Why you need to have prev location in getTransportCost? Optimal solution is calculated by whole route cost calculation, so jsprit by default should return image2 as best solution. Didn`t understood link between your images and getTransportCost).

Before calling jsprit you should calculate distance matrix for each point pair. Something like:

            pickup  deliveryX   deliveryY
pickup       0        10            15
delivery X  12        0         13
delivery Y  11        18            0
Zufar Muhamadeev
  • 3,085
  • 5
  • 23
  • 51
  • Because the next distance is computed on the fly, and it depends on the previous location visited. – Leonardo Larrea Nov 21 '17 at 17:07
  • It don`t depend on previous location. I updated answer. – Zufar Muhamadeev Nov 21 '17 at 17:50
  • I edited the question to explain you better my problem. I know that right now, it doesn't depend on the previous location visited but I need it to get a better solution – Leonardo Larrea Nov 21 '17 at 18:52
  • You mean your optimizer use [crow fly](https://en.wikipedia.org/wiki/As_the_crow_flies) distanse? Distance should be calculated using some directions api, it calculates distance using road direction. – Zufar Muhamadeev Nov 21 '17 at 20:17
  • You are right, I'm using road direction to calculate the distances by api – Leonardo Larrea Nov 22 '17 at 19:13
  • If you using road direction and calculate distance matrix to use it for calcuation transport cost - your setup is ok. And you should receive best solution without any other customization. – Zufar Muhamadeev Nov 22 '17 at 19:51