diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/ars/AtsPlanTrainRouteSelectServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/ars/AtsPlanTrainRouteSelectServiceImpl.java index 49fc4929f..48e8d54e2 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/ars/AtsPlanTrainRouteSelectServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/ars/AtsPlanTrainRouteSelectServiceImpl.java @@ -500,6 +500,9 @@ public class AtsPlanTrainRouteSelectServiceImpl extends AtsRouteSelectService { private List queryAccordingTbStrategy(SimulationDataRepository repository, TrainInfo trainInfo, TripPlan tripPlan) { Section standSection = repository.getByCode(trainInfo.getPlanStandTrack(), Section.class); + if (!standSection.isRouteLock()) { + + } Station station = standSection.getStation(); StationTurnBackStrategyOption strategy = station.getCurrentTurnBackStrategy(); Section tbSection = tripPlan.getEndSection(); @@ -530,6 +533,9 @@ public class AtsPlanTrainRouteSelectServiceImpl extends AtsRouteSelectService { List list = repository.getRoutePaths(standSection, tbSection); boolean right = list.get(0).isRight(); Signal signal = standSection.getSignalOf(right); + if (!this.isApproachSignal(repository, trainInfo, signal)) { + return null; + } List routeList = signal.getRouteList(); List tbRouteList = new ArrayList<>(); for (Route route : routeList) { 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 085acd25b..5bcb638bf 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 @@ -43,7 +43,7 @@ public abstract class AtsRouteSelectService { public Object[] queryTriggers(SimulationDataRepository repository, TrainInfo trainInfo, List routePathList, Boolean right, Section section, Section logicSection) { - Object[] result = new Object[3]; // 结果,0为可触发的进路列表,1为是否存在未触发的进路,2为是否存在未接近的信号机 + Object[] result = new Object[3]; // 结果,0为可触发的进路列表,1为是否存在未触发的进路,2为是否存在未接近的信号机或无法触发信号机 List triggerList = new ArrayList<>(); result[0] = triggerList; result[1] = false; @@ -65,11 +65,15 @@ public abstract class AtsRouteSelectService { if (!ctcLevel && signal.isVirtual()) { continue; } - if ((ctcLevel && signal.isCtcApproachSection(logicSection.getCode())) || - (!ctcLevel && !signal.isVirtual() && signal.isApproachSection(section.getCode()))) { + if (this.isApproachSignal(repository, trainInfo, signal)) { // 是信号机接近区段 if (signal.isNormalOpen()) { //如果信号机已经正常开放,继续查询下一个 - continue; + if (routePath.isPathRoute(signal.getLockedRoute())) { + continue; + } else { + result[2] = true; // 非路径进路办理 + break; + } } else { result[1] = true; for (Route route : routePath.getRouteList()) { @@ -94,4 +98,17 @@ public abstract class AtsRouteSelectService { return result; } + protected boolean isApproachSignal(SimulationDataRepository repository, TrainInfo trainInfo, Signal signal) { + boolean ctcLevel = trainInfo.isCtcLevel(); + Section section = repository.getByCode(trainInfo.getPhysicalSection(), Section.class); + Section logicSection = repository.getByCode(trainInfo.getSection(), Section.class); + if (logicSection.isSwitchAxleCounterSection() || logicSection.isCross()) { + logicSection = section; + } + if ((ctcLevel && signal.isCtcApproachSection(logicSection.getCode())) || + (!ctcLevel && !signal.isVirtual() && signal.isApproachSection(section.getCode()))) { + return true; + } + return false; + } } 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 c84fa4dd6..a5604d824 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 @@ -5,6 +5,7 @@ import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.map.Route; import club.joylink.rtss.simulation.cbtc.data.map.Section; +import club.joylink.rtss.simulation.cbtc.data.map.Signal; import club.joylink.rtss.simulation.cbtc.data.plan.StationPlan; import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; import club.joylink.rtss.simulation.cbtc.data.support.RoutePath; @@ -30,6 +31,7 @@ public class AtsTriggerRouteService { public void tryTrigger(Simulation simulation, TrainInfo trainInfo) { Map atsTriggerRouteMap = trainInfo.getAtsTriggerRouteMap(); if (!atsTriggerRouteMap.isEmpty()) { + SimulationDataRepository repository = simulation.getRepository(); for (Route route : atsTriggerRouteMap.values()) { if (route.isNormalUnlock()) { if (route.isRouteSection(trainInfo.getPhysicalSection())) { @@ -37,6 +39,14 @@ public class AtsTriggerRouteService { continue; } } + if (!route.isAtsControl()) { + atsTriggerRouteMap.remove(route.getCode()); + continue; + } + Signal signal = route.getStart(); + if (!this.planTrainRouteSelectService.isApproachSignal(repository, trainInfo, signal)) { + atsTriggerRouteMap.remove(route.getCode()); + } if (route.isSetting()) { return; } @@ -47,7 +57,6 @@ public class AtsTriggerRouteService { continue; } else if (route.isConflictHandleRunAsPlan()) { if (trainInfo.isPlanTrain()) { - SimulationDataRepository repository = simulation.getRepository(); TripPlan tripPlan = repository.getTripPlan(trainInfo.getServiceNumber(), trainInfo.getTripNumber()); AtsPlanTrainRouteSelectServiceImpl.ConflictInfo conflictInfo = this.planTrainRouteSelectService.checkConflict(repository, trainInfo, tripPlan, route); if (conflictInfo != null) { @@ -76,8 +85,10 @@ public class AtsTriggerRouteService { if (route == null) { // 没有需要触发的进路,返回 return; } - atsTriggerRouteMap.put(route.getCode(), route); - this.trySetRoute(simulation, trainInfo, route); + if (route.isAtsControl()) { // ATS自动排列才处理 + atsTriggerRouteMap.put(route.getCode(), route); + this.trySetRoute(simulation, trainInfo, route); + } } private void trySetRoute(Simulation simulation, TrainInfo trainInfo, Route route) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java index 36635070d..312983e17 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java @@ -24,6 +24,7 @@ import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.fault.FaultGenerator; import club.joylink.rtss.simulation.cbtc.member.MemberManager; import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPLogicLoop; +import club.joylink.rtss.simulation.cbtc.onboard.TrainTargetUpdateService; import club.joylink.rtss.simulation.cbtc.robot.RobotLogicLoop; import club.joylink.rtss.vo.client.runplan.RunPlanVO; import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO; @@ -96,6 +97,8 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic @Autowired private IVirtualRealityPslService iVirtualRealityPslService; + @Autowired + private TrainTargetUpdateService trainTargetUpdateService; @Override public Simulation create(SimulationBuildParams params, String group) { @@ -119,6 +122,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic private void addJobs(Simulation simulation) { atsLogicLoop.addJobs(simulation); atpLogicLoop.addJobs(simulation); + trainTargetUpdateService.addJobs(simulation); vrTrainRunningService.addJobs(simulation); ciLogicLoop.addJobs(simulation); vrDeviceLogicLoop.addJobs(simulation); 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 238b82fba..fa43b7d26 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 @@ -1077,6 +1077,10 @@ public class Section extends MayOutOfOrderDevice { } } + public boolean isJustTurnBackTrack() { + return !this.isNormalStandTrack() && this.isTurnBackTrack(); + } + public enum SectionRoadType { /** * 左行线 diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Signal.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Signal.java index f08d65ad3..5b9e17863 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Signal.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Signal.java @@ -299,23 +299,29 @@ public class Signal extends MayOutOfOrderDevice { List
logicList = path.getLogicList(); if (!CollectionUtils.isEmpty(logicList)) { for (Section logic : logicList) { + if (logic.isSwitchTrack()) { + Switch relSwitch = logic.getRelSwitch(); + SwitchElement switchElement = elementMap.get(relSwitch.getCode()); + if (!relSwitch.isOnPosition(switchElement.isNormal())) { + break; + } + } if (logic.getCode().equals(sectionCode)) { return true; } } } else { for (Section approach : path.getSectionList()) { - if (approach.isSamePhysical(sectionCode)) { - return true; - } else if (approach.isSwitchTrack()) { + if (approach.isSwitchTrack()) { Switch relSwitch = approach.getRelSwitch(); SwitchElement element = elementMap.get(relSwitch.getCode()); - if (relSwitch.isOnPosition(element.isNormal())) { - continue; - } else { + if (!relSwitch.isOnPosition(element.isNormal())) { break; } } + if (approach.isSamePhysical(sectionCode)) { + return true; + } } } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/TrainTargetUpdateService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/TrainTargetUpdateService.java new file mode 100644 index 000000000..f49677839 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/TrainTargetUpdateService.java @@ -0,0 +1,73 @@ +package club.joylink.rtss.simulation.cbtc.onboard; + +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; +import club.joylink.rtss.simulation.cbtc.data.map.Section; +import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Objects; + +@Component +public class TrainTargetUpdateService { + public static final String Model_Name = "TrainTargetUpdate"; + public static final int Rate = 5000; + + public void addJobs(Simulation simulation) { + simulation.addJob(Model_Name, () -> this.run(simulation), Rate); + } + + public void run(Simulation simulation) { + SimulationDataRepository repository = simulation.getRepository(); + List onlineTrain = repository.getOnlineTrainList(); + for (VirtualRealityTrain train : onlineTrain) { + if (train.isStop()) { + continue; + } + Section target = train.getTarget(); + if (target == null) { + continue; + } + Section newTarget = this.queryArriveTarget(train, target); + if (target.equals(newTarget)) { + continue; + } else { + train.setTarget(newTarget); + } + } + } + + private Section queryArriveTarget(VirtualRealityTrain train, Section target) { + SectionPosition headPosition = train.getHeadPosition(); + if (Objects.equals(target, headPosition.getSection())) { + return target; + } + Section newTarget = target; + boolean right = train.isRight(); + Section temp = headPosition.getSection(); + int count = 0; + while (count < 25) { + ++count; + Section nextSection = temp.getNextRunningSectionBaseRealSwitch(right); + if (nextSection == null) { + break; + } + if (Objects.equals(nextSection, target)) {// 找到 + break; + } + if ((target.isNormalStandTrack() && nextSection.isNormalStandTrack()) || + (target.isJustTurnBackTrack() && nextSection.isJustTurnBackTrack()) || + (target.isTransferTrack() && nextSection.isTransferTrack()) && + target.getStation().equals(nextSection.getStation())) { + newTarget = nextSection; + break; + } else { + temp = nextSection; + } + } + return newTarget; + } + +}