JSprit initial vehicle route doesn't allow inserting a new Shipment when capacities are used

227 views Asked by At

I have a simple initial vehicle route with a pickup and a delivery. I would like to add a "LastMinute" delivery job to the route. Activities and vehicle have a Capacity of 1.

JSprit refuses to schedule the new job. After poking around in the source code, I believe it's because the "Delivery" capacity is negative, but this is not reflected in the state manager. Not positive, though.

If I don't use any capacities, the job can be scheduled. If the initial route uses "Service" instead of "Pickup" and "Deliver" the job can be scheduled, but that prevents accurate capacity enforcement also. I took time windows out to make the example as simple as possible, but the results are the same with time windows in place.

Thoughts?

    final Location depot = Location.newInstance(50.0, 50.0);
    final Location loc1 = Location.newInstance(100.0, 100.0);
    final Location loc2 = Location.newInstance(200.0, 200.0);
    final Capacity cap = Capacity.Builder.newInstance()
            .addDimension(0, 1)
            .build();
    Vehicle v1 = VehicleImpl.Builder
            .newInstance("V1")
            .setStartLocation(depot)
            .setEndLocation(depot)
            .setType(VehicleTypeImpl.Builder
                    .newInstance("VT1")
                    .setCapacityDimensions(cap)
                    .build())
            .build();
    final VehicleRoutingProblem vrp = new VehicleRoutingProblem.Builder()
            .addInitialVehicleRoute(VehicleRoute.Builder.newInstance(v1)
                    .addPickup(Pickup.Builder
                            .newInstance("Pickup1")
                            .setLocation(loc1)
                            .addAllSizeDimensions(cap)
                            .build())
                    .addDelivery(Delivery.Builder
                            .newInstance("Dropoff1")
                            .setLocation(loc2)
                            .addAllSizeDimensions(cap)
                            .build())
                    .build())
            .addJob(Shipment.Builder.newInstance("LastMinute")
                    .setPickupLocation(loc1)
                    .setDeliveryLocation(loc2)
                    .addAllSizeDimensions(cap)
                    .build())
            .setFleetSize(VehicleRoutingProblem.FleetSize.FINITE)
            .build();
    final Collection<VehicleRoutingProblemSolution> solutions = Jsprit.Builder
            .newInstance(vrp)
            .buildAlgorithm()
            .searchSolutions();
    final VehicleRoutingProblemSolution best = Solutions.bestOf(solutions);
    SolutionPrinter.print(vrp, best, SolutionPrinter.Print.VERBOSE);
    assertTrue(best.getUnassignedJobs().isEmpty());
1

There are 1 answers

0
Sam Barnum On

I fixed this by creating a Shipment and adding it to the initial route.

Shipment job = Shipment.Builder.newInstance(...)
VehicleRoute.Builder route = VehicleRoute.Builder.newInstance(...)
route.addPickup(job);
route.addDelivery(job);