如何设置路线中涉及的固定车辆数量的约束?我在正确实现 StateManager 和 ConstraintManager 时遇到了一些问题,我可以举一些这类实现的例子(StateManager 和 ConstraintManager 的 main 很短)吗?
问问题
483 次
1 回答
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);
}
于 2016-02-05T06:12:13.817 回答