设置头码车逻辑修改

This commit is contained in:
joylink_zhangsai 2021-06-02 10:04:46 +08:00
parent b2967dc346
commit f291898071
2 changed files with 39 additions and 14 deletions

View File

@ -241,21 +241,38 @@ public class AtsTrainService {
break; break;
} }
case OTHER: case OTHER:
Set<List<Section>> pathSet = CalculateService.querySectionPaths2Destination(headSection, destinationSection, right, stop); // Set<List<Section>> pathSet = CalculateService.querySectionPaths2Destination(headSection, destinationSection, right, stop);
BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(pathSet, // if (CollectionUtils.isEmpty(pathSet)) {
// pathSet = CalculateService.querySectionPaths2Destination(headSection, destinationSection, !right, stop);
// }
// BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(pathSet,
// String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode()));
// //从找到的路径中筛选出最短路径
// List<Section> path = null;
// if (pathSet.size() == 1) {
// path = pathSet.stream().findAny().get();
// } else if (pathSet.size() > 1) {
// Optional<List<Section>> pathOptional = pathSet.stream()
// .min(Comparator.comparingDouble(availablePath -> availablePath.stream().mapToDouble(Section::getLen).sum()));
// path = pathOptional.get();
// }
// BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotNull(path,
// String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode()));
// supervisedTrain.setHeadPath(path);
RoutePath routePath = null;
List<RoutePath> routePaths = repository.queryRoutePathsByEndAndContainsSection(destinationSection, headSection);
BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(routePaths,
String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode())); String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode()));
//从找到的路径中筛选出最短路径 for (RoutePath rp : routePaths) {
List<Section> path = null; if (rp.isStraight()) {
if (pathSet.size() == 1) { routePath = rp;
path = pathSet.stream().findAny().get();
} else if (pathSet.size() > 1) {
Optional<List<Section>> pathOptional = pathSet.stream()
.min(Comparator.comparingDouble(availablePath -> availablePath.stream().mapToDouble(Section::getLen).sum()));
path = pathOptional.get();
} }
BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotNull(path, }
String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode())); if (routePath == null) {
supervisedTrain.setHeadPath(path); routePath = routePaths.get(0);
}
supervisedTrain.setHeadPath(routePath.getAllSections());
break; break;
default: default:
throw new SimulationException(SimulationExceptionType.System_Fault, String.format("无法识别的目的地码类型[%s]", destinationCodeDefinition.getType())); throw new SimulationException(SimulationExceptionType.System_Fault, String.format("无法识别的目的地码类型[%s]", destinationCodeDefinition.getType()));

View File

@ -418,4 +418,12 @@ public class RoutePath {
public boolean isOccupied() { public boolean isOccupied() {
return end.isOccupied() || sectionList.stream().anyMatch(Section::isOccupied); return end.isOccupied() || sectionList.stream().anyMatch(Section::isOccupied);
} }
public List<Section> getAllSections() {
List<Section> list = new ArrayList<>();
list.add(start);
list.addAll(this.sectionList);
list.add(end);
return list;
}
} }