0

我有一个简单的初始车辆路线,包括取货和送货。我想在路线中添加“LastMinute”交付作业。活动和车辆的容量为 1。

JSprit 拒绝安排新作业。在源代码中翻了一下,我认为是因为“交付”能力为负,但这并没有反映在状态管理器中。不过,不是正面的。

如果我不使用任何容量,则可以安排作业。如果初始路线使用“服务”而不是“取货”和“交付”,则可以安排作业,但这也会妨碍准确的容量实施。我抽出时间窗以使示例尽可能简单,但结果与时间窗相同。

想法?

    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());
4

1 回答 1

0

我通过创建一个Shipment并将其添加到初始路由来解决此问题。

Shipment job = Shipment.Builder.newInstance(...)
VehicleRoute.Builder route = VehicleRoute.Builder.newInstance(...)
route.addPickup(job);
route.addDelivery(job);
于 2020-10-30T21:26:31.633 回答