From a415ee4ad33b327b8bb7c8f284415e8dd94f7d50 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Wed, 10 Mar 2021 19:42:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=A1=8C=E7=BA=BF=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=AD=9B=E9=80=89=E8=BF=9B=E8=B7=AF=E5=88=97=E8=A1=A8=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/build/InterlockBuilder2.java | 47 +++++++++++++------ .../cbtc/data/CalculateService.java | 43 ++++++++++++++++- .../simulation/cbtc/data/map/Section.java | 12 +++++ .../cbtc/data/support/MovementAuthority.java | 18 +++++-- 4 files changed, 101 insertions(+), 19 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/InterlockBuilder2.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/InterlockBuilder2.java index 07d37c946..2ca0a3c9a 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/InterlockBuilder2.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/InterlockBuilder2.java @@ -602,15 +602,14 @@ public class InterlockBuilder2 { runPath = new ArrayList<>(); routes = new ArrayList<>(); //从左端车站开始选择路径 - startSection4RoutePath = screeningSection4DestinationCode(leftStation, leftFrontTurnBack, necessarySectionSet, true); + startSection4RoutePath = selectSection4DestinationCode(leftStation, leftFrontTurnBack, necessarySectionSet, true); runPath.add(startSection4RoutePath); - endSection4RoutePath = screeningSection4DestinationCode(rightStation, rightFrontTurnBack, necessarySectionSet, false); + endSection4RoutePath = selectSection4DestinationCode(rightStation, rightFrontTurnBack, necessarySectionSet, false); //查询并添加路径 RoutePath optimalPath = CalculateService.queryLeastSwitchRoutePath(startSection4RoutePath, endSection4RoutePath, necessarySectionSet, true); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(optimalPath, String.format("从%s到%s的路径未找到", startSection4RoutePath.debugStr(), endSection4RoutePath.debugStr())); runPath.addAll(optimalPath.getSectionList()); - routes.addAll(optimalPath.getRouteList()); //寻找反向的路径 Section t = startSection4RoutePath; startSection4RoutePath = endSection4RoutePath; @@ -620,7 +619,9 @@ public class InterlockBuilder2 { BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(optimalPath2, String.format("从%s到%s的路径未找到", startSection4RoutePath.debugStr(), endSection4RoutePath.debugStr())); runPath.addAll(optimalPath2.getSectionList()); - routes.addAll(optimalPath2.getRouteList()); + //添加进路 + routes.addAll(CalculateService.selectUniqueRoutes(optimalPath, true)); + routes.addAll(CalculateService.selectUniqueRoutes(optimalPath2, true)); break; } case LAST_OPERATION: @@ -630,19 +631,37 @@ public class InterlockBuilder2 { if (!StringUtils.hasText(description)) { errMsgList.add(String.format("目的地码[%s]没有描述", code)); } - if (startSection == null || right == null) { - errMsgList.add(String.format("单向目的地码[%s]没有起始区段或方向", code)); - continue; - } if (section == null) { errMsgList.add(String.format("单向目的地码[%s]没有目标区段", code)); continue; } - RoutePath routePath = CalculateService.queryLeastSwitchRoutePath(startSection, section, necessarySections, right); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(routePath, - String.format("从%s到%s的路径未找到", startSection.debugStr(), section.debugStr())); - runPath = new ArrayList<>(routePath.getSectionList()); - routes = new ArrayList<>(routePath.getRouteList()); + if (startSection != null) { + List
sectionPath = new ArrayList<>(); + sectionPath.add(startSection); + sectionPath.addAll(necessarySections); + sectionPath.add(section); + runPath = new ArrayList<>(); + routes = new ArrayList<>(); + for (int i = 0; i < sectionPath.size() - 1; i++) { + Section start = sectionPath.get(i); + Section end = sectionPath.get(i + 1); + RoutePath routePath; + if (right == null) { + routePath = CalculateService.queryLeastSwitchRoutePath(start, end, null, true); + if (routePath == null) { + routePath = CalculateService.queryLeastSwitchRoutePath(start, end, null, false); + } + } else { + routePath = CalculateService.queryLeastSwitchRoutePath(start, end, null, right); + } + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(routePath, + String.format("从%s到%s的路径未找到", startSection.debugStr(), section.debugStr())); + runPath.add(start); + runPath.addAll(routePath.getSectionList()); + routes.addAll(routePath.getRouteList()); + } + runPath.add(section); + } } case OTHER: if (section == null) { @@ -665,7 +684,7 @@ public class InterlockBuilder2 { * @param preferredSections 优先区段 * @param right 站前折返时是否优先选择右向站台轨 */ - private static Section screeningSection4DestinationCode(Station station, Boolean ftb, Set
preferredSections, boolean right) { + private static Section selectSection4DestinationCode(Station station, Boolean ftb, Set
preferredSections, boolean right) { Section section; if (ftb) { Optional
selectedSectionOptional = preferredSections.stream() diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java index 2f95cf0e4..aa16dfce0 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java @@ -691,7 +691,7 @@ public class CalculateService { } return optimalPath; } - return routePaths.stream().min(Comparator.comparingDouble(RoutePath::getLength)).orElse(null); + return routePaths.stream().min(Comparator.comparingInt(RoutePath::getSwitchQuantity)).orElse(null); } } @@ -1157,6 +1157,46 @@ public class CalculateService { return atoSpeed; } + /** + * 筛选唯一进路。 + * 进路路径的sectionList中可能包含同一信号机下的多个进路,本方法将筛选掉多余的进路 + * + * @param routePath + * @param tb 是否要在进路路径的终点区段折返 + * @return + */ + public static List selectUniqueRoutes(RoutePath routePath, boolean tb) { + List routes = new ArrayList<>(); + List routeList = routePath.getRouteList(); + List
runPath = new ArrayList<>(); + runPath.add(routePath.getStart()); + runPath.addAll(routePath.getSectionList()); + runPath.add(routePath.getEnd()); + for (int i = 0; i < routeList.size(); i++) { + Route route = routeList.get(i); + Route last = i > 0 ? routeList.get(i - 1) : null; + if (last == null) { + routes.add(route); + } else { + if (last.getStart().equals(route.getStart())) { + if (last.getLastRouteSection().equals(routePath.getEnd())) { //进路到达目的地折返轨,优先选择折返进路 + if (!Objects.equals(tb, last.isTurnBack())) { + routes.set(routes.size() - 1, route); + } + } else { //优先选择非折返且无延续保护或延续保护在路径上的 + if (last.isTurnBack() || + (last.getOverlap() != null && !runPath.containsAll(last.getOverlap().getPathList().get(0).getSectionList()))) { + routes.set(routes.size() - 1, route); + } + } + } else { + routes.add(route); + } + } + } + return routes; + } + /** * 计算加速段的时间 */ @@ -1195,4 +1235,5 @@ public class CalculateService { return acceleratedDistance + varyingAcceleratedDistance; } + } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java index 280c1b311..5d2c70be7 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java @@ -1046,6 +1046,18 @@ public class Section extends MayOutOfOrderDevice { section.setCtOccupied(true); return true; } + + @Override + public void fix(MayOutOfOrderDevice device) { + if (this.equals(device.getFault())) { + Section section = (Section) device; + section.setCtOccupied(false); + section.setFault(null); + if (section.isSwitchTrack()) { + section.getRelSwitch().getAllSections().forEach(section1 -> section1.setCtOccupied(false)); + } + } + } } } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/MovementAuthority.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/MovementAuthority.java index 69a615ab8..44a6ff3d7 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/MovementAuthority.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/MovementAuthority.java @@ -48,6 +48,14 @@ public class MovementAuthority { end.getEndPosition()); } + @Override + public String toString() { + return "MovementAuthority{" + + "end=" + end + + ", protectSpeedCurve=" + protectSpeedCurve + + '}'; + } + @Getter public static class End { MapNamedElement device; @@ -75,10 +83,12 @@ public class MovementAuthority { @Override public String toString() { - return String.format("End{" + - "device=[%s(%s)]" + - ", type=[%s]" + - '}', this.device.getName(), this.device.getCode(), this.type); + return "End{" + + "device=" + device + + ", type=" + type + + ", baseSection=" + baseSection + + ", endPosition=" + endPosition + + '}'; } private SectionPosition computeEndPosition(boolean right) {