Help me correct my code to get the right solution from jsprit

Hi!

I am learning to use jsprit and I get a solution that I don’t understand.

Here is the entire java code with a distance matrix provided.

When I submit the same problem to the editor/API, it solves it correctly.

What is the problem with my code? I have attached pictures of how it should solve it and it solves it.

It goes to 1, which is correct because of TW, then it goes to 2 and then to 3 which results in more time and distance. (“is” screen)

The editor/API does it correctly: it goes to 1, then 2, then 3. (“should” screen)

Removal of the TW makes it solve the problem correctly, as it should. (nearest stop from vehicle location, then next nearest, then next nearest)

I’m afraid that standalone instance of JSprit does not contains setup of constraints official instance have. There is some fine tunning of setup which has to be done. That could be reason why you get different result from official API and your standalone instance.

@Pavlo_Movchan got the issue, this is happening because by default jsprit does not consider your transport time as the cost for solution building. So you need to add just one line to do so
add
.setCostPerTransportTime(1)
this line while you are building vehicle type.
Means replace
vehicleTypeCar = VehicleTypeImpl.Builder.newInstance(“type_car”)
.setProfile(“car”)
.addCapacityDimension(0, 5)
.build();
with
vehicleTypeCar = VehicleTypeImpl.Builder.newInstance(“type_car”)
.setProfile(“car”)
.addCapacityDimension(0, 5)
.setCostPerTransportTime(1) // Add 1 unit cost for every 1 unit transport time
.build();
Then you will get the desired result.
I have tested your code after my changes and it worked fine.
FYI- @Tomas_Benedikt

1 Like