无法通过使用 Jsprit 向服务提供时间窗口来获得正确的优化路线
Posted
技术标签:
【中文标题】无法通过使用 Jsprit 向服务提供时间窗口来获得正确的优化路线【英文标题】:Not able to get the correct optimised route by providing the time windows to services using Jsprit 【发布时间】:2017-04-20 07:26:32 【问题描述】:我正在尝试使用 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 点内完成所有三项工作。我为此创造了问题并得到了结果,但我不明白它给出两条路线的依据是什么,即使车辆的容量尺寸超过完成所需的容量工作。
结果是这样的
【问题讨论】:
【参考方案1】:因为在您的情况下,使用两辆车返回的总成本 (10.28538328578604) 小于使用一辆车 (10.537319187990756)。
如果您想强制它只使用一辆车,您可以将车队规模设置为 FINITE 或为车辆类型设置固定成本。
【讨论】:
谢谢,这很有帮助。以上是关于无法通过使用 Jsprit 向服务提供时间窗口来获得正确的优化路线的主要内容,如果未能解决你的问题,请参考以下文章