Search code examples
jsprit

jsprit how to add picked-up shipment to a vehicle


I want to recover the VRP problem from a context. In that context some vehicle might already loaded some shipments and en route of delivery. Or maybe it's going to the pickup location for pickup.

I don't want to re-assign those tasks to other vehicles. How can I assign them to the vehicles in that context?

My current workaround is set the picked-up very near to that vehicle's context location and a tight pickup window and a required skill to force the vehicle to pick it up. (this might not always work, so I need a hard writing way to do the set up)

Many thanks!


Solution

  • You can try jsprit's initial route feature. You can refer to this post in jsprit's old mailing list and the example here.

    EDIT:

    essential parts of the answer:

    VehicleRoute initialRoute_withShipmentsAndServices = VehicleRoute.Builder.newInstance(vehicle3)
        .addPickup(shipment1).addPickup(shipment2)
        .addService(service3).addService(service4)
        .addDelivery(shipment2).addDelivery(shipment1)
        .build();
    
    vrpBuilder.addInitialVehicleRoute(initialRoute_withShipmentsAndServices);