From f291898071497a4d7b39dfa1b19c3140f6584208 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Wed, 2 Jun 2021 10:04:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=A4=B4=E7=A0=81=E8=BD=A6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/ATS/service/AtsTrainService.java | 45 +++++++++++++------ .../cbtc/data/support/RoutePath.java | 8 ++++ 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java index defef12ac..bf8594087 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java @@ -241,21 +241,38 @@ public class AtsTrainService { break; } case OTHER: - Set> pathSet = CalculateService.querySectionPaths2Destination(headSection, destinationSection, right, stop); - BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(pathSet, +// Set> 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
path = null; +// if (pathSet.size() == 1) { +// path = pathSet.stream().findAny().get(); +// } else if (pathSet.size() > 1) { +// Optional> 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 routePaths = repository.queryRoutePathsByEndAndContainsSection(destinationSection, headSection); + BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(routePaths, String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode())); - //从找到的路径中筛选出最短路径 - List
path = null; - if (pathSet.size() == 1) { - path = pathSet.stream().findAny().get(); - } else if (pathSet.size() > 1) { - Optional> 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; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/RoutePath.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/RoutePath.java index 237cb9ab8..aed2b4728 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/RoutePath.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/RoutePath.java @@ -418,4 +418,12 @@ public class RoutePath { public boolean isOccupied() { return end.isOccupied() || sectionList.stream().anyMatch(Section::isOccupied); } + + public List
getAllSections() { + List
list = new ArrayList<>(); + list.add(start); + list.addAll(this.sectionList); + list.add(end); + return list; + } }