From ce26b80e6a1612513aed12af7689e5b21acd5d68 Mon Sep 17 00:00:00 2001 From: Jade Date: Wed, 8 Dec 2021 17:55:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=AE=B5=20=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/data/SimulationDataRepository.java | 4 + .../simulation/cbtc/depot/DepotService.java | 164 +++++++++--------- 2 files changed, 88 insertions(+), 80 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 a9f26251b..7a23174ed 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 @@ -227,6 +227,10 @@ public class SimulationDataRepository { */ private Map> parkingTracksMap = new HashMap<>(); + private List outboundPlanList = new ArrayList<>(); + + private List inboundPlanList = 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 2df2a7c27..d260867c1 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 @@ -18,15 +18,14 @@ import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; 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 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; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; @@ -44,11 +43,8 @@ public class DepotService { @Autowired private GroupSimulationService groupSimulationService; - private Map> sectionDispatchMap = new HashMap<>(); - - private List outboundPlanList = new LinkedList<>(); - - private List inboundPlanList = new LinkedList<>(); + @Autowired + private ATPService atpService; public void loadDepotTrain(Simulation simulation) { if (!simulation.getRepository().getConfig().isHandleDepot()) { @@ -75,16 +71,6 @@ public class DepotService { simulation.getRepository().addTrainInfo(trainInfo); } }); - sectionDispatchMap.clear(); - outboundPlanList.clear(); - inboundPlanList.clear(); - simulation.getRepository().getSchedulingTrainPlanList().stream(). - sorted(Comparator.comparing(schedulingTrainPlan -> schedulingTrainPlan.getOutDepotTrip().getStartTime().toSecondOfDay())) - .forEach(schedulingTrainPlan -> { - List planList = sectionDispatchMap - .computeIfAbsent(schedulingTrainPlan.getOutDepotTrip().getStartSection(), key -> new ArrayList<>()); - planList.add(schedulingTrainPlan); - }); } public void addJobs(Simulation simulation) { @@ -99,9 +85,9 @@ public class DepotService { trainOutboundLoadTool.loadOutboundTrain(simulation); } else { timeToDeparture(simulation); + backToParking(simulation); settingRouteAndMoving(simulation); - arriveTransferTrack(simulation); -// backToParking(simulation); + arriveDestination(simulation); } } @@ -111,65 +97,15 @@ public class DepotService { */ private void timeToDeparture(Simulation simulation) { LocalDateTime systemTime = simulation.getSystemTime(); - sectionDispatchMap.forEach((section, list) -> { - for (SchedulingTrainPlan schedulingTrainPlan : list) { - if (schedulingTrainPlan.getOutDepotTrip().isDispatched()) { - continue; - } - if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) { - if (!outboundPlanList.contains(schedulingTrainPlan)) { - outboundPlanList.add(schedulingTrainPlan); - schedulingTrainPlan.getOutDepotTrip().dispatched(); - } - } + for (SchedulingTrainPlan schedulingTrainPlan : simulation.getRepository().getSchedulingTrainPlanList()) { + if (schedulingTrainPlan.getOutDepotTrip().isDispatched()) { + continue; } - }); - } - - /** - * 列车排进路并运行 - * @param simulation - */ - private void settingRouteAndMoving(Simulation simulation) { - for (SchedulingTrainPlan schedulingTrainPlan : outboundPlanList) { - moving(simulation, schedulingTrainPlan.getGroupNumber(), schedulingTrainPlan.getOutDepotTrip().getStartSection()); - } - for (SchedulingTrainPlan schedulingTrainPlan : inboundPlanList) { - moving(simulation, schedulingTrainPlan.getGroupNumber(), schedulingTrainPlan.getInDepotTrip().getEndSection()); - } - } - - /** - * 判断运行列车是否到达转换轨并升级 - * @param simulation - */ - private void arriveTransferTrack(Simulation simulation) { - for (Iterator iterator = outboundPlanList.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())) { - // 到达 - iterator.remove(); - // 升级 - SimulationMember member = simulation.getSimulationMembersByDevice(train).get(0); - Map param = new HashMap<>(); - param.put("preselectionMode", "AM_C"); - CommandInitiateVO commandInitiateVO = new CommandInitiateVO(CommandBO.CommandType.Change_Preselection_Mode, - member.getId(), param); - groupSimulationService.command(simulation, commandInitiateVO, member); - } - } - for (Iterator iterator = inboundPlanList.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.getInDepotTrip().getEndSection())) { - // 到达 - iterator.remove(); + if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) { + if (!simulation.getRepository().getOutboundPlanList().contains(schedulingTrainPlan)) { + simulation.getRepository().getOutboundPlanList().add(schedulingTrainPlan); + schedulingTrainPlan.getOutDepotTrip().dispatched(); + } } } } @@ -187,22 +123,54 @@ public class DepotService { if (!section.isTransferTrack()) { continue; } - for (SchedulingTrainPlan schedulingTrainPlan : sectionDispatchMap.get(section)) { + for (SchedulingTrainPlan schedulingTrainPlan : simulation.getRepository().getSchedulingTrainPlanList()) { if (!schedulingTrainPlan.getInDepotTrip().getEndSection().equals(section)) { continue; } if (!train.getGroupNumber().equals(schedulingTrainPlan.getGroupNumber())) { continue; } - if (!inboundPlanList.contains(schedulingTrainPlan)) { + if (!schedulingTrainPlan.getInDepotTrip().getEndTime().minusMinutes(10) + .isBefore(simulation.getSystemTime().toLocalTime())) { + continue; + } + if (!simulation.getRepository().getInboundPlanList().contains(schedulingTrainPlan)) { train.initAsRM(); - inboundPlanList.add(schedulingTrainPlan); + simulation.getRepository().getInboundPlanList().add(schedulingTrainPlan); break; } } } } + /** + * 列车排进路并运行 + * @param simulation + */ + private void settingRouteAndMoving(Simulation simulation) { + for (SchedulingTrainPlan schedulingTrainPlan : simulation.getRepository().getOutboundPlanList()) { + moving(simulation, schedulingTrainPlan.getGroupNumber(), schedulingTrainPlan.getOutDepotTrip().getStartSection()); + } + for (SchedulingTrainPlan schedulingTrainPlan : simulation.getRepository().getInboundPlanList()) { + Section endSection = schedulingTrainPlan.getInDepotTrip().getEndSection(); + for (Section section : simulation.getRepository().getParkingTracksMap().get(endSection.getStation())) { + if (section.isOccupied()) { + continue; + } + if (section.getLeftSection() == null || section.getRightSection() == null) { + moving(simulation, schedulingTrainPlan.getGroupNumber(), section); + } else if (section.getLeftSection().isParkingTrack() && !section.getLeftSection().isOccupied()) { + moving(simulation, schedulingTrainPlan.getGroupNumber(), section.getLeftSection()); + } else if (section.getRightSection().isParkingTrack() && !section.getRightSection().isOccupied()) { + moving(simulation, schedulingTrainPlan.getGroupNumber(), section.getRightSection()); + } else { + moving(simulation, schedulingTrainPlan.getGroupNumber(), section); + } + break; + } + } + } + private void moving(Simulation simulation, String groupNumber, Section endSection) { VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); Section startSection = train.getHeadPosition().getSection(); @@ -228,4 +196,40 @@ 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())) { + // 到达 + iterator.remove(); + // 升级 + SimulationMember member = simulation.getSimulationMembersByDevice(train).get(0); + Map param = new HashMap<>(); + param.put("preselectionMode", "AM_C"); + CommandInitiateVO commandInitiateVO = new CommandInitiateVO(CommandBO.CommandType.Change_Preselection_Mode, + member.getId(), param); + groupSimulationService.command(simulation, commandInitiateVO, member); + } + } + for (Iterator iterator = simulation.getRepository().getInboundPlanList().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().isParkingTrack() + && train.getTailPosition().getSection().isParkingTrack()) { + // 到达 + iterator.remove(); + atpService.turnDirectionImmediately(train); + } + } + } }