Commit 8f969e73 by chamberone

fix: 修复时间窗错误,修复偏好距离为空bug,修复派工结果更新bug

1 parent bb5efd87
...@@ -138,7 +138,7 @@ public class Technician { ...@@ -138,7 +138,7 @@ public class Technician {
} }
/** /**
* 总路线距离 * 总路线距离(米)
* *
* @return * @return
*/ */
...@@ -156,7 +156,7 @@ public class Technician { ...@@ -156,7 +156,7 @@ public class Technician {
} }
totalDistance += previousLocation.getDistanceTo(this.getVehicleType(), depot.getLocation()); totalDistance += previousLocation.getDistanceTo(this.getVehicleType(), depot.getLocation());
return totalDistance; return totalDistance * 1000;
} }
/** /**
...@@ -168,6 +168,11 @@ public class Technician { ...@@ -168,6 +168,11 @@ public class Technician {
if (customerList.isEmpty()) { if (customerList.isEmpty()) {
return 0; return 0;
} }
// 技术员未设置偏好位置
if(preferredlocationDistanceMap.isEmpty()){
return 0;
}
long totalDistance = 0; long totalDistance = 0;
for (Customer customer : customerList) { for (Customer customer : customerList) {
......
...@@ -15,6 +15,7 @@ import com.dituhui.pea.dispatch.service.ExtractService; ...@@ -15,6 +15,7 @@ import com.dituhui.pea.dispatch.service.ExtractService;
import com.dituhui.pea.dispatch.service.SolveService; import com.dituhui.pea.dispatch.service.SolveService;
import com.dituhui.pea.dispatch.utils.DispatchSolutionUtils; import com.dituhui.pea.dispatch.utils.DispatchSolutionUtils;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.optaplanner.core.api.solver.Solver; import org.optaplanner.core.api.solver.Solver;
...@@ -288,12 +289,17 @@ public class SolveServiceImpl implements SolveService { ...@@ -288,12 +289,17 @@ public class SolveServiceImpl implements SolveService {
// log.debug("组织问题对象, technicianList groupId:{}, batchNo:{}, engineer-code:{} , skills:{}", groupId, batchNo, engineer.getEngineerCode(), String.join(";", skillList)); // log.debug("组织问题对象, technicianList groupId:{}, batchNo:{}, engineer-code:{} , skills:{}", groupId, batchNo, engineer.getEngineerCode(), String.join(";", skillList));
// 距离偏好map // 距离偏好map
Map<String, Long> preferedLoctionDistanceMap = new HashMap<String, Long>(); Map<String, Long> preferedLoctionDistanceMap = new HashMap<String, Long>();
customerList.forEach(customer -> { if (location.getLongitude() > 1 && location.getLatitude() > 1) {
long distance = distanceCalculator.calculateDistance(location, customer.getLocation()); // 设置了偏好位置
preferedLoctionDistanceMap.put(customer.getCode(), distance); customerList.forEach(customer -> {
}); long distance = distanceCalculator.calculateDistance(location, customer.getLocation());
preferedLoctionDistanceMap.put(customer.getCode(), distance);
});
} else {
// 未设置,不参与计算
}
// 硬约束:电动车固定40km上限,其他无限制 // 硬约束:电动车固定40km上限,其他无限制
int maxDistance = engineer.getMaxDistance() * 1000; int maxDistance = engineer.getMaxDistance() * 1000;
...@@ -312,7 +318,13 @@ public class SolveServiceImpl implements SolveService { ...@@ -312,7 +318,13 @@ public class SolveServiceImpl implements SolveService {
} }
Location engineerLocation = new Location(engineer.getId(), engineer.getEngineerCode(), "起点", x, y); Location engineerLocation = new Location(engineer.getId(), engineer.getEngineerCode(), "起点", x, y);
Depot engineerDepot = new Depot(engineer.getId(), engineer.getEngineerCode(), engineerLocation, 60 * 8, 60 * 18); Depot engineerDepot = new Depot(engineer.getId(), engineer.getEngineerCode(), engineerLocation, 60 * 8, 60 * 18);
// FIXME 无锡时间窗数据错误,暂时改成固定值
int[][] timeWindows = engineerCalendarService.timeWindows(engineer.getEngineerCode(), teamId, LocalDateTimeUtil.parseDate(currDay, DateTimeFormatter.ofPattern("yyyy-MM-dd"))); int[][] timeWindows = engineerCalendarService.timeWindows(engineer.getEngineerCode(), teamId, LocalDateTimeUtil.parseDate(currDay, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
System.err.println(engineer.getEngineerName()+" : " + new Gson().toJson(timeWindows));
log.info(engineer.getEngineerName()+" : " + new Gson().toJson(timeWindows));
timeWindows = new int[][] { { 480, 1080 } };
Technician vehicle = new Technician(engineer.getId(), engineer.getEngineerCode(), engineer.getMaxNum(), engineer.getMaxMinute(), maxDistance, engineer.getVehicleType(), engineerDepot, timeWindows, Set.copyOf(skillList), preferedLoctionDistanceMap); Technician vehicle = new Technician(engineer.getId(), engineer.getEngineerCode(), engineer.getMaxNum(), engineer.getMaxMinute(), maxDistance, engineer.getVehicleType(), engineerDepot, timeWindows, Set.copyOf(skillList), preferedLoctionDistanceMap);
technicianList.add(vehicle); technicianList.add(vehicle);
}); });
......
...@@ -151,12 +151,15 @@ public class DispatchSolutionUtils { ...@@ -151,12 +151,15 @@ public class DispatchSolutionUtils {
// 技术员偏好中心点 // 技术员偏好中心点
String preferredlocation = "\"" + solution.getTechnicianList().stream() String preferredlocation = "\"" + solution.getTechnicianList().stream()
.map(c -> c.getPreferredlocation().getX() + "," + c.getPreferredlocation().getY()) .map(c -> (c.getPreferredlocation() == null ? "" : c.getPreferredlocation().getX()) + ","
+ (c.getPreferredlocation() == null ? "" : c.getPreferredlocation().getY()))
.reduce((a, b) -> a + ";" + b).get() + "\""; .reduce((a, b) -> a + ";" + b).get() + "\"";
// 技术员名称 // 技术员名称
String names = "\"" + solution.getTechnicianList().stream() String names = "\"" + solution.getTechnicianList().stream()
.map(c -> c.getPreferredlocation().getX() + "," + c.getPreferredlocation().getY()+ "," + c.getCode()) .map(c -> (c.getPreferredlocation() == null ? "" : c.getPreferredlocation().getX()) + ","
+ (c.getPreferredlocation() == null ? "" : c.getPreferredlocation().getY()) + ","
+ c.getCode())
.reduce((a, b) -> a + ";" + b).get() + "\""; .reduce((a, b) -> a + ";" + b).get() + "\"";
List<String> dispatchMapLines = IOUtils.readLines(new FileInputStream("data/dispatchMap.html"), "GBK"); List<String> dispatchMapLines = IOUtils.readLines(new FileInputStream("data/dispatchMap.html"), "GBK");
......
...@@ -136,7 +136,7 @@ public class RoadDistanceUtils { ...@@ -136,7 +136,7 @@ public class RoadDistanceUtils {
} }
String text = requestGetAK(url, params); String text = requestGetAK(url, params);
System.out.println(url + " : " + gson.toJson(params) + " : " + text); // System.out.println(url + " : " + gson.toJson(params) + " : " + text);
BDResult webResult = gson.fromJson(text, BDResult.class); BDResult webResult = gson.fromJson(text, BDResult.class);
float dis = webResult.getResult().get(0).getDistance().getValue() / 1000F; float dis = webResult.getResult().get(0).getDistance().getValue() / 1000F;
int time = webResult.getResult().get(0).getDuration().getValue(); int time = webResult.getResult().get(0).getDuration().getValue();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!