无法通过使用 Jsprit 向服务提供时间 windows 来获得正确的优化路线

Not able to get the correct optimised route by providing the time windows to services using Jsprit

我正在尝试使用 Jsprit 获得优化路线。我有三个工作,每个工作都有自己的时间 window.Now 就像这样

            VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder
                .newInstance("smallVehicle")
                .addCapacityDimension(0, 4);

        VehicleType vehicleType = vehicleTypeBuilder
                .build();

        /**
         * Create vehicle.
         */
        Builder vehicleBuilder = VehicleImpl.Builder
                .newInstance("audi");
        vehicleBuilder.setStartLocation(Location.Builder
                .newInstance()
                .setCoordinate(new Coordinate(4, 4))
                .setIndex(0).build());
        vehicleBuilder.setType(vehicleType);
        // Start time and end time of the resource in seconds from 10AM to 8PM.
        vehicleBuilder.setEarliestStart(36000);
        vehicleBuilder.setLatestArrival(72000);
        VehicleImpl vehicle = vehicleBuilder.build();

        /**
         * Create the services those should be accomplished by vehicle.
         */

        Service service1 = Service.Builder
                .newInstance("1(11am-1pm)1hr")
                .addSizeDimension(0, 1)
                .setLocation(
                        Location.Builder
                                .newInstance()
                                .setCoordinate(
                                        new Coordinate(4, 5))
                                .setIndex(1).build())
                // Job should be started at 10AM and ends at 8PM.
                .addTimeWindow(39600,46800)
                // Time required to do job is 4 hours
                .setServiceTime(3600).build();

        Service service2 = Service.Builder
                .newInstance("2(2pm-5pm)1hr")
                .addSizeDimension(0, 1)
                .setLocation(
                        Location.Builder
                                .newInstance()
                                .setCoordinate(
                                        new Coordinate(5, 4))
                                .setIndex(1).build())
                // Time required to complete job is 3 hours.
                .setServiceTime(3600)
                // Job should be started at 2PM and ends at 8PM.
                .addTimeWindow(50400, 61200).build();

        Service service3 = Service.Builder
                .newInstance("3(6pm-8pm)1hr")
                .addSizeDimension(0, 1)
                .setLocation(
                        Location.Builder
                                .newInstance()
                                .setCoordinate(
                                        new Coordinate(5, 8))
                                .setIndex(3).build())
                // Service takes 1 hour to complete.
                .setServiceTime(3600)
                // From 12-1
                .addTimeWindow(64800, 72000).build();

        VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder
                .newInstance();
        vrpBuilder.addVehicle(vehicle);
        vrpBuilder.addJob(service1).addJob(service2)
                .addJob(service3);
        vrpBuilder
                .setFleetSize(VehicleRoutingProblem.FleetSize.INFINITE);

        VehicleRoutingProblem vrp = vrpBuilder.build();

        /**
         * Create the algorithm based on the VRP you have created.
         */
        VehicleRoutingAlgorithm algorithm = Jsprit
                .createAlgorithm(vrp);
Collection<VehicleRoutingProblemSolution> solutions = algorithm
                .searchSolutions();

        /**
         * Get the best route among given sollutions.
         */
        VehicleRoutingProblemSolution bestOne = Solutions
                .bestOf(solutions);

现在车辆必须在 上午 10 点 - 晚上 8 点 内完成所有三项工作。我为此制造了问题并得到了结果,但我不明白它给出 两条路线 的基础是什么,即使车辆的 容量尺寸超过完成工作所需的能力.

结果是这样的

因为在您的案例中使用两辆车 returns 总成本 (10.28538328578604) 比使用一辆车 (10.537319187990756) 少。

如果您想强制它只使用一辆车,您可以将车队规模设置为有限或为车辆类型设置固定成本。