0

我正在尝试通过使用Jsprit来获得优化的路线。我有三个工作,每个工作都有自己的时间窗口。现在是这样的

            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 点之间完成所有三项工作。我为此创造了问题并得到了结果,但我不明白它提供两条路线的基础是什么,即使车辆的容量尺寸大于完成工作所需的容量

结果是这样的 在此处输入图像描述

4

1 回答 1

1

因为在您的情况下,使用两辆车返回的总成本 (10.28538328578604) 比使用一辆车 (10.537319187990756) 小。

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

于 2017-04-24T03:05:23.870 回答