optaplanner - 有问题的简单 TimeWindowedVehicleRoutingSolution 示例
问题描述
我目前正在尝试将 Optaplanner 库实现为一个简单的 TimeWindowedVehicleRoutingSolution 示例。我当前的代码试图尽可能简单,并且主要使用默认的东西,比如vehicleRoutingSolverConfig。
public static void main(String[] args) {
SolverFactory<TimeWindowedVehicleRoutingSolution> solverFactory = SolverFactory.createFromXmlResource("test/vehicleRoutingSolverConfig.xml");
solverFactory.getSolverConfig();
Solver<TimeWindowedVehicleRoutingSolution> solver = null;
try{
solver = solverFactory.buildSolver();
}catch(Exception e){
System.out.println(e.toString());
}
// from 12/07/2018 @ 12:00pm to 12/07/2018 @ 12:30pm
TimeWindowedCustomer hans = new TimeWindowedCustomer();
hans.setReadyTime(1544184000);
hans.setDueTime(1544185800);
// from 12/07/2018 @ 11:00pm to 12/07/2018 @ 11:30pm
TimeWindowedCustomer detlef = new TimeWindowedCustomer();
detlef.setReadyTime(1544180400);
detlef.setDueTime(1544182200);
RoadLocation hansRoad = new RoadLocation();
RoadLocation detlefRoad = new RoadLocation();
RoadLocation hubRoad = new RoadLocation();
HashMap hansMap = new HashMap<RoadLocation, Double>();
//10min
hansMap.put(detlefRoad, 0.6);
//15min
hansMap.put(hubRoad, 0.9);
hansRoad.setTravelDistanceMap(hansMap);
HashMap detlefMap = new HashMap<RoadLocation, Double>();
//10min
detlefMap.put(hansRoad, 0.6);
//20min
detlefMap.put(hubRoad, 1.2);
detlefRoad.setTravelDistanceMap(detlefMap);
HashMap hubMap = new HashMap<RoadLocation, Double>();
//15min
hubMap.put(hansRoad, 0.9);
//20min
hubMap.put(detlefRoad, 1.2);
hubRoad.setTravelDistanceMap(hubMap);
TimeWindowedDepot hub = new TimeWindowedDepot();
hub.setLocation(hubRoad);
hans.setLocation(hansRoad);
detlef.setLocation(detlefRoad);
Vehicle vehicle = new Vehicle();
vehicle.setDepot(hub);
List<Customer> customers = new ArrayList<Customer>();
customers.add(detlef);
customers.add(hans);
List<Depot> depots = new ArrayList<Depot>();
depots.add(hub);
List<Vehicle> vehicles = new ArrayList<Vehicle>();
vehicles.add(vehicle);
List<Location> locations = new ArrayList<Location>();
locations.add(hansRoad);
locations.add(detlefRoad);
locations.add(hubRoad);
hans.setId(1L);
detlef.setId(2L);
hub.setId(3L);
vehicle.setId(4L);
hansRoad.setId(5L);
detlefRoad.setId(6L);
hubRoad.setId(7L);
TimeWindowedVehicleRoutingSolution problem = new TimeWindowedVehicleRoutingSolution();
problem.setCustomerList(customers);
problem.setDepotList(depots);
problem.setVehicleList(vehicles);
problem.setLocationList(locations);
problem.setDistanceType(DistanceType.ROAD_DISTANCE);
TimeWindowedVehicleRoutingSolution solution = solver.solve(problem);
for(Customer c : solution.getCustomerList()) {
TimeWindowedCustomer tc = (TimeWindowedCustomer) c;
System.out.println(tc.getArrivalTime());
}
}
我现在面临的问题是时间窗口并不是真正的硬性规则,因此建议的路线在时间窗口之前到达。我想我只是错过了驱动程序可以进行的中断,并且通过查看代码我认为中断是可能的,只是不是我的配置。所以问题是,如何打破我的例子。
解决方案
推荐阅读
- c# - 使用 `in` 运算符从 id 列表中查找所有 MongoDB 文档
- c# - 身份服务器 4 access_token null
- android - Mockito + Espresso + Dagger2 => 运行 SDK 时的 ClassNotFoundException 低于目标 SDK
- java - 如何在java中将一个对象作为参数传递并将它的一些值与另一个对象进行比较
- unit-testing - 如何对这个用 golang 编写的 promptui 包进行单元测试?
- sql-server - 试图找到长时间运行的 SQL 代码的解决方案,我认为 NESTED SQL 语句是罪魁祸首
- python - Python 2 中的 Python 3 类型提示
- python - 外部嵌套循环 Python 的累加器
- php - TWIG:从字符串中修剪两个字符
- sql-server - 在 xml 节点 SQL Server 上迭代值