限制车辆数量 JSPRIT
Posted
技术标签:
【中文标题】限制车辆数量 JSPRIT【英文标题】:Constraint on number of vehicles JSPRIT 【发布时间】:2015-12-09 17:26:38 【问题描述】:如何设置路线中涉及的固定车辆数量的限制?我在正确实现 StateManager 和 ConstraintManager 时遇到了一些问题,我可以举一些这种类型的实现示例(StateManager 和 ConstraintManager 的 main 很短)吗?
【问题讨论】:
【参考方案1】:要设置固定/有限数量的车辆,您需要通过以下方式设置车辆类型:
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);
【讨论】:
以上是关于限制车辆数量 JSPRIT的主要内容,如果未能解决你的问题,请参考以下文章