对JSPRIT车辆数量的约束

时间:2015-12-09 17:26:39

标签: jsprit

如何设置路线中涉及的固定车辆数量的约束?我有一些问题正确实现StateManager和ConstraintManager,我可以有一些这种类型的实现的例子(StateManager和ConstraintManager短主要)?

1 个答案:

答案 0 :(得分:0)

要设置固定/有限数量的车辆,您需要通过以下方式设置车辆类型:

VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2);
VehicleType vehicleType = vehicleTypeBuilder.build();
VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle");
vehicleBuilder.setStartLocation(loc(Coordinate.newInstance(10, 10)));
vehicleBuilder.setType(vehicleType);
VehicleImpl vehicle = vehicleBuilder.build();

然后通过以下方式构建问题:

VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
vrpBuilder.addVehicle(vehicle).setFleetSize(VehicleRoutingProblem.FleetSize.INFINITE);

现在,如果你想设置有限数量的车辆,你必须使用: VehicleRoutingProblem.FleetSize.FINITE

添加车辆使用:

            int nuOfVehicles = 13;
            for (int i = 0; i < nuOfVehicles; i++) {
            VehicleType vehicleType = VehicleTypeImpl.Builder.newInstance(depotCounter + "_type")
                .addCapacityDimension(0, capacity).setCostPerDistance(1.0).build();
            String vehicleId = depotCounter + "_" + (i + 1) + "_vehicle";
            VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance(vehicleId);
            vehicleBuilder.setStartLocation(Location.newInstance(depotCoord.getX(), depotCoord.getY()));
            vehicleBuilder.setType(vehicleType);
            vehicleBuilder.setLatestArrival(maxDuration);
            VehicleImpl vehicle = vehicleBuilder.build();
            vrpBuilder.addVehicle(vehicle);
        }