From 6b7a36aeedc0eca5bb60f08b9ece213d9269023a Mon Sep 17 00:00:00 2001 From: Jade Date: Mon, 13 Dec 2021 11:02:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=AE=B5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/data/SimulationDataRepository.java | 5 +- .../simulation/cbtc/depot/DepotService.java | 111 +++++++++++------- 2 files changed, 74 insertions(+), 42 deletions(-) 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 67c14cbc2..232f3bfc7 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 @@ -17,6 +17,7 @@ import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; import club.joylink.rtss.simulation.cbtc.data.vo.TdtStatusVO; import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import club.joylink.rtss.simulation.cbtc.data.vr.*; +import club.joylink.rtss.simulation.cbtc.depot.DepotService; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.util.StrUtils; @@ -227,9 +228,9 @@ public class SimulationDataRepository { */ private Map> parkingTracksMap = new HashMap<>(); - private List outboundPlanList = new ArrayList<>(); + private List outboundInfoList = new ArrayList<>(); - private List inboundTrainList = new ArrayList<>(); + private List inboundInfoList = new ArrayList<>(); /** * 间隔时间/s diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotService.java index dc9449703..67cd0bbf9 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotService.java @@ -19,10 +19,12 @@ import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService; +import lombok.Getter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; @@ -102,10 +104,15 @@ public class DepotService { continue; } if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) { - if (!simulation.getRepository().getOutboundPlanList().contains(schedulingTrainPlan)) { - simulation.getRepository().getOutboundPlanList().add(schedulingTrainPlan); - schedulingTrainPlan.getOutDepotTrip().dispatched(); - } + schedulingTrainPlan.getOutDepotTrip().dispatched(); + // 保存信息 + VirtualRealityTrain train = simulation.getRepository().getVRByCode(schedulingTrainPlan.getGroupNumber(), VirtualRealityTrain.class); + Section startSection = train.getHeadPosition().getSection(); + Section endSection = schedulingTrainPlan.getOutDepotTrip().getStartSection(); + List routePaths = simulation.getRepository().queryRoutePaths(startSection, endSection); + RoutePath routePath = routePaths.get(0); + DepotInfo depotInfo = new DepotInfo(endSection, train, routePath); + simulation.getRepository().getOutboundInfoList().add(depotInfo); } } } @@ -116,10 +123,15 @@ public class DepotService { */ private void backToParking(Simulation simulation) { for (TrainInfo trainInfo : simulation.getRepository().getTrainInfoMap().values()) { + next: if (trainInfo.isInbound() && trainInfo.isParking()) { VirtualRealityTrain train = simulation.getRepository().getVRByCode(trainInfo.getGroupNumber(), VirtualRealityTrain.class); if (train.getHeadPosition().getSection().isTransferTrack() && train.getTailPosition().getSection().isTransferTrack()) { - simulation.getRepository().getInboundTrainList().add(train); + for (DepotInfo depotInfo : simulation.getRepository().getInboundInfoList()) { + if (depotInfo.getTrain().equals(train)) { + break next; + } + } train.initAsRM(); Section startSection = train.getHeadPosition().getSection(); Section endSection = null; @@ -139,6 +151,13 @@ public class DepotService { break; } train.setTarget(endSection); + List routePaths = simulation.getRepository().queryRoutePaths(startSection, endSection); + if (routePaths == null || routePaths.isEmpty()) { + return; + } + RoutePath routePath = routePaths.get(0); + DepotInfo depotInfo = new DepotInfo(endSection, train, routePath); + simulation.getRepository().getInboundInfoList().add(depotInfo); break; } } @@ -150,36 +169,24 @@ public class DepotService { * @param simulation */ private void settingRouteAndMoving(Simulation simulation) { - for (SchedulingTrainPlan schedulingTrainPlan : simulation.getRepository().getOutboundPlanList()) { - VirtualRealityTrain train = simulation.getRepository().getVRByCode(schedulingTrainPlan.getGroupNumber(), VirtualRealityTrain.class); - moving(simulation, train, schedulingTrainPlan.getOutDepotTrip().getStartSection()); + for (DepotInfo depotInfo : simulation.getRepository().getOutboundInfoList()) { + moving(simulation, depotInfo); } - for (VirtualRealityTrain train : simulation.getRepository().getInboundTrainList()) { - moving(simulation, train, train.getTarget()); + for (DepotInfo depotInfo : simulation.getRepository().getInboundInfoList()) { + moving(simulation, depotInfo); } } - private void moving(Simulation simulation, VirtualRealityTrain train, Section endSection) { - Section startSection = train.getHeadPosition().getSection(); - List routePaths = simulation.getRepository().queryRoutePaths(startSection, endSection); - if (routePaths == null || routePaths.isEmpty()) { - return; - } - RoutePath routePath = routePaths.get(0); - Section pathEnd = routePath.getEnd(); - train.setRobotTargetPosition(new SectionPosition(pathEnd, pathEnd.getStopPointByDirection(routePath.isRight()))); - for (Signal signal : routePath.getSignalList()) { - for (Route route : signal.getRouteList()) { - if (routePath.getRouteList().contains(route)) { - if (route.isSetting()) { - return; - } - if (route.isLock()) { - break; - } - ciRouteService.setRoute(simulation, route); - return; - } + private void moving(Simulation simulation, DepotInfo depotInfo) { + SectionPosition position = new SectionPosition(depotInfo.endSection, depotInfo.endSection.getStopPointByDirection(depotInfo.getRight())); + depotInfo.getTrain().setRobotTargetPosition(position); + if (!depotInfo.getRouteList().isEmpty()) { + Route route = depotInfo.getRouteList().get(0); + if (route.isLock()) { + depotInfo.getRouteList().remove(0); + } + if (!route.isSetting()) { + ciRouteService.setRoute(simulation, route); } } } @@ -189,13 +196,11 @@ public class DepotService { * @param simulation */ private void arriveDestination(Simulation simulation) { - for (Iterator iterator = simulation.getRepository().getOutboundPlanList().iterator(); iterator.hasNext(); ) { - SchedulingTrainPlan schedulingTrainPlan = iterator.next(); - String groupNumber = schedulingTrainPlan.getGroupNumber(); - VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); - if (train.getSpeed() == 0 - && train.getHeadPosition().getSection().equals(schedulingTrainPlan.getOutDepotTrip().getStartSection()) - && train.getTailPosition().getSection().equals(schedulingTrainPlan.getOutDepotTrip().getStartSection())) { + for (Iterator iterator = simulation.getRepository().getOutboundInfoList().iterator(); iterator.hasNext(); ) { + DepotInfo depotInfo = iterator.next(); + VirtualRealityTrain train = depotInfo.getTrain(); + if (train.getSpeed() == 0 && train.getHeadPosition().getSection().equals(depotInfo.getEndSection()) + && train.getTailPosition().getSection().equals(depotInfo.getEndSection())) { // 到达 iterator.remove(); // 升级 @@ -207,8 +212,9 @@ public class DepotService { groupSimulationService.command(simulation, commandInitiateVO, member); } } - for (Iterator iterator = simulation.getRepository().getInboundTrainList().iterator(); iterator.hasNext(); ) { - VirtualRealityTrain train = iterator.next(); + for (Iterator iterator = simulation.getRepository().getInboundInfoList().iterator(); iterator.hasNext(); ) { + DepotInfo depotInfo = iterator.next(); + VirtualRealityTrain train = depotInfo.getTrain(); if (train.getSpeed() == 0 && train.getHeadPosition().getSection().isParkingTrack() && train.getTailPosition().getSection().isParkingTrack()) { // 到达 @@ -217,4 +223,29 @@ public class DepotService { } } } + + @Getter + public static class DepotInfo { + + private final List routeList = new ArrayList<>(); + + private final Section endSection; + + private final VirtualRealityTrain train; + + private final Boolean right; + + public DepotInfo(Section endSection, VirtualRealityTrain train, RoutePath routePath) { + this.endSection = endSection; + this.train = train; + for (Signal signal : routePath.getSignalList()) { + for (Route route : signal.getRouteList()) { + if (routePath.getRouteList().contains(route)) { + routeList.add(route); + } + } + } + this.right = routePath.isRight(); + } + } }