| Forum | GitHub | Maps | Blog

Using a custom method instead of a cost matrix array



Is it possible to have a method override in Jsprit that can return the cost and time between the from and to of a route depending on the state of the vehicle at the time, i.e how long it has travelled or its capacity at the time?

I guess this is an alternative to using a cost matrix defined in as an array and get each matrix point using a custom method?



You can create your own implementation of the VehicleRoutingTransportCosts interface, then set it on your VehicleRoutingProblem.


Hi LCenteleghe,

Thanks for the response. I’m examining the implementation of this. Is there a way to find out what the vehicle has, or its capacity dimensions at the point the getTransportCost method is called.

It’s possible to access the vehicle, but i’m not sure how to access the vehicles load or capacity at the point in time the distance gets called.



Hi @tmaner,

You would like to access some info stored in StateManager in the getTransportCost method? It does not look positive to me.

But what you can do is to apply a soft activity constraint. There you can have access to the info you need and impost some cost.

Best regards,