设置头码车逻辑修改

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;
}
case OTHER:
Set<List<Section>> pathSet = CalculateService.querySectionPaths2Destination(headSection, destinationSection, right, stop);
BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(pathSet,
// Set<List<Section>> pathSet = CalculateService.querySectionPaths2Destination(headSection, destinationSection, right, stop);
// 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()));
//从找到的路径中筛选出最短路径
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();
for (RoutePath rp : routePaths) {
if (rp.isStraight()) {
routePath = rp;
}
BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotNull(path,
String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode()));
supervisedTrain.setHeadPath(path);
}
if (routePath == null) {
routePath = routePaths.get(0);
}
supervisedTrain.setHeadPath(routePath.getAllSections());
break;
default:
throw new SimulationException(SimulationExceptionType.System_Fault, String.format("无法识别的目的地码类型[%s]", destinationCodeDefinition.getType()));
@ -437,7 +454,7 @@ public class AtsTrainService {
/* 寻找下一目标区段 */
nextTarget = findNextTarget4HeadTrain(simulation, train, repository, headSection, headStation, trainRight, destDefinition);
/* 判断换端并更新目标 */
if (nextTarget != null){
if (nextTarget != null) {
if (nextTarget.getCode().equals(estimatedArriveStandTrack)) {
return;
}

View File

@ -418,4 +418,12 @@ public class RoutePath {
public boolean 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;
}
}