如何设置对路线中涉及的固定车辆数量的约束??我在正确实现StateManager和ConstraintManager时遇到了一些问题,我能举一些这种类型的实现的例子吗(StateManager和ConstraintManager带有一个简短的main)?
要设置固定/有限数量的车辆,您需要通过以下方式设置车辆类型:
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);
现在,如果你想设置有限数量的车辆,你必须使用:车辆巡检问题。尺寸。初始化
添加车辆使用:
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);
}