Commit 8cdcaaa1 by chamberone

feat(project-dispatch): 算法添加真实路网时间矩阵

1 parent 05cfb647
......@@ -56,7 +56,7 @@ public class DispatchConstraintProvider implements ConstraintProvider {
protected Constraint technicianBalance(ConstraintFactory factory) {
// 会导致剩余单子集中?
return factory.forEach(Technician.class).filter(technician -> technician.getOffWorkTime() > 1440)
return factory.forEach(Technician.class).filter(technician -> technician.getOffWorkTime() > 1140)
.penalizeLong(HardSoftLongScore.ONE_HARD,
technician -> (long) Math.ceil(technician.getOffWorkTime() / 1440f))
.asConstraint("订单均分");
......@@ -64,7 +64,7 @@ public class DispatchConstraintProvider implements ConstraintProvider {
protected Constraint technicianBalance2(ConstraintFactory factory) {
// 单量不能过少 FIXME
return factory.forEach(Technician.class).filter(technician -> technician.getOffWorkTime() <= 1140)
return factory.forEach(Technician.class).filter(technician -> technician.getOffWorkTime() <= 960)
.penalizeLong(HardSoftLongScore.ONE_HARD,
technician -> 1)
.asConstraint("订单均分2");
......
......@@ -41,16 +41,15 @@ public class Location {
return distanceMap.get(location);
}
/**
* time to the given location in minutes.
* FIXME 这里简化处理没有用时间矩阵 时间=距离/100
*
* @param location other location
* @return time in minutes
*/
public int getPathTimeTo(Location location) {
return (int)(distanceMap.get(location)/100);
}
/**
* time to the given location in minutes.
*
* @param location other location
* @return time in minutes
*/
public int getPathTimeTo(Location location) {
return distanceTimeMap.get(location).intValue();
}
// ************************************************************************
// Complex methods
......
......@@ -59,7 +59,7 @@ public class DispatchServiceImpl implements DispatchService {
@Override
public Result<?> manualDispatch() throws UncheckedIOException, FileNotFoundException {
logger.info("%s", "invoke manualDispatch");
logger.info("{}", "invoke manualDispatch");
// 创建解决方案对象
Map<Integer, String> customerIndexMap = loadCustomerIndex();
......@@ -248,6 +248,23 @@ public class DispatchServiceImpl implements DispatchService {
}
// 初始化时间矩阵
List<String> pathTimeMatrixlines = IOUtils.readLines(new FileInputStream("data/pathTimeMatrix.csv"), "utf-8");
long[][] pathTimeMatrix = new long[customerIndexMap.keySet().size() + 1][customerIndexMap.keySet().size() + 1];
for (int i = 0; i < pathTimeMatrixlines.size(); i++) {
String line = pathTimeMatrixlines.get(i);
String[] temps = line.split(",");
for (int j = 0; j < temps.length; j++) {
// 秒转分钟
pathTimeMatrix[i][j] = (long) (Math.round(Float.parseFloat(temps[j]) / 60));
}
}
for (int i = 0; i < pathTimeMatrix.length; i++) {
Location locationi = locationIndex.get(i + 1);
for (int j = 0; j < pathTimeMatrix[i].length; j++) {
Location locationj = locationIndex.get(j + 1);
locationi.getDistanceTimeMap().put(locationj, pathTimeMatrix[i][j]);
}
}
// 初始化订单服务窗
List<String> customerWindowslines = IOUtils.readLines(new FileInputStream("data/customerWindows.csv"), "utf-8");
......
This diff could not be displayed because it is too large.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!