From a3634dda761f5c34325de0ef78bcc18e6493f795 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Tue, 3 Aug 2021 16:58:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=89=88ATS=E8=BF=9B=E8=B7=AF?= =?UTF-8?q?=E9=80=89=E6=8B=A9bug=E4=BF=AE=E6=94=B9=EF=BC=9B=E5=A4=B4?= =?UTF-8?q?=E7=A0=81=E8=BD=A6=E8=AE=A1=E5=88=92=E5=8C=BA=E6=AE=B5=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ars/AtsRouteSelectService.java | 22 +++--- .../service/ars/AtsTriggerRouteService.java | 39 ++++++----- .../stage/AtsHeadTrainStageService.java | 68 ++++++++++++------- .../service/stage/AtsTrainStageHandler.java | 2 +- .../cbtc/data/SimulationDataRepository.java | 5 ++ 5 files changed, 84 insertions(+), 52 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/ars/AtsRouteSelectService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/ars/AtsRouteSelectService.java index 16a4a1c51..f448c2a7f 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/ars/AtsRouteSelectService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/ars/AtsRouteSelectService.java @@ -147,7 +147,7 @@ public abstract class AtsRouteSelectService { } public RouteSelectResult queryTriggerRoutesOfRoutePath(SimulationDataRepository repository, - TrainInfo trainInfo, List routePathList, Section nextPlanSection) { + TrainInfo trainInfo, List routePathList, Section nextPlanSection) { Section section = repository.getByCode(trainInfo.getPhysicalSection(), Section.class); // 列车所在区段 Section planSection = repository.getByCode(trainInfo.getPlanStandTrack(), Section.class); //列车计划区段 List triggerList = new ArrayList<>(); @@ -155,19 +155,24 @@ public abstract class AtsRouteSelectService { RoutePath routePath = this.selectRoutePath(routePathList); // 查找可以触发的进路列表 boolean ctcLevel = trainInfo.isCtcLevel(); - for (Signal signal : routePath.getSignalList()) { + List signalList = routePath.getSignalList(); + for (Signal signal : signalList) { Section signalSection = signal.getSection(); if (routePath.containsSection(section) && routePath.getSectionSort(signalSection) < routePath.getSectionSort(section)) { // 列车已越过此信号机 continue; } - if (signal.hasCiAutoTriggerRoute() || signal.hasFleetModeRoute()) { - break; - } if (!ctcLevel && signal.isVirtual()) { continue; } + if (signal.hasCiAutoTriggerRoute() || signal.hasFleetModeRoute()) { + if (signal.getLockedRoute() != null) { + continue; + } else { + return new RouteSelectResult(null, false); + } + } if (this.isApproachSignal(repository, trainInfo, signal)) { // 是信号机接近区段 if (signal.isNormalOpen()) { @@ -217,11 +222,8 @@ public abstract class AtsRouteSelectService { } } } - } else { - // 列车未接近此信号机 - return new RouteSelectResult(null, false); } - break; + return new RouteSelectResult(null, false); } } return new RouteSelectResult(null, true); @@ -242,7 +244,7 @@ public abstract class AtsRouteSelectService { } @Getter - class RouteSelectResult{ + class RouteSelectResult { private Route route; private boolean allSet; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/ars/AtsTriggerRouteService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/ars/AtsTriggerRouteService.java index c51e76b4a..766a99530 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/ars/AtsTriggerRouteService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/ars/AtsTriggerRouteService.java @@ -29,7 +29,25 @@ public class AtsTriggerRouteService { private CiApiService ciApiService; public void tryTrigger(Simulation simulation, TrainInfo trainInfo) { + if (trainInfo.isManualTrain()) { // 人工车不触发 + return; + } Map atsTriggerRouteMap = trainInfo.getAtsTriggerRouteMap(); + boolean triggerRoute = triggerRoute(simulation, trainInfo, atsTriggerRouteMap); //触发了进路办理 + if (!triggerRoute) { + AtsRouteSelectService routeSelectService = this.getRouteSelectService(trainInfo); + Route route = routeSelectService.select(simulation, trainInfo); + if (route != null && route.isAtsControl()) { + atsTriggerRouteMap.put(route.getCode(), route); + this.trySetRoute(simulation, trainInfo, route); + } + } + } + + /** + * 尝试触发进路办理 + */ + public boolean triggerRoute(Simulation simulation, TrainInfo trainInfo, Map atsTriggerRouteMap) { if (!atsTriggerRouteMap.isEmpty()) { SimulationDataRepository repository = simulation.getRepository(); for (Route route : atsTriggerRouteMap.values()) { @@ -48,7 +66,7 @@ public class AtsTriggerRouteService { atsTriggerRouteMap.remove(route.getCode()); } if (route.isSetting()) { - return; + return true; } if (route.getConflictAlarm() != null) { if (route.isOpen()) { @@ -60,7 +78,7 @@ public class AtsTriggerRouteService { TripPlan tripPlan = repository.getTripPlan(trainInfo.getServiceNumber(), trainInfo.getTripNumber()); AtsPlanTrainRouteSelectServiceImpl.ConflictInfo conflictInfo = this.planTrainRouteSelectService.checkConflict(repository, trainInfo, tripPlan, route); if (conflictInfo != null) { - return; + return true; } else { route.getConflictAlarm().recover(simulation.getCorrectSystemTime()); route.setConflictAlarm(null); @@ -70,25 +88,14 @@ public class AtsTriggerRouteService { } } if (!route.isOpen()) { // 存在未开放的进路,直接返回 - if(!route.isSetting()){ // 进路未办理,继续尝试办理 + if (!route.isSetting()) { // 进路未办理,继续尝试办理 this.trySetRoute(simulation, trainInfo, route); } - return; + return true; } } } - if (trainInfo.isManualTrain()) { // 人工车不触发 - return; - } - AtsRouteSelectService routeSelectService = this.getRouteSelectService(trainInfo); - Route route = routeSelectService.select(simulation, trainInfo); - if (route == null) { // 没有需要触发的进路,返回 - return; - } - if (route.isAtsControl()) { // ATS自动排列才处理 - atsTriggerRouteMap.put(route.getCode(), route); - this.trySetRoute(simulation, trainInfo, route); - } + return false; } private void trySetRoute(Simulation simulation, TrainInfo trainInfo, Route route) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsHeadTrainStageService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsHeadTrainStageService.java index b34dcc48f..7d23d0901 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsHeadTrainStageService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsHeadTrainStageService.java @@ -6,14 +6,18 @@ import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.data.CalculateService; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.map.*; +import club.joylink.rtss.simulation.cbtc.data.support.RoutePath; import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService; import club.joylink.rtss.simulation.cbtc.onboard.ATP.OnboardAtpApiService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.stereotype.Repository; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +import java.util.Comparator; import java.util.List; import java.util.Objects; @@ -90,52 +94,66 @@ public class AtsHeadTrainStageService implements AtsStageService { } private void updatePlanSection(Simulation simulation, TrainInfo trainInfo) { - if (!StringUtils.hasText(trainInfo.getPlanStandTrack())) - return; boolean planRight = trainInfo.getHctPath().isRight(); SimulationDataRepository repository = simulation.getRepository(); SectionPosition headPosition = repository.buildHeadPositionOfTrainInfo(trainInfo); - Section planSection = repository.getByCode(trainInfo.getPlanStandTrack(), Section.class); - //如果还未到达目标轨 Section headSection = headPosition.getSection(); - if (!planSection.equals(headSection) && planSection.isAheadOf(repository, headSection, planRight)) { - return; + if (StringUtils.hasText(trainInfo.getPlanStandTrack())) { + Section planSection = repository.getByCode(trainInfo.getPlanStandTrack(), Section.class); + //如果还未到达目标轨 + if (!planSection.equals(headSection) && planSection.isAheadOf(repository, headSection, planRight)) { + return; + } } + Section nextPlanSection = queryNextPlanSection(repository, headSection, trainInfo); //寻找目标区段 - Section nextPlanSection = queryNextPlanSection(simulation, trainInfo); if (nextPlanSection == null) return; //判断调头 Boolean trainRight = trainInfo.getRight(); if (!nextPlanSection.isAheadOf(repository, headSection, trainRight)) {//下一计划区段不在当前车头方向的前方 - atpService.turnDirectionImmediately(repository.getOnlineTrainBy(trainInfo.getGroupNumber())); //调头 + onboardAtpApiService.startTurnBack(simulation, trainInfo.getGroupNumber(), headSection.getCode()); } //更新计划到站 - SectionPosition stopPosition = new SectionPosition(nextPlanSection, nextPlanSection.getStopPointByDirection(planRight)); - Float distance = CalculateService.calculateDistance(headPosition, stopPosition, planRight); - int runningTime; - if (distance != null) { - runningTime = (int) (distance / (45 / 3.6)); - } else { - runningTime = 180; - } trainInfo.updatePlanInfo(nextPlanSection, null, null); boolean jump = this.atsStandService.isJump(nextPlanSection, trainInfo.getGroupNumber()); + int runningTime = getRunningTime(repository, headSection, nextPlanSection); onboardAtpApiService.updateNextArriveInfo(simulation, trainInfo.getGroupNumber(), nextPlanSection, true, runningTime, jump); } - public static Section queryNextPlanSection(Simulation simulation, TrainInfo trainInfo) { - if (trainInfo.getPlanStandTrack() == null) { - return null; + private int getRunningTime(SimulationDataRepository repository, Section headSection, Section nextPlanSection) { + if (!CollectionUtils.isEmpty(headSection.getStandList())) { + Stand stand = headSection.getStandList().get(0); + if (stand.getRunLevelTime() > 0) { + return stand.getRunLevelTime(); + } } - SimulationDataRepository repository = simulation.getRepository(); + StationRunLevel runLevel = repository.queryRunLevel(headSection, nextPlanSection); + if (runLevel != null) { + return runLevel.getL3(); + } + List routePaths = repository.queryRoutePaths(headSection, nextPlanSection); + if (!CollectionUtils.isEmpty(routePaths)) { + float distance = routePaths.stream().min(Comparator.comparingDouble(RoutePath::calculateDistance)).get().calculateDistance(); + return (int) (distance / (45 / 3.6)); + } + return 120; + } + + public static Section queryNextPlanSection(SimulationDataRepository repository, Section headSection, TrainInfo trainInfo) { List
targetList = trainInfo.getHctPath().getSections(); - Section planSection = repository.getByCode(trainInfo.getPlanStandTrack(), Section.class); - int index = targetList.indexOf(planSection); - if (index == -1 || index == targetList.size() - 1) { - return null; - } else { + int index = targetList.indexOf(headSection); + if (index == -1) { + for (int i = targetList.size() - 1; i >= 0; i--) { + Section section = targetList.get(i); + List routePaths = repository.queryRoutePathsByEndAndContainsSection(section, headSection); + if (!CollectionUtils.isEmpty(routePaths)) { + return section; + } + } + } else if (index < targetList.size() - 1) { return targetList.get(index + 1); } + return null; } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsTrainStageHandler.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsTrainStageHandler.java index 2d1bf8224..19b92828d 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsTrainStageHandler.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsTrainStageHandler.java @@ -63,7 +63,7 @@ public class AtsTrainStageHandler { stageService.handleNormalStandParking(simulation, trainInfo, parkSection); List standList = parkSection.getStandList(); int remainTime = standList.get(0).getRemainTime(); - if (remainTime < 2 && !trainInfo.isDoorOpen() && + if (remainTime < 2000 && !trainInfo.isDoorOpen() && (this.atsStandService.isStandDoorCloseOrInterlockRelease(simulation, parkSection)) && !this.atsStandService.isHoldTrain(parkSection)) { //即将发车 stageService.ready2DepartFromNormalStand(simulation, trainInfo, parkSection); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/SimulationDataRepository.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/SimulationDataRepository.java index e1a4b55b8..4b6dd43a9 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/SimulationDataRepository.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/SimulationDataRepository.java @@ -1336,4 +1336,9 @@ public class SimulationDataRepository { public List getAlarmList() { return new ArrayList<>(this.alarmMap.values()); } + + public StationRunLevel queryRunLevel(Section start, Section end) { + String key = start.getCode() + "-" + end.getCode(); + return this.runLevelMap.get(key); + } }