I have come across a vrp for which Jsprit does not return optimal solution. The code is attached at the end of the post.
Basically I have two vehicles: v1 starts from (0, 0) and needs to return to the end location (2, 0), and v2 starts from (0, 0) and does not need to return to any depot. And there is a service at (1, 0). Thus, if v1 takes the route, the cost will be 2, while, if v2 takes it, the cost will be 1. However, the solution Jsprit returns is that v1 takes it.
Interesting thing is, if I change the end location of v1 to (0, 0) - the same as the start location, the costs won’t change, but the solution will be that v2 takes the route.
It might be related to that. I am not sure. If states are vehicle dependent, I always update states for each vehicle type - similar to the vehicle type dependent time window update. If you need to constraint distance in route by setting max distance then you obviously need to look at each vehicle type having a different start/end location independently (or - as you also found out already, you need to prohibit vehicle switches, i.e. once a route is conducted by vehicle A, it will always be conducted with vehicle A. thus you would save looking at other vehicles here).
Consider evaluating the insertion of service s1 into an empty route, and if v1 is the new vehicle, then totalCosts will be 2, and oldCosts will also be 2 due to the aforementioned line, thus the returned cost is 0; on the other hand, if v2 is the new vehicle, then the returned cost will be 1 (due to this line). Thus, the returned solution will be that v1 takes the route (which is not the optimal solution).
When I change the end location of v1 to (0,0), then the returned cost in the above case will be 2, because oldCosts will be 0. Thus the returned solution will be that v2 takes the route (which is the optimal solution).
So perhaps the aforementioned line should set tp_costs_prevAct_nextAct to 0 in that case?
Thanks a lot, He. I ll check this asap. it would be even better you wrote a unit test, fixed it with your solution and made a pull request? Also you sent me a unit test via discuss which is great. Thanks a lot for it, but why dont you add the unit test to your fork of jsprit and make a pull request. This is much easier for me to keep track and to fix this asap. If you need help with regard to pull request etc., just let me know. I can help .