From 05e0eedb3461f9109201993dc37ffc701120d542 Mon Sep 17 00:00:00 2001 From: Jade Date: Fri, 3 Dec 2021 17:58:56 +0800 Subject: [PATCH 01/21] =?UTF-8?q?=E5=88=97=E8=BD=A6=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=88=B0=E8=BD=A6=E8=BE=86=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/SimulationLifeCycleServiceImpl.java | 6 +++ .../cbtc/build/MapDeviceBuilder.java | 12 ++++- .../cbtc/build/SimulationBuilder.java | 6 +++ .../cbtc/data/SimulationDataRepository.java | 5 +++ .../simulation/cbtc/data/map/MapConfig.java | 3 ++ .../simulation/cbtc/data/map/Section.java | 5 +++ .../cbtc/data/vr/VirtualRealityTrain.java | 5 +++ .../cbtc/depot/DepotLoadService.java | 45 +++++++++++++++++++ .../rtss/vo/map/MapCiGenerateConfig.java | 3 ++ .../rtss/vo/map/graph/MapSectionNewVO.java | 5 +++ .../joylink/rtss/vo/map/graph/MapTrainVO.java | 5 +++ 11 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotLoadService.java 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 eacc1f300..ee4c3b8ed 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java @@ -18,6 +18,7 @@ import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityIbp; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; +import club.joylink.rtss.simulation.cbtc.depot.DepotLoadService; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.SimulationRealDeviceConnectManager; import club.joylink.rtss.simulation.cbtc.device.virtual.VRDeviceLogicLoop; import club.joylink.rtss.simulation.cbtc.device.virtual.VRTrainRunningService; @@ -110,6 +111,9 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic @Autowired private IbpService ibpService; + @Autowired + private DepotLoadService depotLoadService; + @Override public Simulation create(SimulationBuildParams params, String group) { // 构建仿真 @@ -122,6 +126,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic simulation.addMessagePublisher(new IscsStatusPublisher(simulation)); // 初始化设备状态 this.deviceStatusService.init(simulation); + depotLoadService.loadDepotTrain(simulation); // 初始化成员 this.memberManager.init(simulation); // 初始化语音指令 @@ -215,6 +220,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic // } // 初始化设备状态 this.deviceStatusService.init(simulation); + depotLoadService.loadDepotTrain(simulation); // Map oldMemberMap = simulation.getMemberMap(); // Simulation build = SimulationBuilder.build(simulation.getBuildParams()); // simulation.resetFrom(build); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java index a0881fcff..1654aa0e5 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java @@ -99,6 +99,7 @@ public class MapDeviceBuilder { aSwitch.setVirtualSwitch(virtualRealitySwitch); deviceMap.put(virtualRealitySwitch.getCode(), virtualRealitySwitch); }); + Map> parkingTracksMap = mapDataBuildResult.getParkingTracksMap(); // 区段关系 sectionList.forEach(sectionVO -> { Section section = (Section) elementMap.get(sectionVO.getCode()); @@ -167,6 +168,9 @@ public class MapDeviceBuilder { }); } } + if (section.isParkingTrack()) { + parkingTracksMap.computeIfAbsent(section.getStation(), key -> new ArrayList<>()).add(section); + } }); // 计轴区段下的逻辑区段排序 List
physicalSectionList = elementMap.values().stream() @@ -566,6 +570,9 @@ public class MapDeviceBuilder { } MapTrainModelVO trainModelVO = trainModelMap.get(trainVO.getModelCode()); virtualRealityTrain.setLen(trainModelVO.getLength()); + if (!StringUtils.isEmpty(trainVO.getStationCode())) { + virtualRealityTrain.setDepotStation((Station) elementMap.get(trainVO.getStationCode())); + } deviceMap.put(virtualRealityTrain.getGroupNumber(), virtualRealityTrain); }); // 方向杆 @@ -1004,6 +1011,7 @@ public class MapDeviceBuilder { section.setTurnBackTrack(sectionVO.isReentryTrack()); section.setFirstTurnBack(sectionVO.isFirstTurnBack()); section.setTransferTrack(sectionVO.isTransferTrack()); + section.setParkingTrack(sectionVO.isParkingTrack()); if (section.isTransferTrack()) { if (section.isStandTrack()) { errMsgList.add(String.format("区段[%s(%s)]是转换轨,就不能再设置为站台轨", @@ -1022,8 +1030,8 @@ public class MapDeviceBuilder { section.setStopPointLeft(sectionVO.getLeftStopPointOffset()); section.setStopPointRight(sectionVO.getRightStopPointOffset()); } - // 转换轨/折返轨,构建关联车站,站台轨在后面处理站台逻辑里做了 - if (section.isStandTrack() || section.isTransferTrack() || section.isTurnBackTrack()) { + // 转换轨/折返轨/停车轨,构建关联车站,站台轨在后面处理站台逻辑里做了 + if (section.isStandTrack() || section.isTransferTrack() || section.isTurnBackTrack() || section.isParkingTrack()) { if (!StringUtils.hasText(sectionVO.getBelongStation())) { errMsgList.add(String.format("区段[%s(%s)]是站台轨或转换轨或折返轨,却未设置关联车站", sectionVO.getName(), sectionVO.getCode())); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java index 1d9ab270a..8c2664ca8 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java @@ -48,6 +48,8 @@ public class SimulationBuilder { .setOverlapSettingByTrigger(buildParams.getMap().getGraphDataNew().getGenerateConfig().isOverlapSettingByTrigger()); simulation.getRepository().getConfig() .setSharingECStations(buildParams.getMap().getGraphDataNew().getGenerateConfig().getSharingECStations()); + simulation.getRepository().getConfig() + .setHandleDepot(buildParams.getMap().getGraphDataNew().getGenerateConfig().isHandleDepot()); // 地图数据构建 SimulationDeviceBuildResult mapDataBuildResult = checkAndBuildMapData(buildParams.getMap()); // ibp数据构建 @@ -62,6 +64,7 @@ public class SimulationBuilder { // simulation.getRepository().setRunLevelList(mapDataBuildResult.getRunLevelList()); simulation.getRepository().getCatenaryMap().putAll(mapDataBuildResult.getCatenaryMap()); simulation.getRepository().getSectionRespondersMap().putAll(mapDataBuildResult.getSectionRespondersMap()); + simulation.getRepository().setParkingTracksMap(mapDataBuildResult.getParkingTracksMap()); // simulation.getRepository().setParkTimeMap(mapDataBuildResult.getParkTimeMap()); UserConfigDataBuilder.buildRunLevel(simulation.getRepository(), buildParams.getUserRunLevelList(), buildParams.getMap(), mapDataBuildResult.getErrMsgList()); @@ -393,6 +396,9 @@ public class SimulationBuilder { @Setter Map> sectionArriveNearMap; + + Map> parkingTracksMap = new HashMap<>(); + /** * 数据错误信息列表 */ 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 640b5a6cb..395769321 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 @@ -221,6 +221,11 @@ public class SimulationDataRepository { */ private List changeTrips = new CopyOnWriteArrayList<>(); + /** + * 车辆段/停车场 停车轨 + */ + private Map> parkingTracksMap = new HashMap<>(); + /** * 间隔时间/s */ diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/MapConfig.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/MapConfig.java index 2fa1e63df..0d2683715 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/MapConfig.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/MapConfig.java @@ -216,6 +216,9 @@ public class MapConfig { /** 进路默认开启冲突检测 */ private boolean routeDefaultCheckConflict; + /** 处理停车场/车辆段逻辑 */ + private boolean handleDepot; + private Set needConfirmConnectMembers = Stream.of(DISPATCHER, STATION_SUPERVISOR, MAINTAINER, ELECTRIC_DISPATCHER).collect(Collectors.toSet()); 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 a039ab7e3..ff1dccae2 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 @@ -142,6 +142,11 @@ public class Section extends DelayUnlockDevice { */ private boolean transferTrack; + /** + * 是否停车轨 + */ + private boolean parkingTrack; + /** * 目的地码 */ diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java index ef65019cf..b172f24a0 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java @@ -103,6 +103,11 @@ public class VirtualRealityTrain extends VirtualRealityDevice { */ private Float maximumPower = 3583333f; + /** + * 所属停车场/车辆段 + */ + private Station depotStation; + // -----------列车运行属性----------- /** diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotLoadService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotLoadService.java new file mode 100644 index 000000000..80b7d4990 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotLoadService.java @@ -0,0 +1,45 @@ +package club.joylink.rtss.simulation.cbtc.depot; + +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.data.map.Section; +import club.joylink.rtss.simulation.cbtc.data.map.Station; +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 org.springframework.stereotype.Component; + +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +@Component +public class DepotLoadService { + + public void loadDepotTrain(Simulation simulation) { + if (!simulation.getRepository().getConfig().isHandleDepot()) { + return; + } + Map> parkingTracksMap = simulation.getRepository().getParkingTracksMap(); + simulation.getRepository().getAllVrTrain().stream() + .collect(Collectors.groupingBy(VirtualRealityTrain::getDepotStation)) + .forEach((station, trainList) -> { + List
sections = parkingTracksMap.get(station); + // 先加载内侧的停车轨 + sections.sort(Comparator.comparing(section -> + Objects.isNull(section.getLeftSection()) || Objects.isNull(section.getRightSection()))); + boolean right = sections.get(sections.size() - 1).getLeftSection() == null; + for (int i = 0, trainListSize = trainList.size(); i < trainListSize; i++) { + VirtualRealityTrain train = trainList.get(i); + Section section = sections.get(i); + train.initManualTrain(new SectionPosition(section, section.getStopPointByDirection(right)), right); + train.parkingAt(section); + TrainInfo trainInfo = TrainInfo.constructManualTrain(train); + trainInfo.tracking(train); + simulation.getRepository().addOnlineTrain(train); + simulation.getRepository().addTrainInfo(trainInfo); + } + }); + } +} diff --git a/src/main/java/club/joylink/rtss/vo/map/MapCiGenerateConfig.java b/src/main/java/club/joylink/rtss/vo/map/MapCiGenerateConfig.java index 1229c9f65..164d46242 100644 --- a/src/main/java/club/joylink/rtss/vo/map/MapCiGenerateConfig.java +++ b/src/main/java/club/joylink/rtss/vo/map/MapCiGenerateConfig.java @@ -127,6 +127,9 @@ public class MapCiGenerateConfig { // @ApiModelProperty(value = "是否分开生成ATP联锁和地面信号联锁") // private boolean apartGroundAndAtp; + /** 是否处理停车场/车辆段逻辑 */ + private boolean handleDepot; + //--------------------联锁数据生成配置end------------------- } diff --git a/src/main/java/club/joylink/rtss/vo/map/graph/MapSectionNewVO.java b/src/main/java/club/joylink/rtss/vo/map/graph/MapSectionNewVO.java index a4199f4e4..638439270 100644 --- a/src/main/java/club/joylink/rtss/vo/map/graph/MapSectionNewVO.java +++ b/src/main/java/club/joylink/rtss/vo/map/graph/MapSectionNewVO.java @@ -207,6 +207,11 @@ public class MapSectionNewVO { */ private Point transferTrackNamePosition; + /** + * 是否停车轨 + */ + private boolean parkingTrack; + /** * 是否道岔区段 */ diff --git a/src/main/java/club/joylink/rtss/vo/map/graph/MapTrainVO.java b/src/main/java/club/joylink/rtss/vo/map/graph/MapTrainVO.java index 1eec97253..159463f5d 100644 --- a/src/main/java/club/joylink/rtss/vo/map/graph/MapTrainVO.java +++ b/src/main/java/club/joylink/rtss/vo/map/graph/MapTrainVO.java @@ -32,5 +32,10 @@ public class MapTrainVO { @NotBlank(message = "车组号不能为空") private String groupNumber; + /** + * 所属车辆段/停车场 + */ + private String stationCode; + private MapTrainModelVO trainModel; } From ac1e32082cb4ee08932a6f3cae7bb698dcadfb57 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Mon, 6 Dec 2021 15:52:14 +0800 Subject: [PATCH 02/21] =?UTF-8?q?=E3=80=90=E7=BA=BF=E8=B7=AF=E7=9A=84ZC?= =?UTF-8?q?=E5=8F=AA=E6=9C=89=E4=B8=80=E4=B8=AA=E3=80=91=E4=B8=94=E3=80=90?= =?UTF-8?q?ZC=E6=B2=A1=E6=9C=89=E8=AE=BE=E7=BD=AE=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=8C=BA=E6=AE=B5=E3=80=91=E6=97=B6=EF=BC=8C=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=85=B3=E8=81=94=E5=85=A8=E7=BA=BF=E8=AE=A1=E8=BD=B4=E5=8C=BA?= =?UTF-8?q?=E6=AE=B5=EF=BC=88=E4=BB=A5=E5=89=8D=E6=98=AF=E7=89=A9=E7=90=86?= =?UTF-8?q?=E5=8C=BA=E6=AE=B5=EF=BC=89=EF=BC=9B=E4=BF=AE=E6=94=B9=E3=80=90?= =?UTF-8?q?=E5=8C=BA=E6=AE=B5=E6=9C=89ZC=E5=9C=A8=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E3=80=91=E7=9A=84=E5=88=A4=E5=AE=9A=E4=B8=BA=E3=80=90=E6=89=80?= =?UTF-8?q?=E5=B1=9E=E8=AE=A1=E8=BD=B4=E5=8C=BA=E6=AE=B5=E6=9C=89ZC?= =?UTF-8?q?=E5=9C=A8=E5=B7=A5=E4=BD=9C=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/build/MapDeviceBuilder.java | 40 +++++++++++++------ .../simulation/cbtc/data/map/Section.java | 16 ++++---- .../rtss/simulation/cbtc/data/map/ZC.java | 7 ++-- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java index a0881fcff..817fb30e3 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java @@ -314,13 +314,22 @@ public class MapDeviceBuilder { }); /* ZC和区段相互赋值 */ // ZC - if (graphData.getZcList().size() == 1) { + if (graphData.getZcList().size() == 1 && CollectionUtils.isEmpty(graphData.getZcList().get(0).getManagedSectionList())) { + //线路的【ZC只有一个】且【ZC没有设置关联区段】时,自动关联全线计轴区段 MapZcVO mapZcVO = graphData.getZcList().get(0); ZC zc = (ZC) elementMap.get(mapZcVO.getCode()); - physicalSectionList.forEach(section -> { - zc.addSection(section); - section.addZc(zc); - }); + elementMap.values().stream() + .filter(element -> element instanceof Section) + .map(element -> (Section) element) + .filter(Section::isAxleCounterSection) + .forEach(section -> { + zc.addSection(section); + section.addZc(zc); + }); +// physicalSectionList.forEach(section -> { +// zc.addSection(section); +// section.addZc(zc); +// }); } else { graphData.getZcList().forEach(mapZcVO -> { if (mapZcVO.isNoService()) @@ -334,15 +343,20 @@ public class MapDeviceBuilder { Section section = (Section) elementMap.get(sectionCode); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(section, String.format("ZC[%s]关联的区段[%s]不存在", zc.getCode(), sectionCode)); - if (section.isPhysical()) { - section.addZc(zc); - zc.addSection(section); - } else if (section.isSwitchAxleCounterSection() || section.isCross()) { - section.getLogicList().forEach(logic -> { - logic.addZc(zc); - zc.addSection(logic); - }); + Section axleCounterSection = section.findAxleCounterSection(); + if (axleCounterSection != null) { + axleCounterSection.addZc(zc); + zc.addSection(axleCounterSection); } +// if (section.isPhysical()) { +// section.addZc(zc); +// zc.addSection(section); +// } else if (section.isSwitchAxleCounterSection() || section.isCross()) { +// section.getLogicList().forEach(logic -> { +// logic.addZc(zc); +// zc.addSection(logic); +// }); +// } } } }); 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 a039ab7e3..f78945094 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 @@ -12,10 +12,7 @@ import lombok.Getter; import lombok.Setter; import org.springframework.util.CollectionUtils; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.util.*; /** * 区段 @@ -160,7 +157,7 @@ public class Section extends DelayUnlockDevice { /** * 所属zc */ - private List zcs = new ArrayList<>(); + private Set zcs = new HashSet<>(); // ------------------状态属性--------------------- @@ -1143,10 +1140,15 @@ public class Section extends DelayUnlockDevice { * 任意一个zc正常工作 */ public boolean anyZcWorking() { - if (!CollectionUtils.isEmpty(zcs)) { - return zcs.stream().anyMatch(zc -> !zc.isFault()); + Section axleCounterSection = this.findAxleCounterSection(); + if (axleCounterSection != null && !CollectionUtils.isEmpty(axleCounterSection.getZcs())) { + return axleCounterSection.getZcs().stream().anyMatch(zc -> !zc.isFault()); } return false; +// if (!CollectionUtils.isEmpty(zcs)) { +// return zcs.stream().anyMatch(zc -> !zc.isFault()); +// } +// return false; } public void setInvalid(boolean invalid) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/ZC.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/ZC.java index f5d31d790..58f959294 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/ZC.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/ZC.java @@ -1,11 +1,10 @@ package club.joylink.rtss.simulation.cbtc.data.map; import lombok.Getter; -import lombok.Setter; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; import java.util.Objects; +import java.util.Set; /** * 区域控制器 @@ -13,7 +12,7 @@ import java.util.Objects; @Getter public class ZC extends MayOutOfOrderDevice { - private List
sections = new ArrayList<>(); + private Set
sections = new HashSet<>(); public ZC(String code, String name) { super(code, name, DeviceType.ZC); From 7254a0235693cfffce26bc1cad1ae18543e393f8 Mon Sep 17 00:00:00 2001 From: Jade Date: Mon, 6 Dec 2021 16:15:12 +0800 Subject: [PATCH 03/21] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=AE=B5=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/TrainOperateHandler.java | 2 +- .../cbtc/ATS/service/AtsTrainLoadService.java | 7 +- .../cbtc/SimulationLifeCycleServiceImpl.java | 22 ++--- .../cbtc/build/SchedulingBuilder.java | 4 +- .../cbtc/constant/SimulationConstants.java | 3 + .../cbtc/constant/SimulationModule.java | 2 + .../cbtc/data/SimulationDataRepository.java | 6 +- .../cbtc/depot/DepotLoadService.java | 45 ---------- .../simulation/cbtc/depot/DepotService.java | 86 +++++++++++++++++++ 9 files changed, 113 insertions(+), 64 deletions(-) delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotLoadService.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotService.java diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/TrainOperateHandler.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/TrainOperateHandler.java index f64706942..5f517df23 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/TrainOperateHandler.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/TrainOperateHandler.java @@ -50,7 +50,7 @@ public class TrainOperateHandler { SimulationDataRepository repository = simulation.getRepository(); List onlineTrainList = repository.getOnlineTrainList(); VirtualRealityTrain train = repository - .getTrain(serviceNumber, tripNumber); + .getTrain(simulation, serviceNumber, tripNumber); for (VirtualRealityTrain online : onlineTrainList) { if (Objects.equals(train, online)) { throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java index 3f4287d5c..4c0dac1d1 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java @@ -510,7 +510,10 @@ public class AtsTrainLoadService { SimulationDataRepository repository = simulation.getRepository(); for (VirtualRealityTrain train : loadedList) { // 构建监控列车信息 - TrainInfo trainInfo = new TrainInfo(train.getGroupNumber()); + TrainInfo trainInfo = simulation.getRepository().getTrainInfoMap().get(train.getGroupNumber()); + if (trainInfo == null) { + trainInfo = new TrainInfo(train.getGroupNumber()); + } TripPlan tripPlan = repository.getTripPlan(train.getServiceNumber(), train.getTripNumber()); trainInfo.init(tripPlan, repository.getConfig()); List stationPlanList = tripPlan.getPlanList(); @@ -739,7 +742,7 @@ public class AtsTrainLoadService { break; } TripPlan tripPlan = trainLoadParam2.getTripPlan(); - VirtualRealityTrain train = repository.getTrain(tripPlan.getServiceNumber(), tripPlan.getTripNumber()); + VirtualRealityTrain train = repository.getTrain(simulation, tripPlan.getServiceNumber(), tripPlan.getTripNumber()); if (loadedTrainList.contains(train)) { throw new SimulationException(SimulationExceptionType.System_Fault, String.format("加载计划[%s|%s|%s]和[%s|%s|%s]使用列车重复", 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 ee4c3b8ed..7b9d41db2 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java @@ -14,15 +14,18 @@ import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder; import club.joylink.rtss.simulation.cbtc.command.VoiceCommandBO; import club.joylink.rtss.simulation.cbtc.communication.Joylink3DMessageService; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; -import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan; -import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityIbp; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; -import club.joylink.rtss.simulation.cbtc.depot.DepotLoadService; +import club.joylink.rtss.simulation.cbtc.depot.DepotService; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.SimulationRealDeviceConnectManager; import club.joylink.rtss.simulation.cbtc.device.virtual.VRDeviceLogicLoop; import club.joylink.rtss.simulation.cbtc.device.virtual.VRTrainRunningService; -import club.joylink.rtss.simulation.cbtc.event.*; +import club.joylink.rtss.simulation.cbtc.event.SimulationCreateSuccessEvent; +import club.joylink.rtss.simulation.cbtc.event.SimulationErrorEvent; +import club.joylink.rtss.simulation.cbtc.event.SimulationPauseEvent; +import club.joylink.rtss.simulation.cbtc.event.SimulationResetEvent; +import club.joylink.rtss.simulation.cbtc.event.SimulationResumeEvent; +import club.joylink.rtss.simulation.cbtc.event.SimulationRunPlanReloadEvent; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.fault.FaultGenerator; @@ -31,10 +34,6 @@ 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.simulation.rt.iscs.IscsStatusPublisher; -import club.joylink.rtss.util.JsonUtils; -import club.joylink.rtss.vo.client.ibp.IbpData; -import club.joylink.rtss.vo.client.ibp.IbpQueryVO; -import club.joylink.rtss.vo.client.ibp.IbpVO; import club.joylink.rtss.vo.client.runplan.RunPlanVO; import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO; import lombok.extern.slf4j.Slf4j; @@ -112,7 +111,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic private IbpService ibpService; @Autowired - private DepotLoadService depotLoadService; + private DepotService depotService; @Override public Simulation create(SimulationBuildParams params, String group) { @@ -126,7 +125,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic simulation.addMessagePublisher(new IscsStatusPublisher(simulation)); // 初始化设备状态 this.deviceStatusService.init(simulation); - depotLoadService.loadDepotTrain(simulation); + depotService.loadDepotTrain(simulation); // 初始化成员 this.memberManager.init(simulation); // 初始化语音指令 @@ -141,6 +140,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic private void addJobs(Simulation simulation) { atsLogicLoop.addJobs(simulation); atpLogicLoop.addJobs(simulation); + depotService.addJobs(simulation); trainTargetUpdateService.addJobs(simulation); vrTrainRunningService.addJobs(simulation); this.ciLogic.addJobs(simulation); @@ -220,7 +220,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic // } // 初始化设备状态 this.deviceStatusService.init(simulation); - depotLoadService.loadDepotTrain(simulation); + depotService.loadDepotTrain(simulation); // Map oldMemberMap = simulation.getMemberMap(); // Simulation build = SimulationBuilder.build(simulation.getBuildParams()); // simulation.resetFrom(build); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SchedulingBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SchedulingBuilder.java index 14e25b6ee..434e3015e 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SchedulingBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SchedulingBuilder.java @@ -78,9 +78,7 @@ public class SchedulingBuilder { SchedulingTrainPlan schedulingTrainPlan = schedulingPlanList.get(i); String serviceNumber = schedulingTrainPlan.getOutDepotTrip().getServiceNumber(); VirtualRealityTrain train = serverTrainMap.get(serviceNumber); - if (Objects.nonNull(train)) { - schedulingTrainPlan.setGroupNumber(train.getGroupNumber()); - } else { + if (Objects.isNull(train)) { train = trainQueue.poll(); serverTrainMap.put(serviceNumber, train); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationConstants.java b/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationConstants.java index b51987081..c7d5a4a77 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationConstants.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationConstants.java @@ -105,6 +105,9 @@ public interface SimulationConstants { */ int ROUTE_SETTING_TIMEOUT = 20; + /** 停车场/车辆段循环逻辑频率(单位ms) */ + int DEPOT_LOOP_RATE = 1000; + /** * 获取仿真运行计划日期(运营日) * @return diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationModule.java b/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationModule.java index ebd81a5bd..fc438e63d 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationModule.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationModule.java @@ -43,6 +43,8 @@ public enum SimulationModule { DRIVE_POSITION(SimulationConstants.TRAIN_DRIVE_POSITION_SYNC_RATE), /** 剧本演出模块 */ SCRIPT(SimulationConstants.SCRIPT_LOOP_RATE), + /** 停车场/车辆段模块 */ + DEPOT(SimulationConstants.DEPOT_LOOP_RATE), /** 故障模块 */ FAULT(SimulationConstants.FAULT_GENERATE_RATE), 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 395769321..a9f26251b 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 @@ -2,6 +2,7 @@ package club.joylink.rtss.simulation.cbtc.data; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm; +import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.communication.vo.TrainHmiDisplay; import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.plan.RealRun; @@ -586,12 +587,13 @@ public class SimulationDataRepository { return this.serviceTripsMap.get(serviceNumber); } - public VirtualRealityTrain getTrain(String serviceNumber, String tripNumber) { + public VirtualRealityTrain getTrain(Simulation simulation, String serviceNumber, String tripNumber) { VirtualRealityTrain train = this.queryTrain(serviceNumber, tripNumber); if (Objects.isNull(train)) { throw new SimulationException(SimulationExceptionType.System_Fault, String.format("服务车次[%s|%s]找不到派班的列车", serviceNumber, tripNumber)); - } else if (this.usedTrainMap.containsKey(train.getGroupNumber())) { + } else if (!simulation.getRepository().getConfig().isHandleDepot() + && this.usedTrainMap.containsKey(train.getGroupNumber())) { throw new SimulationException(SimulationExceptionType.System_Fault, String.format("列车[%s]已经被使用", train.getGroupNumber())); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotLoadService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotLoadService.java deleted file mode 100644 index 80b7d4990..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotLoadService.java +++ /dev/null @@ -1,45 +0,0 @@ -package club.joylink.rtss.simulation.cbtc.depot; - -import club.joylink.rtss.simulation.cbtc.Simulation; -import club.joylink.rtss.simulation.cbtc.data.map.Section; -import club.joylink.rtss.simulation.cbtc.data.map.Station; -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 org.springframework.stereotype.Component; - -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; - -@Component -public class DepotLoadService { - - public void loadDepotTrain(Simulation simulation) { - if (!simulation.getRepository().getConfig().isHandleDepot()) { - return; - } - Map> parkingTracksMap = simulation.getRepository().getParkingTracksMap(); - simulation.getRepository().getAllVrTrain().stream() - .collect(Collectors.groupingBy(VirtualRealityTrain::getDepotStation)) - .forEach((station, trainList) -> { - List
sections = parkingTracksMap.get(station); - // 先加载内侧的停车轨 - sections.sort(Comparator.comparing(section -> - Objects.isNull(section.getLeftSection()) || Objects.isNull(section.getRightSection()))); - boolean right = sections.get(sections.size() - 1).getLeftSection() == null; - for (int i = 0, trainListSize = trainList.size(); i < trainListSize; i++) { - VirtualRealityTrain train = trainList.get(i); - Section section = sections.get(i); - train.initManualTrain(new SectionPosition(section, section.getStopPointByDirection(right)), right); - train.parkingAt(section); - TrainInfo trainInfo = TrainInfo.constructManualTrain(train); - trainInfo.tracking(train); - simulation.getRepository().addOnlineTrain(train); - simulation.getRepository().addTrainInfo(trainInfo); - } - }); - } -} 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 new file mode 100644 index 000000000..b4c9afa26 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotService.java @@ -0,0 +1,86 @@ +package club.joylink.rtss.simulation.cbtc.depot; + +import club.joylink.rtss.simulation.cbtc.CI.device.CiRouteService; +import club.joylink.rtss.simulation.cbtc.GroupSimulationService; +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.command.CommandBO; +import club.joylink.rtss.simulation.cbtc.command.CommandInitiateVO; +import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; +import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; +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.Station; +import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan; +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.data.vr.VirtualRealityTrain; +import club.joylink.rtss.simulation.cbtc.member.SimulationMember; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +@Component +public class DepotService { + + @Autowired + private CiRouteService ciRouteService; + + @Autowired + private GroupSimulationService groupSimulationService; + + public void loadDepotTrain(Simulation simulation) { + if (!simulation.getRepository().getConfig().isHandleDepot()) { + return; + } + Map> parkingTracksMap = simulation.getRepository().getParkingTracksMap(); + simulation.getRepository().getAllVrTrain().stream() + .collect(Collectors.groupingBy(VirtualRealityTrain::getDepotStation)) + .forEach((station, trainList) -> { + List
sections = parkingTracksMap.get(station); + // 先加载内侧的停车轨 + sections.sort(Comparator.comparing(section -> + Objects.isNull(section.getLeftSection()) || Objects.isNull(section.getRightSection()))); + boolean right = sections.get(sections.size() - 1).getLeftSection() == null; + for (int i = 0, trainListSize = trainList.size(); i < trainListSize; i++) { + VirtualRealityTrain train = trainList.get(i); + Section section = sections.get(i); + train.initManualTrain(new SectionPosition(section, section.getStopPointByDirection(right)), right); + train.parkingAt(section); + train.initAsRM(); + TrainInfo trainInfo = TrainInfo.constructManualTrain(train); + trainInfo.tracking(train); + simulation.getRepository().addOnlineTrain(train); + simulation.getRepository().addTrainInfo(trainInfo); + } + }); + } + + public void addJobs(Simulation simulation) { + simulation.addJob(SimulationModule.DEPOT.name(), () -> this.run(simulation), SimulationConstants.DEPOT_LOOP_RATE); + } + + private void run(Simulation simulation) { + SchedulingTrainPlan schedulingTrainPlan = simulation.getRepository().getSchedulingTrainPlanList().get(0); + LocalDateTime systemTime = simulation.getSystemTime(); + if (!schedulingTrainPlan.getOutDepotTrip().getStartTime().plusMinutes(20).isAfter(systemTime.toLocalTime())) { + return; + } + String groupNumber = schedulingTrainPlan.getGroupNumber(); + VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); + List routePaths = simulation.getRepository().queryRoutePathsByStart(train.getHeadPosition().getSection()); + RoutePath routePath = routePaths.get(0); + for (Route route : routePath.getRouteList()) { + ciRouteService.setRoute(simulation, route); + } + CommandInitiateVO commandInitiateVO = new CommandInitiateVO(CommandBO.CommandType.Drive_To, schedulingTrainPlan.getDriverCode(), null); + List memberList = simulation.getSimulationMembersByDevice(train); + groupSimulationService.command(simulation, commandInitiateVO, memberList.get(0)); + } +} From eb56128954d55384b16a1ee1f882a25cc15d55a0 Mon Sep 17 00:00:00 2001 From: xiazengbin Date: Mon, 6 Dec 2021 18:06:01 +0800 Subject: [PATCH 04/21] =?UTF-8?q?SimulationBuilder.build=E4=B8=AD=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=8A=A0=E8=BD=BD=E8=BD=A6=E8=BE=86=E6=AE=B5route=20p?= =?UTF-8?q?ath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/build/SimulationBuilder.java | 893 ++++++++++-------- 1 file changed, 477 insertions(+), 416 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java index 8c2664ca8..efd9fa1f6 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java @@ -1,416 +1,477 @@ -package club.joylink.rtss.simulation.cbtc.build; - -import club.joylink.rtss.entity.Ibp; -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.plan.TerminalDeparturePlan; -import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; -import club.joylink.rtss.simulation.cbtc.data.support.RoutePath; -import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityDevice; -import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityIbp; -import club.joylink.rtss.util.JsonUtils; -import club.joylink.rtss.vo.client.ibp.IbpData; -import club.joylink.rtss.vo.client.runplan.RunPlanVO; -import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO; -import club.joylink.rtss.vo.map.logic.MapStationParkingTimeVO; -import club.joylink.rtss.vo.map.MapVO; -import club.joylink.rtss.vo.map.RealLineConfigVO; -import lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; -import org.springframework.util.CollectionUtils; - -import javax.swing.text.Element; -import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -@Slf4j -public class SimulationBuilder { - - /** - * 构造仿真对象 - */ - public static Simulation build(String group, SimulationBuildParams buildParams) { - Simulation simulation = new Simulation(group); - simulation.setBuildParams(buildParams); - if (Objects.nonNull(buildParams.getLoginUserInfo())) { - simulation.setProject(buildParams.getLoginUserInfo().getProject()); - } - // 线路配置参数 - simulation.getRepository().setConfig(buildConfig(buildParams.getMap().getConfigVO())); - simulation.getRepository().getConfig() - .setRouteLikeHa1(buildParams.getMap().getGraphDataNew().getGenerateConfig().isLikeHa1()); - simulation.getRepository().getConfig() - .setOverlapSettingByTrigger(buildParams.getMap().getGraphDataNew().getGenerateConfig().isOverlapSettingByTrigger()); - simulation.getRepository().getConfig() - .setSharingECStations(buildParams.getMap().getGraphDataNew().getGenerateConfig().getSharingECStations()); - simulation.getRepository().getConfig() - .setHandleDepot(buildParams.getMap().getGraphDataNew().getGenerateConfig().isHandleDepot()); - // 地图数据构建 - SimulationDeviceBuildResult mapDataBuildResult = checkAndBuildMapData(buildParams.getMap()); - // ibp数据构建 - buildIbpData(mapDataBuildResult, buildParams.getMap().getIbpList()); - simulation.getRepository().setDeviceMap(mapDataBuildResult.getDeviceMap()); - simulation.getRepository().setSectionArriveNearMap(mapDataBuildResult.sectionArriveNearMap); - simulation.getRepository().setVrDeviceMap(mapDataBuildResult.getVrDeviceMap()); -// simulation.getRepository().setRouteUnitMap(mapDataBuildResult.getRouteUnitMap()); - simulation.getRepository().setRoutePathMap(mapDataBuildResult.getRoutePathMap()); - simulation.getRepository().setDestinationMap(mapDataBuildResult.getDestinationMap()); - simulation.getRepository().setRoutingList(mapDataBuildResult.getRoutingList()); -// simulation.getRepository().setRunLevelList(mapDataBuildResult.getRunLevelList()); - simulation.getRepository().getCatenaryMap().putAll(mapDataBuildResult.getCatenaryMap()); - simulation.getRepository().getSectionRespondersMap().putAll(mapDataBuildResult.getSectionRespondersMap()); - simulation.getRepository().setParkingTracksMap(mapDataBuildResult.getParkingTracksMap()); -// simulation.getRepository().setParkTimeMap(mapDataBuildResult.getParkTimeMap()); - UserConfigDataBuilder.buildRunLevel(simulation.getRepository(), buildParams.getUserRunLevelList(), - buildParams.getMap(), mapDataBuildResult.getErrMsgList()); - UserConfigDataBuilder.buildParkTime(simulation.getRepository(), buildParams.getUserParkTimeList(), - buildParams.getMap(), mapDataBuildResult.getErrMsgList()); - if (!CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 存在数据异常 - mapDataBuildResult.getErrMsgList().forEach(errMsg -> log.warn(String.format("地图数据异常:%s", errMsg))); - simulation.setMapDataError(true); - simulation.addDataErrMsgs(mapDataBuildResult.getErrMsgList()); - } - // 加载运行图 - checkAndLoadRunPlan(simulation, buildParams.getRunPlan()); - // 加载派班计划 - checkAndLoadSchedulingPlan(simulation, buildParams.getSchedulingPlan()); - return simulation; - } - - private static void buildIbpData(SimulationDeviceBuildResult mapDataBuildResult, List ibpList) { - if (CollectionUtils.isEmpty(ibpList)) - return; - Map deviceMap = mapDataBuildResult.getDeviceMap(); - Map vrDeviceMap = mapDataBuildResult.getVrDeviceMap(); - Map ibpMap = ibpList.stream().collect(Collectors.toMap(Ibp::getStationCode, Function.identity())); - List collect = deviceMap.values().stream() - .filter(element -> MapElement.DeviceType.STATION.equals(element.getDeviceType())) - .map(element -> (Station) element).collect(Collectors.toList()); - collect.forEach(station -> { - //构建添加IBP - Ibp ibp = ibpMap.get(station.getCode()); - if (ibp == null) - ibp = ibpMap.get(null); - if (ibp != null) { - IbpData ibpData = JsonUtils.read(ibp.getData(), IbpData.class); - VirtualRealityIbp vrIbp = new VirtualRealityIbp(station.getCode() + "_IBP", station.getName() + "_IBP", ibpData, station); - station.setVrIbp(vrIbp); - deviceMap.put(vrIbp.getCode(), vrIbp); - vrDeviceMap.put(vrIbp.getCode(), vrIbp); - } - }); - } - - private static boolean isOverlapSettingByTrigger(Map deviceMap) { - for (MapElement mapElement : deviceMap.values()) { - if (mapElement.getDeviceType().equals(MapElement.DeviceType.OVERLAP)) { - if (!CollectionUtils.isEmpty(((RouteOverlap) mapElement).getTriggerPathList())) { - return true; - } else { - return false; - } - } - } - return false; - } - - /** - * 检查并加载派班计划 - * @param simulation - * @param schedulingPlan - */ - public static void checkAndLoadSchedulingPlan(Simulation simulation, SchedulingPlanNewVO schedulingPlan) { - if (simulation.isMapDataError() || simulation.isPlanDataError()) { - return; - } - if (Objects.isNull(schedulingPlan)) { - // 如果没有加载计划,生成默认的加载计划 - if (!simulation.isMapDataError() && simulation.isPlanLoaded() && !simulation.isPlanDataError()) { // 地图数据和运行计划加载成功的情况下 - log.info(String.format("地图[%s(%s)]没有派班计划,生成默认派班计划使用", - simulation.getBuildParams().getMap().getName(), - simulation.getBuildParams().getMap().getId())); - SchedulingBuilder.generateSchedulingPlan(simulation); - } - } else { - SchedulingBuilder.loadSchedulingPlan(simulation, schedulingPlan); - } - } - - /** - * 检查并加载运行计划 - * @param simulation - * @param runPlan - * @return - */ - public static void checkAndLoadRunPlan(Simulation simulation, RunPlanVO runPlan) { - if (simulation.isMapDataError()) { - // 地图逻辑数据有问题,不加载 - log.info(String.format("仿真地图[%s(%s)]数据有问题,不执行运行计划加载", - simulation.getBuildParams().getMap().getName(), - simulation.getBuildParams().getMap().getId())); - return; - } - if (Objects.nonNull(runPlan)) { - RunPlanBuilder.RunPlanBuildResult runPlanBuildResult = - RunPlanBuilder.buildRunDiagram(simulation.getRepository().getDeviceMap(), runPlan); - simulation.setPlanLoaded(true); - if (!CollectionUtils.isEmpty(runPlanBuildResult.getErrMsgList())) { // 数据异常 - runPlanBuildResult.getErrMsgList().forEach(errMsg -> log.warn(String.format("运行图数据异常:%s", errMsg))); - simulation.setPlanDataError(true); - simulation.addDataErrMsgs(runPlanBuildResult.getErrMsgList()); - } else { - simulation.getRepository().setServiceTripsMap(runPlanBuildResult.getServerTripMap()); - simulation.getRepository().setStandTripMap(runPlanBuildResult.getStandTripMap()); - simulation.getRepository().setEndTripMap(runPlanBuildResult.getEndTripMap()); - // 校验运行计划和路径单元 - List errMsgList = checkRunPlanAndBuildLostRoutePaths(runPlanBuildResult.getServerTripMap(), - simulation.getRepository().getRoutePathMap()); - if (!errMsgList.isEmpty()) { - simulation.setMapDataError(true); - simulation.addDataErrMsgs(errMsgList); - } -// // 构建终端发车计划 -// TerminalPlanBuildResult terminalPlanBuildResult = buildTerminalPlan(simulation.getRepository(), runPlanBuildResult.getServerTripMap()); -// if (!CollectionUtils.isEmpty(terminalPlanBuildResult.getErrMsgList())) { -// simulation.setMapDataError(true); -// simulation.addDataErrMsgs(terminalPlanBuildResult.getErrMsgList()); -// } else { -// simulation.getRepository().setTerminalDeparturePlanMap(terminalPlanBuildResult.getTerminalPlanMap()); -// } - } - } else { - simulation.addDataErrMsg("运行图为空"); - } - } - - public static List checkRunPlanAndBuildLostRoutePaths(Map> serverTripMap, - Map> routePathMap) { - Map errMsgMap = new HashMap<>(); - for (List tripPlanList : serverTripMap.values()) { - for (TripPlan tripPlan : tripPlanList) { - List
allViaSectionList = tripPlan.getAllViaStoppedSectionList(); - for (int i = 1; i < allViaSectionList.size(); i++) { - Section start = allViaSectionList.get(i - 1); - Section end = allViaSectionList.get(i); - String key = RoutePath.buildKey(start, end); - if (!routePathMap.containsKey(key)) { - // 路径不存在,尝试构建 - List routePaths = CalculateService.queryRoutePathsOnDirection(start, end, tripPlan.isRight(), 10); - if (CollectionUtils.isEmpty(routePaths)) { - // 计划方向路径未找到,反向尝试 - routePaths = CalculateService.queryRoutePathsOnDirection(start, end, !tripPlan.isRight(), 10); - } - if (CollectionUtils.isEmpty(routePaths)) { - // 依然未找到 - errMsgMap.put(key, String.format("从[%s]->[%s]无法到达,请检查运行图和联锁数据是否正确", - start.debugStr(), end.debugStr())); - } else { - // 找到,保存 - log.info(String.format("运行图从[%s]->[%s]没有站间运行数据,根据路径查询找到并生成默认的路径单元", - start.debugStr(), end.debugStr())); - for (RoutePath routePath : routePaths) { - routePath.calculateDistance(); - } - routePathMap.put(key, routePaths); - } - } - } - } - } - return new ArrayList<>(errMsgMap.values()); - } - -// private static List checkRunPlanAndBuildLostRouteUnit(Map> serverTripMap, -// Map routeUnitMap) { -// Map errMsgMap = new HashMap<>(); -// for (List tripPlanList : serverTripMap.values()) { -// for (TripPlan tripPlan : tripPlanList) { -// List
allViaSectionList = tripPlan.getAllViaSectionList(); -// for (int i = 1; i < allViaSectionList.size(); i++) { -// Section start = allViaSectionList.get(i - 1); -// Section end = allViaSectionList.get(i); -// String key = RouteUnit.buildKey(start, end); -// if (!routeUnitMap.containsKey(key)) { -// // 尝试构建 -// List errList = new ArrayList<>(); -// RouteUnit routeUnit = InterlockBuilder2.findAndBuildRouteUnit(start, end, tripPlan.isRight(), errList); -// if (Objects.isNull(routeUnit)) { -// // 反向再尝试 -// routeUnit = InterlockBuilder2.findAndBuildRouteUnit(start, end, !tripPlan.isRight(), errList); -// } -// if (Objects.nonNull(routeUnit)) { -// log.warn(String.format("运行图从[%s(%s)]到[%s(%s)]没有站间运行数据,根据路径查询找到并生成默认的路径单元", -// start.getName(), start.getCode(), end.getName(), end.getCode())); -// routeUnitMap.put(key, routeUnit); -// } else { -// errMsgMap.put(key, String.format("从[%s(%s)]到[%s(%s)]无法到达,请检查运行图和联锁数据是否正确", -// start.getName(), start.getCode(), end.getName(), end.getCode())); -// } -// } -// } -// } -// } -// return new ArrayList<>(errMsgMap.values()); -// } - - private static TerminalPlanBuildResult buildTerminalPlan(SimulationDataRepository repository, Map> serverTripMap) { - TerminalPlanBuildResult result = new TerminalPlanBuildResult(); - List errMsgList = result.getErrMsgList(); - Map terminalPlanMap = result.getTerminalPlanMap(); - serverTripMap.values().forEach(tripPlanList -> - tripPlanList.forEach(tripPlan -> { - Section startSection = tripPlan.getStartSection(); - TerminalDeparturePlan terminalPlan = terminalPlanMap.get(startSection.getCode()); - if (Objects.isNull(terminalPlan)) { - terminalPlan = new TerminalDeparturePlan(startSection.getCode()); - terminalPlanMap.put(startSection.getCode(), terminalPlan); - } - terminalPlan.addTripPlan(tripPlan); - })); - terminalPlanMap.values().forEach(terminalDeparturePlan -> - terminalDeparturePlan.getPlanList().sort((plan1, plan2) -> { - return plan1.getStartTime().compareTo(plan2.getStartTime()); - })); - return result; - } - - public static MapConfig buildConfig(RealLineConfigVO configVO) { - MapConfig mapConfig = new MapConfig(); - if (Objects.nonNull(configVO)) { - mapConfig.copyConfigBy(configVO); - } - return mapConfig; - } - - /** - * 地图基础数据检查和构建 - * @param map - * @return - */ - public static SimulationDeviceBuildResult checkAndBuildBasicMapData(MapVO map) { - SimulationDeviceBuildResult mapDataBuildResult = new SimulationDeviceBuildResult(); - MapDeviceBuilder.checkAndBuildMapDeviceData(map.getGraphDataNew(), mapDataBuildResult); - return mapDataBuildResult; - } - - /** - * 地图数据逻辑检查和构建 - * - * @param map - * @return - */ - public static SimulationDeviceBuildResult checkAndBuildMapData(MapVO map) { - SimulationDeviceBuildResult mapDataBuildResult = new SimulationDeviceBuildResult(); - MapDeviceBuilder.checkAndBuildMapDeviceData(map.getGraphDataNew(), mapDataBuildResult); - if (CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 基础数据没有问题,再构建逻辑数据 -// InterlockBuilder.checkAndBuildMapCILogicData(map.getLogicDataNew(), mapDataBuildResult); - InterlockBuilder2.checkAndBuildMapCILogicData(map.getLogicDataNew(), mapDataBuildResult); - List parkingTimeList = map.getLogicDataNew().getParkingTimeList(); - if (CollectionUtils.isEmpty(parkingTimeList)) { - mapDataBuildResult.errMsgList.add("无停站时间数据"); - } - } - return mapDataBuildResult; - } - - public static SimulationDeviceBuildResult checkAndBuildMapDeviceData(MapVO map) { - SimulationDeviceBuildResult mapDataBuildResult = new SimulationDeviceBuildResult(); - MapDeviceBuilder.checkAndBuildMapDeviceData(map.getGraphDataNew(), mapDataBuildResult); - return mapDataBuildResult; - } - - @Getter - public static class TerminalPlanBuildResult { - private Map terminalPlanMap; - - private List errMsgList; - - public TerminalPlanBuildResult() { - this.terminalPlanMap = new HashMap<>(); - this.errMsgList = new ArrayList<>(); - } - } - - /** - * 地图数据构建结果 - */ - @Getter - public static class SimulationDeviceBuildResult { - /** - * 地图设备map - * key-设备code - * val-设备对象 - */ - private Map deviceMap; - - /** - * 虚拟真实设备map - * key-设备code - * val-虚拟真实设备对象 - */ - private Map vrDeviceMap; - - /** - * 目的地码定义map - * key-目的地码code - */ - private Map destinationMap = new HashMap<>(); - - /** - * 交路列表 - */ - @Setter - private List routingList; - - /** - * 站间运行等级列表 - */ - @Setter - private List runLevelList; - -// /** -// * 路径单元map -// */ -// private Map routeUnitMap; - - /** - * 路径map - */ - private Map> routePathMap; - - /** - * 接触网map - * key-sectionCode - */ - private Map> catenaryMap = new HashMap<>(); - - private Map> sectionRespondersMap; - - /** 默认停站时间map */ - private Map parkTimeMap = new HashMap<>(); - - @Setter - Map> sectionArriveNearMap; - - Map> parkingTracksMap = new HashMap<>(); - - /** - * 数据错误信息列表 - */ - private List errMsgList; - - public SimulationDeviceBuildResult() { - this.deviceMap = new HashMap<>(); - this.vrDeviceMap = new HashMap<>(); -// this.routeUnitMap = new HashMap<>(); - this.routePathMap = new HashMap<>(); - this.sectionRespondersMap = new HashMap<>(); - this.errMsgList = new ArrayList<>(); - } - } -} +package club.joylink.rtss.simulation.cbtc.build; + +import club.joylink.rtss.entity.Ibp; +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.plan.TerminalDeparturePlan; +import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; +import club.joylink.rtss.simulation.cbtc.data.support.RoutePath; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityDevice; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityIbp; +import club.joylink.rtss.util.JsonUtils; +import club.joylink.rtss.vo.client.ibp.IbpData; +import club.joylink.rtss.vo.client.runplan.RunPlanVO; +import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO; +import club.joylink.rtss.vo.map.logic.MapStationParkingTimeVO; +import club.joylink.rtss.vo.map.MapVO; +import club.joylink.rtss.vo.map.RealLineConfigVO; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.util.CollectionUtils; + +import javax.swing.text.Element; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Slf4j +public class SimulationBuilder { + + /** + * 构造仿真对象 + */ + public static Simulation build(String group, SimulationBuildParams buildParams) { + Simulation simulation = new Simulation(group); + simulation.setBuildParams(buildParams); + if (Objects.nonNull(buildParams.getLoginUserInfo())) { + simulation.setProject(buildParams.getLoginUserInfo().getProject()); + } + // 线路配置参数 + simulation.getRepository().setConfig(buildConfig(buildParams.getMap().getConfigVO())); + simulation.getRepository().getConfig() + .setRouteLikeHa1(buildParams.getMap().getGraphDataNew().getGenerateConfig().isLikeHa1()); + simulation.getRepository().getConfig() + .setOverlapSettingByTrigger(buildParams.getMap().getGraphDataNew().getGenerateConfig().isOverlapSettingByTrigger()); + simulation.getRepository().getConfig() + .setSharingECStations(buildParams.getMap().getGraphDataNew().getGenerateConfig().getSharingECStations()); + simulation.getRepository().getConfig() + .setHandleDepot(buildParams.getMap().getGraphDataNew().getGenerateConfig().isHandleDepot()); + // 地图数据构建 + SimulationDeviceBuildResult mapDataBuildResult = checkAndBuildMapData(buildParams.getMap()); + // ibp数据构建 + buildIbpData(mapDataBuildResult, buildParams.getMap().getIbpList()); + simulation.getRepository().setDeviceMap(mapDataBuildResult.getDeviceMap()); + simulation.getRepository().setSectionArriveNearMap(mapDataBuildResult.sectionArriveNearMap); + simulation.getRepository().setVrDeviceMap(mapDataBuildResult.getVrDeviceMap()); +// simulation.getRepository().setRouteUnitMap(mapDataBuildResult.getRouteUnitMap()); + simulation.getRepository().setRoutePathMap(mapDataBuildResult.getRoutePathMap()); + simulation.getRepository().setDestinationMap(mapDataBuildResult.getDestinationMap()); + simulation.getRepository().setRoutingList(mapDataBuildResult.getRoutingList()); +// simulation.getRepository().setRunLevelList(mapDataBuildResult.getRunLevelList()); + simulation.getRepository().getCatenaryMap().putAll(mapDataBuildResult.getCatenaryMap()); + simulation.getRepository().getSectionRespondersMap().putAll(mapDataBuildResult.getSectionRespondersMap()); + simulation.getRepository().setParkingTracksMap(mapDataBuildResult.getParkingTracksMap()); +// simulation.getRepository().setParkTimeMap(mapDataBuildResult.getParkTimeMap()); + UserConfigDataBuilder.buildRunLevel(simulation.getRepository(), buildParams.getUserRunLevelList(), + buildParams.getMap(), mapDataBuildResult.getErrMsgList()); + UserConfigDataBuilder.buildParkTime(simulation.getRepository(), buildParams.getUserParkTimeList(), + buildParams.getMap(), mapDataBuildResult.getErrMsgList()); + if (!CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 存在数据异常 + mapDataBuildResult.getErrMsgList().forEach(errMsg -> log.warn(String.format("地图数据异常:%s", errMsg))); + simulation.setMapDataError(true); + simulation.addDataErrMsgs(mapDataBuildResult.getErrMsgList()); + } + // 加载运行图 + checkAndLoadRunPlan(simulation, buildParams.getRunPlan()); + // 加载派班计划 + checkAndLoadSchedulingPlan(simulation, buildParams.getSchedulingPlan()); + // 加载车辆段route path + loadDepotInOutRoutePath(simulation); + return simulation; + } + + /** + * 加载进出depot的route path + */ + private static void loadDepotInOutRoutePath(Simulation simulation) { + final Map> srps = simulation.getRepository().getRoutePathMap(); + // 仿真车辆段站台停车轨列表 + Map> parkingTracksMap = simulation.getRepository().getParkingTracksMap(); + if (CollectionUtils.isEmpty(parkingTracksMap)) { + return; + } + parkingTracksMap.forEach((station, secs) -> { + if (station.isDepot()) {// 车站为车辆段 + List
transferList = station.getTransferList();// 转换轨列表 + if(!CollectionUtils.isEmpty(transferList)) { + transferList.forEach(transSec->{ + //停车轨到转换轨 + secs.forEach(parkSec->{ + final String rpKey=RoutePath.buildKey(parkSec, transSec); + List nrp=tryFindRoutePathByDirection(parkSec, transSec,10); + List srp=srps.get(rpKey); + if(null==srp) { + srp=new ArrayList(); + srps.put(rpKey, srp); + } + if(!CollectionUtils.isEmpty(nrp)) { + srp.addAll(nrp); + } + }); + //转换轨到停车轨 + secs.forEach(parkSec->{ + final String rpKey=RoutePath.buildKey(transSec, parkSec); + List nrp=tryFindRoutePathByDirection(transSec, parkSec,10); + List srp=srps.get(rpKey); + if(null==srp) { + srp=new ArrayList(); + srps.put(rpKey, srp); + } + if(!CollectionUtils.isEmpty(nrp)) { + srp.addAll(nrp); + } + }); + }); + }else { + log.info("仿真数据有问题,车辆段[{}]没有转换轨",station.getName()); + } + } + }); + } + /** + *当方向未知时,起点终点不变,不同方向搜索route path + */ + private static List tryFindRoutePathByDirection(Section start, Section end,int iterTimes) { + List r= CalculateService.queryRoutePathsOnDirection(start, end,true, iterTimes); + if(!CollectionUtils.isEmpty(r)) { + return r; + }else { + return CalculateService.queryRoutePathsOnDirection(start, end,false, iterTimes); + } + } + private static void buildIbpData(SimulationDeviceBuildResult mapDataBuildResult, List ibpList) { + if (CollectionUtils.isEmpty(ibpList)) + return; + Map deviceMap = mapDataBuildResult.getDeviceMap(); + Map vrDeviceMap = mapDataBuildResult.getVrDeviceMap(); + Map ibpMap = ibpList.stream().collect(Collectors.toMap(Ibp::getStationCode, Function.identity())); + List collect = deviceMap.values().stream() + .filter(element -> MapElement.DeviceType.STATION.equals(element.getDeviceType())) + .map(element -> (Station) element).collect(Collectors.toList()); + collect.forEach(station -> { + //构建添加IBP + Ibp ibp = ibpMap.get(station.getCode()); + if (ibp == null) + ibp = ibpMap.get(null); + if (ibp != null) { + IbpData ibpData = JsonUtils.read(ibp.getData(), IbpData.class); + VirtualRealityIbp vrIbp = new VirtualRealityIbp(station.getCode() + "_IBP", station.getName() + "_IBP", ibpData, station); + station.setVrIbp(vrIbp); + deviceMap.put(vrIbp.getCode(), vrIbp); + vrDeviceMap.put(vrIbp.getCode(), vrIbp); + } + }); + } + + private static boolean isOverlapSettingByTrigger(Map deviceMap) { + for (MapElement mapElement : deviceMap.values()) { + if (mapElement.getDeviceType().equals(MapElement.DeviceType.OVERLAP)) { + if (!CollectionUtils.isEmpty(((RouteOverlap) mapElement).getTriggerPathList())) { + return true; + } else { + return false; + } + } + } + return false; + } + + /** + * 检查并加载派班计划 + * @param simulation + * @param schedulingPlan + */ + public static void checkAndLoadSchedulingPlan(Simulation simulation, SchedulingPlanNewVO schedulingPlan) { + if (simulation.isMapDataError() || simulation.isPlanDataError()) { + return; + } + if (Objects.isNull(schedulingPlan)) { + // 如果没有加载计划,生成默认的加载计划 + if (!simulation.isMapDataError() && simulation.isPlanLoaded() && !simulation.isPlanDataError()) { // 地图数据和运行计划加载成功的情况下 + log.info(String.format("地图[%s(%s)]没有派班计划,生成默认派班计划使用", + simulation.getBuildParams().getMap().getName(), + simulation.getBuildParams().getMap().getId())); + SchedulingBuilder.generateSchedulingPlan(simulation); + } + } else { + SchedulingBuilder.loadSchedulingPlan(simulation, schedulingPlan); + } + } + + /** + * 检查并加载运行计划 + * @param simulation + * @param runPlan + * @return + */ + public static void checkAndLoadRunPlan(Simulation simulation, RunPlanVO runPlan) { + if (simulation.isMapDataError()) { + // 地图逻辑数据有问题,不加载 + log.info(String.format("仿真地图[%s(%s)]数据有问题,不执行运行计划加载", + simulation.getBuildParams().getMap().getName(), + simulation.getBuildParams().getMap().getId())); + return; + } + if (Objects.nonNull(runPlan)) { + RunPlanBuilder.RunPlanBuildResult runPlanBuildResult = + RunPlanBuilder.buildRunDiagram(simulation.getRepository().getDeviceMap(), runPlan); + simulation.setPlanLoaded(true); + if (!CollectionUtils.isEmpty(runPlanBuildResult.getErrMsgList())) { // 数据异常 + runPlanBuildResult.getErrMsgList().forEach(errMsg -> log.warn(String.format("运行图数据异常:%s", errMsg))); + simulation.setPlanDataError(true); + simulation.addDataErrMsgs(runPlanBuildResult.getErrMsgList()); + } else { + simulation.getRepository().setServiceTripsMap(runPlanBuildResult.getServerTripMap()); + simulation.getRepository().setStandTripMap(runPlanBuildResult.getStandTripMap()); + simulation.getRepository().setEndTripMap(runPlanBuildResult.getEndTripMap()); + // 校验运行计划和路径单元 + List errMsgList = checkRunPlanAndBuildLostRoutePaths(runPlanBuildResult.getServerTripMap(), + simulation.getRepository().getRoutePathMap()); + if (!errMsgList.isEmpty()) { + simulation.setMapDataError(true); + simulation.addDataErrMsgs(errMsgList); + } +// // 构建终端发车计划 +// TerminalPlanBuildResult terminalPlanBuildResult = buildTerminalPlan(simulation.getRepository(), runPlanBuildResult.getServerTripMap()); +// if (!CollectionUtils.isEmpty(terminalPlanBuildResult.getErrMsgList())) { +// simulation.setMapDataError(true); +// simulation.addDataErrMsgs(terminalPlanBuildResult.getErrMsgList()); +// } else { +// simulation.getRepository().setTerminalDeparturePlanMap(terminalPlanBuildResult.getTerminalPlanMap()); +// } + } + } else { + simulation.addDataErrMsg("运行图为空"); + } + } + + public static List checkRunPlanAndBuildLostRoutePaths(Map> serverTripMap, + Map> routePathMap) { + Map errMsgMap = new HashMap<>(); + for (List tripPlanList : serverTripMap.values()) { + for (TripPlan tripPlan : tripPlanList) { + List
allViaSectionList = tripPlan.getAllViaStoppedSectionList(); + for (int i = 1; i < allViaSectionList.size(); i++) { + Section start = allViaSectionList.get(i - 1); + Section end = allViaSectionList.get(i); + String key = RoutePath.buildKey(start, end); + if (!routePathMap.containsKey(key)) { + // 路径不存在,尝试构建 + List routePaths = CalculateService.queryRoutePathsOnDirection(start, end, tripPlan.isRight(), 10); + if (CollectionUtils.isEmpty(routePaths)) { + // 计划方向路径未找到,反向尝试 + routePaths = CalculateService.queryRoutePathsOnDirection(start, end, !tripPlan.isRight(), 10); + } + if (CollectionUtils.isEmpty(routePaths)) { + // 依然未找到 + errMsgMap.put(key, String.format("从[%s]->[%s]无法到达,请检查运行图和联锁数据是否正确", + start.debugStr(), end.debugStr())); + } else { + // 找到,保存 + log.info(String.format("运行图从[%s]->[%s]没有站间运行数据,根据路径查询找到并生成默认的路径单元", + start.debugStr(), end.debugStr())); + for (RoutePath routePath : routePaths) { + routePath.calculateDistance(); + } + routePathMap.put(key, routePaths); + } + } + } + } + } + return new ArrayList<>(errMsgMap.values()); + } + +// private static List checkRunPlanAndBuildLostRouteUnit(Map> serverTripMap, +// Map routeUnitMap) { +// Map errMsgMap = new HashMap<>(); +// for (List tripPlanList : serverTripMap.values()) { +// for (TripPlan tripPlan : tripPlanList) { +// List
allViaSectionList = tripPlan.getAllViaSectionList(); +// for (int i = 1; i < allViaSectionList.size(); i++) { +// Section start = allViaSectionList.get(i - 1); +// Section end = allViaSectionList.get(i); +// String key = RouteUnit.buildKey(start, end); +// if (!routeUnitMap.containsKey(key)) { +// // 尝试构建 +// List errList = new ArrayList<>(); +// RouteUnit routeUnit = InterlockBuilder2.findAndBuildRouteUnit(start, end, tripPlan.isRight(), errList); +// if (Objects.isNull(routeUnit)) { +// // 反向再尝试 +// routeUnit = InterlockBuilder2.findAndBuildRouteUnit(start, end, !tripPlan.isRight(), errList); +// } +// if (Objects.nonNull(routeUnit)) { +// log.warn(String.format("运行图从[%s(%s)]到[%s(%s)]没有站间运行数据,根据路径查询找到并生成默认的路径单元", +// start.getName(), start.getCode(), end.getName(), end.getCode())); +// routeUnitMap.put(key, routeUnit); +// } else { +// errMsgMap.put(key, String.format("从[%s(%s)]到[%s(%s)]无法到达,请检查运行图和联锁数据是否正确", +// start.getName(), start.getCode(), end.getName(), end.getCode())); +// } +// } +// } +// } +// } +// return new ArrayList<>(errMsgMap.values()); +// } + + private static TerminalPlanBuildResult buildTerminalPlan(SimulationDataRepository repository, Map> serverTripMap) { + TerminalPlanBuildResult result = new TerminalPlanBuildResult(); + List errMsgList = result.getErrMsgList(); + Map terminalPlanMap = result.getTerminalPlanMap(); + serverTripMap.values().forEach(tripPlanList -> + tripPlanList.forEach(tripPlan -> { + Section startSection = tripPlan.getStartSection(); + TerminalDeparturePlan terminalPlan = terminalPlanMap.get(startSection.getCode()); + if (Objects.isNull(terminalPlan)) { + terminalPlan = new TerminalDeparturePlan(startSection.getCode()); + terminalPlanMap.put(startSection.getCode(), terminalPlan); + } + terminalPlan.addTripPlan(tripPlan); + })); + terminalPlanMap.values().forEach(terminalDeparturePlan -> + terminalDeparturePlan.getPlanList().sort((plan1, plan2) -> { + return plan1.getStartTime().compareTo(plan2.getStartTime()); + })); + return result; + } + + public static MapConfig buildConfig(RealLineConfigVO configVO) { + MapConfig mapConfig = new MapConfig(); + if (Objects.nonNull(configVO)) { + mapConfig.copyConfigBy(configVO); + } + return mapConfig; + } + + /** + * 地图基础数据检查和构建 + * @param map + * @return + */ + public static SimulationDeviceBuildResult checkAndBuildBasicMapData(MapVO map) { + SimulationDeviceBuildResult mapDataBuildResult = new SimulationDeviceBuildResult(); + MapDeviceBuilder.checkAndBuildMapDeviceData(map.getGraphDataNew(), mapDataBuildResult); + return mapDataBuildResult; + } + + /** + * 地图数据逻辑检查和构建 + * + * @param map + * @return + */ + public static SimulationDeviceBuildResult checkAndBuildMapData(MapVO map) { + SimulationDeviceBuildResult mapDataBuildResult = new SimulationDeviceBuildResult(); + MapDeviceBuilder.checkAndBuildMapDeviceData(map.getGraphDataNew(), mapDataBuildResult); + if (CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 基础数据没有问题,再构建逻辑数据 +// InterlockBuilder.checkAndBuildMapCILogicData(map.getLogicDataNew(), mapDataBuildResult); + InterlockBuilder2.checkAndBuildMapCILogicData(map.getLogicDataNew(), mapDataBuildResult); + List parkingTimeList = map.getLogicDataNew().getParkingTimeList(); + if (CollectionUtils.isEmpty(parkingTimeList)) { + mapDataBuildResult.errMsgList.add("无停站时间数据"); + } + } + return mapDataBuildResult; + } + + public static SimulationDeviceBuildResult checkAndBuildMapDeviceData(MapVO map) { + SimulationDeviceBuildResult mapDataBuildResult = new SimulationDeviceBuildResult(); + MapDeviceBuilder.checkAndBuildMapDeviceData(map.getGraphDataNew(), mapDataBuildResult); + return mapDataBuildResult; + } + + @Getter + public static class TerminalPlanBuildResult { + private Map terminalPlanMap; + + private List errMsgList; + + public TerminalPlanBuildResult() { + this.terminalPlanMap = new HashMap<>(); + this.errMsgList = new ArrayList<>(); + } + } + + /** + * 地图数据构建结果 + */ + @Getter + public static class SimulationDeviceBuildResult { + /** + * 地图设备map + * key-设备code + * val-设备对象 + */ + private Map deviceMap; + + /** + * 虚拟真实设备map + * key-设备code + * val-虚拟真实设备对象 + */ + private Map vrDeviceMap; + + /** + * 目的地码定义map + * key-目的地码code + */ + private Map destinationMap = new HashMap<>(); + + /** + * 交路列表 + */ + @Setter + private List routingList; + + /** + * 站间运行等级列表 + */ + @Setter + private List runLevelList; + +// /** +// * 路径单元map +// */ +// private Map routeUnitMap; + + /** + * 路径map + */ + private Map> routePathMap; + + /** + * 接触网map + * key-sectionCode + */ + private Map> catenaryMap = new HashMap<>(); + + private Map> sectionRespondersMap; + + /** 默认停站时间map */ + private Map parkTimeMap = new HashMap<>(); + + @Setter + Map> sectionArriveNearMap; + + Map> parkingTracksMap = new HashMap<>(); + + /** + * 数据错误信息列表 + */ + private List errMsgList; + + public SimulationDeviceBuildResult() { + this.deviceMap = new HashMap<>(); + this.vrDeviceMap = new HashMap<>(); +// this.routeUnitMap = new HashMap<>(); + this.routePathMap = new HashMap<>(); + this.sectionRespondersMap = new HashMap<>(); + this.errMsgList = new ArrayList<>(); + } + } +} From b9a550a6a523ab32d81873d7845f0c821b633831 Mon Sep 17 00:00:00 2001 From: xiazengbin Date: Tue, 7 Dec 2021 09:12:32 +0800 Subject: [PATCH 05/21] =?UTF-8?q?=E4=BC=98=E5=8C=96loadDepotInOutRoutePath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../joylink/rtss/simulation/cbtc/build/SimulationBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java index efd9fa1f6..ca191ea93 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java @@ -87,13 +87,13 @@ public class SimulationBuilder { /** * 加载进出depot的route path */ - private static void loadDepotInOutRoutePath(Simulation simulation) { - final Map> srps = simulation.getRepository().getRoutePathMap(); + private static void loadDepotInOutRoutePath(Simulation simulation) { // 仿真车辆段站台停车轨列表 Map> parkingTracksMap = simulation.getRepository().getParkingTracksMap(); if (CollectionUtils.isEmpty(parkingTracksMap)) { return; } + final Map> srps = simulation.getRepository().getRoutePathMap(); parkingTracksMap.forEach((station, secs) -> { if (station.isDepot()) {// 车站为车辆段 List
transferList = station.getTransferList();// 转换轨列表 From 578d1fd44a55fb1cde83e3e95a5c02c1b0a69ecf Mon Sep 17 00:00:00 2001 From: xiazengbin Date: Tue, 7 Dec 2021 09:38:44 +0800 Subject: [PATCH 06/21] =?UTF-8?q?=E4=BC=98=E5=8C=96loadDepotInOutRoutePath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtss/simulation/cbtc/build/SimulationBuilder.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java index ca191ea93..a716f6387 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java @@ -20,13 +20,10 @@ import club.joylink.rtss.vo.map.RealLineConfigVO; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; -import org.springframework.util.CollectionUtils; - -import javax.swing.text.Element; +import org.springframework.util.CollectionUtils; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; -import java.util.stream.Stream; @Slf4j public class SimulationBuilder { @@ -94,6 +91,7 @@ public class SimulationBuilder { return; } final Map> srps = simulation.getRepository().getRoutePathMap(); + log.info("==>>!!!车辆段RoutePathMap 初始 size = {}",srps.size()); parkingTracksMap.forEach((station, secs) -> { if (station.isDepot()) {// 车站为车辆段 List
transferList = station.getTransferList();// 转换轨列表 @@ -130,7 +128,7 @@ public class SimulationBuilder { log.info("仿真数据有问题,车辆段[{}]没有转换轨",station.getName()); } } - }); + }); } /** *当方向未知时,起点终点不变,不同方向搜索route path From 09b0f9261401e3761091c4f94165081da805e6e4 Mon Sep 17 00:00:00 2001 From: xiazengbin Date: Tue, 7 Dec 2021 09:43:15 +0800 Subject: [PATCH 07/21] =?UTF-8?q?=E4=BC=98=E5=8C=96loadDepotInOutRoutePath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../joylink/rtss/simulation/cbtc/build/SimulationBuilder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java index a716f6387..aebbc8bcd 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java @@ -90,8 +90,7 @@ public class SimulationBuilder { if (CollectionUtils.isEmpty(parkingTracksMap)) { return; } - final Map> srps = simulation.getRepository().getRoutePathMap(); - log.info("==>>!!!车辆段RoutePathMap 初始 size = {}",srps.size()); + final Map> srps = simulation.getRepository().getRoutePathMap(); parkingTracksMap.forEach((station, secs) -> { if (station.isDepot()) {// 车站为车辆段 List
transferList = station.getTransferList();// 转换轨列表 From 2433e7d813e7abde1b1f36ad562dbc6dfac30d47 Mon Sep 17 00:00:00 2001 From: Jade Date: Tue, 7 Dec 2021 11:27:48 +0800 Subject: [PATCH 08/21] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=AE=B5=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulation/cbtc/ATS/ATSLogicLoop.java | 4 - .../simulation/cbtc/depot/DepotService.java | 99 +++++++++++++++---- 2 files changed, 82 insertions(+), 21 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSLogicLoop.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSLogicLoop.java index 934ef09a0..c1c87b019 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSLogicLoop.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSLogicLoop.java @@ -3,7 +3,6 @@ package club.joylink.rtss.simulation.cbtc.ATS; import club.joylink.rtss.simulation.cbtc.ATS.service.AtsStandService; import club.joylink.rtss.simulation.cbtc.ATS.service.AtsStationService; import club.joylink.rtss.simulation.cbtc.ATS.service.AtsTrainMonitorService; -import club.joylink.rtss.simulation.cbtc.ATS.tools.TrainOutboundLoadTool; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; @@ -24,11 +23,8 @@ public class ATSLogicLoop { private AtsStationService atsStationService; @Autowired private AtsTrainMonitorService atsTrainMonitorService; - @Autowired - private TrainOutboundLoadTool trainOutboundLoadTool; public void run(Simulation simulation) { - this.trainOutboundLoadTool.loadOutboundTrain(simulation); this.atsStandService.countDown(simulation); this.atsTrainMonitorService.monitor(simulation); this.atsStationService.updateFieldThatChangeOverTime(simulation); 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 b4c9afa26..640f64312 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 @@ -1,10 +1,8 @@ package club.joylink.rtss.simulation.cbtc.depot; +import club.joylink.rtss.simulation.cbtc.ATS.tools.TrainOutboundLoadTool; import club.joylink.rtss.simulation.cbtc.CI.device.CiRouteService; -import club.joylink.rtss.simulation.cbtc.GroupSimulationService; import club.joylink.rtss.simulation.cbtc.Simulation; -import club.joylink.rtss.simulation.cbtc.command.CommandBO; -import club.joylink.rtss.simulation.cbtc.command.CommandInitiateVO; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; import club.joylink.rtss.simulation.cbtc.data.map.Route; @@ -15,15 +13,17 @@ 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.data.vr.VirtualRealityTrain; -import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.time.LocalDateTime; import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Queue; import java.util.stream.Collectors; @Component @@ -33,7 +33,11 @@ public class DepotService { private CiRouteService ciRouteService; @Autowired - private GroupSimulationService groupSimulationService; + private TrainOutboundLoadTool trainOutboundLoadTool; + + private Map> stationListMap = new HashMap<>(); + + private List schedulingTrainPlanList = new LinkedList<>(); public void loadDepotTrain(Simulation simulation) { if (!simulation.getRepository().getConfig().isHandleDepot()) { @@ -60,6 +64,14 @@ public class DepotService { simulation.getRepository().addTrainInfo(trainInfo); } }); + stationListMap.clear(); + schedulingTrainPlanList.clear(); + simulation.getRepository().getSchedulingTrainPlanList().stream(). + sorted(Comparator.comparing(schedulingTrainPlan -> schedulingTrainPlan.getOutDepotTrip().getStartTime().toSecondOfDay())) + .forEach(schedulingTrainPlan -> { + Queue queue = stationListMap.computeIfAbsent(schedulingTrainPlan.getOutDepotTrip().getStartSection(), key -> new LinkedList<>()); + queue.add(schedulingTrainPlan); + }); } public void addJobs(Simulation simulation) { @@ -67,20 +79,73 @@ public class DepotService { } private void run(Simulation simulation) { - SchedulingTrainPlan schedulingTrainPlan = simulation.getRepository().getSchedulingTrainPlanList().get(0); - LocalDateTime systemTime = simulation.getSystemTime(); - if (!schedulingTrainPlan.getOutDepotTrip().getStartTime().plusMinutes(20).isAfter(systemTime.toLocalTime())) { + if (!simulation.isPlanRunning()) { return; } - String groupNumber = schedulingTrainPlan.getGroupNumber(); - VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); - List routePaths = simulation.getRepository().queryRoutePathsByStart(train.getHeadPosition().getSection()); - RoutePath routePath = routePaths.get(0); - for (Route route : routePath.getRouteList()) { - ciRouteService.setRoute(simulation, route); + if (!simulation.getRepository().getConfig().isHandleDepot()) { + trainOutboundLoadTool.loadOutboundTrain(simulation); + } else { + timeToDeparture(simulation); + settingRouteAndMoving(simulation); + arriveTransferTrack(simulation); + } + } + + /** + * 根据时间筛选,从停车轨自动发车 + * @param simulation + */ + private void timeToDeparture(Simulation simulation) { + LocalDateTime systemTime = simulation.getSystemTime(); + stationListMap.forEach((section, list) -> { + SchedulingTrainPlan schedulingTrainPlan = list.peek(); + if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(20).isBefore(systemTime.toLocalTime())) { + schedulingTrainPlanList.add(list.poll()); + list.add(schedulingTrainPlan); + } + }); + } + + /** + * 列车排进路并运行 + * @param simulation + */ + private void settingRouteAndMoving(Simulation simulation) { + for (SchedulingTrainPlan schedulingTrainPlan : schedulingTrainPlanList) { + String groupNumber = schedulingTrainPlan.getGroupNumber(); + VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); + List routePaths = simulation.getRepository().queryRoutePathsByStart(train.getHeadPosition().getSection()); + if (routePaths.isEmpty()) { + continue; + } + RoutePath routePath = routePaths.get(0); + for (Route route : routePath.getRouteList()) { + if (route.isSetting()) { + continue; + } + if (route.isLock()) { + continue; + } + ciRouteService.setRoute(simulation, route); + } + Section lastSection = routePath.getLastSection(); + train.setRobotTargetPosition(new SectionPosition(lastSection, lastSection.getStopPointByDirection(routePath.isRight()))); + } + } + + /** + * 判断运行列车是否到达转换轨并升级 + * @param simulation + */ + private void arriveTransferTrack(Simulation simulation) { + for (SchedulingTrainPlan schedulingTrainPlan : schedulingTrainPlanList) { + String groupNumber = schedulingTrainPlan.getGroupNumber(); + VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); + List routePaths = simulation.getRepository().queryRoutePathsByStart(train.getHeadPosition().getSection()); + if (train.isParkingAt() && train.getHeadPosition().getSection().equals(routePaths.get(0).getLastSection())) { + // 到达 + schedulingTrainPlanList.remove(schedulingTrainPlan); + } } - CommandInitiateVO commandInitiateVO = new CommandInitiateVO(CommandBO.CommandType.Drive_To, schedulingTrainPlan.getDriverCode(), null); - List memberList = simulation.getSimulationMembersByDevice(train); - groupSimulationService.command(simulation, commandInitiateVO, memberList.get(0)); } } From cae20aba53f5a518efa3f191bed4a80e7fb8128b Mon Sep 17 00:00:00 2001 From: xiazengbin Date: Tue, 7 Dec 2021 15:26:50 +0800 Subject: [PATCH 09/21] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=AE=B5=E5=8A=A0?= =?UTF-8?q?=E8=BD=BDroute=20path=20=E6=B7=BB=E5=8A=A0=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/build/SimulationBuilder.java | 80 ++++++++++++------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java index aebbc8bcd..12ff17feb 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SimulationBuilder.java @@ -22,6 +22,7 @@ import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.util.CollectionUtils; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; import java.util.stream.Collectors; @@ -84,61 +85,78 @@ public class SimulationBuilder { /** * 加载进出depot的route path */ - private static void loadDepotInOutRoutePath(Simulation simulation) { + private static void loadDepotInOutRoutePath(Simulation simulation) { // 仿真车辆段站台停车轨列表 Map> parkingTracksMap = simulation.getRepository().getParkingTracksMap(); if (CollectionUtils.isEmpty(parkingTracksMap)) { return; } - final Map> srps = simulation.getRepository().getRoutePathMap(); + final Map> srps = simulation.getRepository().getRoutePathMap(); parkingTracksMap.forEach((station, secs) -> { if (station.isDepot()) {// 车站为车辆段 List
transferList = station.getTransferList();// 转换轨列表 - if(!CollectionUtils.isEmpty(transferList)) { - transferList.forEach(transSec->{ - //停车轨到转换轨 - secs.forEach(parkSec->{ - final String rpKey=RoutePath.buildKey(parkSec, transSec); - List nrp=tryFindRoutePathByDirection(parkSec, transSec,10); - List srp=srps.get(rpKey); - if(null==srp) { - srp=new ArrayList(); + if (!CollectionUtils.isEmpty(transferList)) { + transferList.forEach(transSec -> { + // 停车轨到转换轨 + secs.forEach(parkSec -> { + final String rpKey = RoutePath.buildKey(parkSec, transSec); + List nrp = tryFindRoutePathForOutByDirection(parkSec, transSec, 20); + List srp = srps.get(rpKey); + if (null == srp) { + srp = new ArrayList(); srps.put(rpKey, srp); } - if(!CollectionUtils.isEmpty(nrp)) { + if (!CollectionUtils.isEmpty(nrp)) { srp.addAll(nrp); } }); - //转换轨到停车轨 - secs.forEach(parkSec->{ - final String rpKey=RoutePath.buildKey(transSec, parkSec); - List nrp=tryFindRoutePathByDirection(transSec, parkSec,10); - List srp=srps.get(rpKey); - if(null==srp) { - srp=new ArrayList(); + // 转换轨到停车轨 + secs.forEach(parkSec -> { + final String rpKey = RoutePath.buildKey(transSec, parkSec); + List nrp = tryFindRoutePathByDirection(transSec, parkSec, 20); + List srp = srps.get(rpKey); + if (null == srp) { + srp = new ArrayList(); srps.put(rpKey, srp); } - if(!CollectionUtils.isEmpty(nrp)) { + if (!CollectionUtils.isEmpty(nrp)) { srp.addAll(nrp); } }); - }); - }else { - log.info("仿真数据有问题,车辆段[{}]没有转换轨",station.getName()); + }); + } else { + log.info("仿真数据有问题,车辆段[{}]没有转换轨", station.getName()); } } - }); + }); } + /** - *当方向未知时,起点终点不变,不同方向搜索route path + * 当方向未知时,起点终点不变,不同方向搜索route path */ - private static List tryFindRoutePathByDirection(Section start, Section end,int iterTimes) { - List r= CalculateService.queryRoutePathsOnDirection(start, end,true, iterTimes); - if(!CollectionUtils.isEmpty(r)) { + private static List tryFindRoutePathForOutByDirection(Section start, Section end, int iterTimes) { + List r = tryFindRoutePathByDirection(start, end, iterTimes); + if (r.size() == 2) { + return r.stream().sorted((RoutePath r1, RoutePath r2) -> { + return r1.getSignalList().size() - r2.getSignalList().size(); + }).findFirst().stream().collect(Collectors.toList()); + + } else if (r.size() > 2) { + log.warn("获取车辆段从停车轨到转换轨的路径, routeKey = {} , 路径数量大于2异常 !!!"); + } + return r; + } + + /** + * 当方向未知时,起点终点不变,不同方向搜索route path + */ + private static List tryFindRoutePathByDirection(Section start, Section end, int iterTimes) { + List r = CalculateService.queryRoutePathsOnDirection(start, end, true, iterTimes); + if (!CollectionUtils.isEmpty(r)) { return r; - }else { - return CalculateService.queryRoutePathsOnDirection(start, end,false, iterTimes); - } + } else { + return CalculateService.queryRoutePathsOnDirection(start, end, false, iterTimes); + } } private static void buildIbpData(SimulationDeviceBuildResult mapDataBuildResult, List ibpList) { if (CollectionUtils.isEmpty(ibpList)) From 2e099683626d9e9d90fc398f87d2df45243f976d Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Tue, 7 Dec 2021 15:47:41 +0800 Subject: [PATCH 10/21] =?UTF-8?q?=E4=BF=AE=E6=94=B9ZC=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=85=B3=E8=81=94=E7=9A=84=E5=8C=BA=E6=AE=B5=E7=AD=9B=E9=80=89?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java index e0fb2c50c..7c876f550 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java @@ -325,7 +325,7 @@ public class MapDeviceBuilder { elementMap.values().stream() .filter(element -> element instanceof Section) .map(element -> (Section) element) - .filter(Section::isAxleCounterSection) + .filter(Section::isAxleCounter) .forEach(section -> { zc.addSection(section); section.addZc(zc); From 645bfee5594684e21f8beda142cc42aba74e627a Mon Sep 17 00:00:00 2001 From: Jade Date: Tue, 7 Dec 2021 15:50:10 +0800 Subject: [PATCH 11/21] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=AE=B5=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulation/cbtc/depot/DepotService.java | 109 +++++++++++++----- 1 file changed, 81 insertions(+), 28 deletions(-) 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 640f64312..3fc2bfd95 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 @@ -37,7 +37,9 @@ public class DepotService { private Map> stationListMap = new HashMap<>(); - private List schedulingTrainPlanList = new LinkedList<>(); + private List outboundPlanList = new LinkedList<>(); + + private List inboundPlanList = new LinkedList<>(); public void loadDepotTrain(Simulation simulation) { if (!simulation.getRepository().getConfig().isHandleDepot()) { @@ -65,11 +67,12 @@ public class DepotService { } }); stationListMap.clear(); - schedulingTrainPlanList.clear(); + outboundPlanList.clear(); simulation.getRepository().getSchedulingTrainPlanList().stream(). sorted(Comparator.comparing(schedulingTrainPlan -> schedulingTrainPlan.getOutDepotTrip().getStartTime().toSecondOfDay())) .forEach(schedulingTrainPlan -> { - Queue queue = stationListMap.computeIfAbsent(schedulingTrainPlan.getOutDepotTrip().getStartSection(), key -> new LinkedList<>()); + Queue queue = stationListMap + .computeIfAbsent(schedulingTrainPlan.getOutDepotTrip().getStartSection(), key -> new LinkedList<>()); queue.add(schedulingTrainPlan); }); } @@ -88,6 +91,7 @@ public class DepotService { timeToDeparture(simulation); settingRouteAndMoving(simulation); arriveTransferTrack(simulation); + backToParking(simulation); } } @@ -100,8 +104,10 @@ public class DepotService { stationListMap.forEach((section, list) -> { SchedulingTrainPlan schedulingTrainPlan = list.peek(); if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(20).isBefore(systemTime.toLocalTime())) { - schedulingTrainPlanList.add(list.poll()); - list.add(schedulingTrainPlan); + if (!outboundPlanList.contains(schedulingTrainPlan)) { + outboundPlanList.add(schedulingTrainPlan); + list.add(list.poll()); + } } }); } @@ -111,25 +117,11 @@ public class DepotService { * @param simulation */ private void settingRouteAndMoving(Simulation simulation) { - for (SchedulingTrainPlan schedulingTrainPlan : schedulingTrainPlanList) { - String groupNumber = schedulingTrainPlan.getGroupNumber(); - VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); - List routePaths = simulation.getRepository().queryRoutePathsByStart(train.getHeadPosition().getSection()); - if (routePaths.isEmpty()) { - continue; - } - RoutePath routePath = routePaths.get(0); - for (Route route : routePath.getRouteList()) { - if (route.isSetting()) { - continue; - } - if (route.isLock()) { - continue; - } - ciRouteService.setRoute(simulation, route); - } - Section lastSection = routePath.getLastSection(); - train.setRobotTargetPosition(new SectionPosition(lastSection, lastSection.getStopPointByDirection(routePath.isRight()))); + for (SchedulingTrainPlan schedulingTrainPlan : outboundPlanList) { + moving(simulation, schedulingTrainPlan.getGroupNumber(), schedulingTrainPlan.getOutDepotTrip().getStartSection()); + } + for (SchedulingTrainPlan schedulingTrainPlan : inboundPlanList) { + moving(simulation, schedulingTrainPlan.getGroupNumber(), schedulingTrainPlan.getInDepotTrip().getEndSection()); } } @@ -138,14 +130,75 @@ public class DepotService { * @param simulation */ private void arriveTransferTrack(Simulation simulation) { - for (SchedulingTrainPlan schedulingTrainPlan : schedulingTrainPlanList) { + for (SchedulingTrainPlan schedulingTrainPlan : outboundPlanList) { String groupNumber = schedulingTrainPlan.getGroupNumber(); VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); - List routePaths = simulation.getRepository().queryRoutePathsByStart(train.getHeadPosition().getSection()); - if (train.isParkingAt() && train.getHeadPosition().getSection().equals(routePaths.get(0).getLastSection())) { + if (train.isParkingAt() + && train.getHeadPosition().getSection().equals(schedulingTrainPlan.getOutDepotTrip().getStartSection())) { // 到达 - schedulingTrainPlanList.remove(schedulingTrainPlan); + outboundPlanList.remove(schedulingTrainPlan); + train.setServiceNumber(schedulingTrainPlan.getOutDepotTrip().getServiceNumber()); + train.setTripNumber(schedulingTrainPlan.getOutDepotTrip().getTripNumber()); + train.setCommunication(true); + } + } + for (SchedulingTrainPlan schedulingTrainPlan : inboundPlanList) { + String groupNumber = schedulingTrainPlan.getGroupNumber(); + VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); + if (train.isParkingAt() + && train.getHeadPosition().getSection().equals(schedulingTrainPlan.getInDepotTrip().getEndSection())) { + // 到达 + inboundPlanList.remove(schedulingTrainPlan); } } } + + /** + * 筛选入库 + * @param simulation + */ + private void backToParking(Simulation simulation) { + for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) { + if (!train.isParkingAt()) { + continue; + } + Section section = train.getHeadPosition().getSection(); + if (!section.isTransferTrack()) { + continue; + } + for (SchedulingTrainPlan schedulingTrainPlan : stationListMap.get(section)) { + if (!schedulingTrainPlan.getInDepotTrip().getEndSection().equals(section)) { + continue; + } + if (!train.getGroupNumber().equals(schedulingTrainPlan.getGroupNumber())) { + continue; + } + if (!inboundPlanList.contains(schedulingTrainPlan)) { + train.initAsRM(); + inboundPlanList.add(schedulingTrainPlan); + } + } + } + } + + private void moving(Simulation simulation, String groupNumber, Section endSection) { + VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); + Section startSection = train.getHeadPosition().getSection(); + List routePaths = simulation.getRepository().queryRoutePaths(startSection, endSection); + if (routePaths == null || routePaths.isEmpty()) { + return; + } + RoutePath routePath = routePaths.get(0); + for (Route route : routePath.getRouteList()) { + if (route.isSetting()) { + continue; + } + if (route.isLock()) { + continue; + } + ciRouteService.setRoute(simulation, route); + } + Section lastSection = routePath.getEnd(); + train.setRobotTargetPosition(new SectionPosition(lastSection, lastSection.getStopPointByDirection(routePath.isRight()))); + } } From 4755d9a137e327d343b095a56a91fd7d66235e8b Mon Sep 17 00:00:00 2001 From: Jade Date: Tue, 7 Dec 2021 17:53:53 +0800 Subject: [PATCH 12/21] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=AE=B5=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulation/cbtc/depot/DepotService.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) 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 3fc2bfd95..f0a28c8cf 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,6 +19,7 @@ import org.springframework.stereotype.Component; import java.time.LocalDateTime; import java.util.Comparator; import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -103,7 +104,7 @@ public class DepotService { LocalDateTime systemTime = simulation.getSystemTime(); stationListMap.forEach((section, list) -> { SchedulingTrainPlan schedulingTrainPlan = list.peek(); - if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(20).isBefore(systemTime.toLocalTime())) { + if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) { if (!outboundPlanList.contains(schedulingTrainPlan)) { outboundPlanList.add(schedulingTrainPlan); list.add(list.poll()); @@ -130,25 +131,24 @@ public class DepotService { * @param simulation */ private void arriveTransferTrack(Simulation simulation) { - for (SchedulingTrainPlan schedulingTrainPlan : outboundPlanList) { + 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.isParkingAt() + if (train.getSpeed() == 0 && train.getHeadPosition().getSection().equals(schedulingTrainPlan.getOutDepotTrip().getStartSection())) { // 到达 - outboundPlanList.remove(schedulingTrainPlan); - train.setServiceNumber(schedulingTrainPlan.getOutDepotTrip().getServiceNumber()); - train.setTripNumber(schedulingTrainPlan.getOutDepotTrip().getTripNumber()); - train.setCommunication(true); + iterator.remove(); } } - for (SchedulingTrainPlan schedulingTrainPlan : inboundPlanList) { + 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.isParkingAt() + if (train.getSpeed() == 0 && train.getHeadPosition().getSection().equals(schedulingTrainPlan.getInDepotTrip().getEndSection())) { // 到达 - inboundPlanList.remove(schedulingTrainPlan); + iterator.remove(); } } } @@ -176,6 +176,7 @@ public class DepotService { if (!inboundPlanList.contains(schedulingTrainPlan)) { train.initAsRM(); inboundPlanList.add(schedulingTrainPlan); + break; } } } From 549e1ef0585c389369971e64c710248112ba3d1e Mon Sep 17 00:00:00 2001 From: Jade Date: Wed, 8 Dec 2021 10:36:11 +0800 Subject: [PATCH 13/21] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=AE=B5=E6=8E=92?= =?UTF-8?q?=E5=88=97=E8=BF=9B=E8=B7=AF=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulation/cbtc/depot/DepotService.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) 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 f0a28c8cf..8d91304bf 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 @@ -7,6 +7,7 @@ import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; 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.map.Station; import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan; import club.joylink.rtss.simulation.cbtc.data.support.RoutePath; @@ -69,6 +70,7 @@ public class DepotService { }); stationListMap.clear(); outboundPlanList.clear(); + inboundPlanList.clear(); simulation.getRepository().getSchedulingTrainPlanList().stream(). sorted(Comparator.comparing(schedulingTrainPlan -> schedulingTrainPlan.getOutDepotTrip().getStartTime().toSecondOfDay())) .forEach(schedulingTrainPlan -> { @@ -190,16 +192,21 @@ public class DepotService { return; } RoutePath routePath = routePaths.get(0); - for (Route route : routePath.getRouteList()) { - if (route.isSetting()) { - continue; - } - if (route.isLock()) { - continue; - } - ciRouteService.setRoute(simulation, route); - } Section lastSection = routePath.getEnd(); train.setRobotTargetPosition(new SectionPosition(lastSection, lastSection.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; + } + } + } } } From 2cad9aea1593eee770dc6d0106522d74fb86c5f7 Mon Sep 17 00:00:00 2001 From: Jade Date: Wed, 8 Dec 2021 10:57:35 +0800 Subject: [PATCH 14/21] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=AE=B5fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../club/joylink/rtss/simulation/cbtc/depot/DepotService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 8d91304bf..e502933f9 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 @@ -106,7 +106,8 @@ public class DepotService { LocalDateTime systemTime = simulation.getSystemTime(); stationListMap.forEach((section, list) -> { SchedulingTrainPlan schedulingTrainPlan = list.peek(); - if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) { + if (!schedulingTrainPlan.getOutDepotTrip().isDeparture() + && schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) { if (!outboundPlanList.contains(schedulingTrainPlan)) { outboundPlanList.add(schedulingTrainPlan); list.add(list.poll()); From 58cf6af8c7c3aec6fc1ffe74ab20240a6a4aea3f Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Wed, 8 Dec 2021 11:01:06 +0800 Subject: [PATCH 15/21] =?UTF-8?q?=E4=BF=AE=E6=94=B9ATS=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=9A=E3=80=90=E8=AE=A1=E5=88=92=E8=BD=A6=E5=88=B0=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E8=BD=A8=E5=87=86=E5=A4=87=E5=9B=9E=E5=BA=93=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=BD=AC=E4=BA=BA=E5=B7=A5=E8=BD=A6=E3=80=91?= =?UTF-8?q?=E3=80=90=E6=9C=89=E8=BD=A6=E8=BE=86=E6=AE=B5=E6=97=B6=E5=9B=9E?= =?UTF-8?q?=E5=BA=93=E5=88=97=E8=BD=A6=E4=B8=8D=E6=B6=88=E5=A4=B1=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stage/AtsHeadTrainStageService.java | 14 ++++++---- .../stage/AtsManualTrainStageService.java | 13 +++++----- .../stage/AtsPlanTrainStageService.java | 26 +++++++++++++------ .../service/stage/AtsTrainStageHandler.java | 2 ++ .../simulation/cbtc/data/vo/TrainInfo.java | 11 ++++++++ 5 files changed, 46 insertions(+), 20 deletions(-) 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 eb17ba6a2..49dab3722 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 @@ -3,9 +3,11 @@ package club.joylink.rtss.simulation.cbtc.ATS.service.stage; import club.joylink.rtss.simulation.cbtc.ATS.service.AtsStandService; import club.joylink.rtss.simulation.cbtc.ATS.service.AtsTrainService; 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.map.DestinationCodeDefinition; +import club.joylink.rtss.simulation.cbtc.data.map.Section; +import club.joylink.rtss.simulation.cbtc.data.map.Stand; +import club.joylink.rtss.simulation.cbtc.data.map.StationRunLevel; 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; @@ -13,9 +15,7 @@ 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; @@ -87,7 +87,11 @@ public class AtsHeadTrainStageService implements AtsStageService { */ private void handleArriveDestination(Simulation simulation, TrainInfo trainInfo) { // 先回库,后设置为人工车 - trainInfo.finishPlanPrepareInbound(); + if (simulation.getRepository().getConfig().isHandleDepot()) { + trainInfo.finishPlanPrepareEnterDepot(); + } else { + trainInfo.finishPlanPrepareInbound(); + } if (simulation.getRepository().getConfig().isSetManualWhenHeadTrainArriveTarget()) { atsTrainService.setManualTrain(simulation, trainInfo.getGroupNumber()); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsManualTrainStageService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsManualTrainStageService.java index c0c3c5180..e7ffaf9ab 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsManualTrainStageService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsManualTrainStageService.java @@ -4,7 +4,6 @@ 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.plan.TripPlan; -import club.joylink.rtss.simulation.cbtc.data.support.RoutePath; import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -25,12 +24,12 @@ public class AtsManualTrainStageService implements AtsStageService { @Override public void handleTransferTrackParking(Simulation simulation, TrainInfo trainInfo, Section parkSection) { - SimulationDataRepository repository = simulation.getRepository(); - List routePathList = repository.queryRoutePathsByEnd(parkSection); - boolean in = false; // 回库?出库? - if (routePathList.get(0).isRight() == trainInfo.getRight().booleanValue()) { - in = true; - } +// SimulationDataRepository repository = simulation.getRepository(); +// List routePathList = repository.queryRoutePathsByEnd(parkSection); + boolean in = trainInfo.isInbound(); // 回库? +// if (routePathList.get(0).isRight() == trainInfo.getRight().booleanValue()) { +// in = true; +// } if (!in) { // 出库,查询计划,是否此轨道有出库计划 if (simulation.isPlanRunning()) { this.checkAndApplyTripPlan(simulation, trainInfo, parkSection); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsPlanTrainStageService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsPlanTrainStageService.java index 9c4606b00..a5edae484 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsPlanTrainStageService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsPlanTrainStageService.java @@ -2,6 +2,7 @@ package club.joylink.rtss.simulation.cbtc.ATS.service.stage; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.ATS.service.AtsStandService; +import club.joylink.rtss.simulation.cbtc.ATS.service.AtsTrainService; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.map.*; @@ -34,22 +35,31 @@ public class AtsPlanTrainStageService implements AtsStageService { private AtsStandService atsStandService; @Autowired private OnboardAtpApiService onboardAtpApiService; + @Autowired + private AtsTrainService atsTrainService; @Override public void handleTransferTrackParking(Simulation simulation, TrainInfo trainInfo, Section parkSection) { SimulationDataRepository repository = simulation.getRepository(); TripPlan tripPlan = repository.getTripPlan(trainInfo.getServiceNumber(), trainInfo.getTripNumber()); - List routePathList = repository.queryRoutePathsByEnd(parkSection); - if (routePathList.get(0).isRight() == trainInfo.getRight()) { //准备回库 - if (!parkSection.isTurnBackTrack()) { //针对上饶沙盘 - trainInfo.finishPlanPrepareInbound(); - } - } else if (tripPlan.getEndSection().equals(parkSection) || +// List routePathList = repository.queryRoutePathsByEnd(parkSection); +// if (routePathList.get(0).isRight() == trainInfo.getRight()) { //准备回库 +// if (!parkSection.isTurnBackTrack()) { //针对上饶沙盘 +// trainInfo.finishPlanPrepareInbound(); +// } +// } else 没看懂为啥有这部分逻辑,先注掉 + if (tripPlan.getEndSection().equals(parkSection) || tripPlan.getEndSection().getStation().equals(parkSection.getStation())) { // 列车到达计划终点,准备回库 - if (!parkSection.isTurnBackTrack()) { //针对上饶沙盘 - trainInfo.finishPlanPrepareInbound(); + if (simulation.getRepository().getConfig().isHandleDepot()) { + trainInfo.finishPlanPrepareEnterDepot(); + } else { + if (!parkSection.isTurnBackTrack()) { //针对上饶沙盘 + trainInfo.finishPlanPrepareInbound(); + } } + //转人工车 + atsTrainService.setManualTrain(simulation, trainInfo.getGroupNumber()); } else if (tripPlan.getStartSection().equals(parkSection)) { // 出库列车 if (trainInfo.getPlanStandTrack() != 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 5bd9e853f..5ca99eaa7 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 @@ -39,6 +39,8 @@ public class AtsTrainStageHandler { public void handleInbound(Simulation simulation, TrainInfo train) { SimulationDataRepository repository = simulation.getRepository(); int deleteRemain = train.getDeleteRemain(); + if (deleteRemain < 0) //以该条件作为列车入库是要进入车辆段而不是消失的标记 + return; deleteRemain -= SimulationModule.ATS.getRateMs(); if (deleteRemain <= 0) { // 删除列车 repository.deleteOnlineTrain(train.getGroupNumber()); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java index 8f1f5562b..a902f7ea0 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java @@ -586,11 +586,22 @@ public class TrainInfo extends MapElement { this.routing = routing; } + /** + * 准备回库(消失) + */ public void finishPlanPrepareInbound() { this.inbound = true; this.deleteRemain = 5 * 1000; } + /** + * 准备进入车辆段 + */ + public void finishPlanPrepareEnterDepot() { + this.inbound = true; + this.deleteRemain = -1; + } + public void updateDeleteRemain(int deleteRemain) { this.deleteRemain = deleteRemain; } From 88e5fa6abba8845be8de2e289d25675e5fcb20e6 Mon Sep 17 00:00:00 2001 From: Jade Date: Wed, 8 Dec 2021 13:05:44 +0800 Subject: [PATCH 16/21] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=AE=B5=20=E6=B4=BE?= =?UTF-8?q?=E7=8F=AD=E8=AE=A1=E5=88=92=E7=94=9F=E6=88=90=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/build/SchedulingBuilder.java | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SchedulingBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SchedulingBuilder.java index 434e3015e..c1e4890fd 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SchedulingBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SchedulingBuilder.java @@ -3,6 +3,7 @@ package club.joylink.rtss.simulation.cbtc.build; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.map.MapElement; +import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan; import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; @@ -72,17 +73,34 @@ public class SchedulingBuilder { trainList.size(), schedulingPlanList.size())); } // 分配列车到派班计划 - LinkedList trainQueue = new LinkedList<>(trainList); - Map serverTrainMap = new HashMap<>(); - for (int i = 0; i < schedulingPlanList.size(); i++) { - SchedulingTrainPlan schedulingTrainPlan = schedulingPlanList.get(i); - String serviceNumber = schedulingTrainPlan.getOutDepotTrip().getServiceNumber(); - VirtualRealityTrain train = serverTrainMap.get(serviceNumber); - if (Objects.isNull(train)) { - train = trainQueue.poll(); - serverTrainMap.put(serviceNumber, train); + if (simulation.getRepository().getConfig().isHandleDepot()) { + Map> map = new HashMap<>(); + for (VirtualRealityTrain train : trainList) { + Queue queue = map.computeIfAbsent(train.getDepotStation(), key -> new LinkedList<>()); + queue.add(train); + } + Map serverTrainMap = new HashMap<>(); + for (SchedulingTrainPlan schedulingTrainPlan : schedulingPlanList) { + String serviceNumber = schedulingTrainPlan.getOutDepotTrip().getServiceNumber(); + VirtualRealityTrain train = serverTrainMap.get(serviceNumber); + if (Objects.isNull(train)) { + train = map.get(schedulingTrainPlan.getOutDepotTrip().getStartSection().getStation()).poll(); + serverTrainMap.put(serviceNumber, train); + } + schedulingTrainPlan.setGroupNumber(train.getGroupNumber()); + } + } else { + LinkedList trainQueue = new LinkedList<>(trainList); + Map serverTrainMap = new HashMap<>(); + for (SchedulingTrainPlan schedulingTrainPlan : schedulingPlanList) { + String serviceNumber = schedulingTrainPlan.getOutDepotTrip().getServiceNumber(); + VirtualRealityTrain train = serverTrainMap.get(serviceNumber); + if (Objects.isNull(train)) { + train = trainQueue.poll(); + serverTrainMap.put(serviceNumber, train); + } + schedulingTrainPlan.setGroupNumber(train.getGroupNumber()); } - schedulingTrainPlan.setGroupNumber(train.getGroupNumber()); } repository.setSchedulingTrainPlanList(schedulingPlanList); return schedulingPlanList; From 15f9f69428a25a48ea5e7cffa7a52dcee9ec8427 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Wed, 8 Dec 2021 15:01:17 +0800 Subject: [PATCH 17/21] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BA=BF=E8=B7=AF?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E3=80=90=E8=BF=90=E8=A1=8C=E5=9B=BE=E4=B8=AD?= =?UTF-8?q?=E8=BD=A6=E6=AC=A1=E5=8F=B7=E5=94=AF=E4=B8=80=E3=80=91=EF=BC=88?= =?UTF-8?q?=E5=BD=B1=E5=93=8D=E7=94=9F=E6=88=90=E8=AE=A1=E5=88=92=E7=9A=84?= =?UTF-8?q?=E8=BD=A6=E6=AC=A1=E5=8F=B7=EF=BC=89=E4=B8=8E=E7=9B=B8=E5=BA=94?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtss/services/RunPlanDraftService.java | 7 +++- .../services/runplan/RunPlanGenerator.java | 40 ++++++++++++++++++- .../simulation/cbtc/data/map/MapConfig.java | 3 ++ .../joylink/rtss/vo/map/RealLineConfigVO.java | 3 ++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/main/java/club/joylink/rtss/services/RunPlanDraftService.java b/src/main/java/club/joylink/rtss/services/RunPlanDraftService.java index 0c0b574f2..86c441540 100644 --- a/src/main/java/club/joylink/rtss/services/RunPlanDraftService.java +++ b/src/main/java/club/joylink/rtss/services/RunPlanDraftService.java @@ -21,7 +21,8 @@ import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.runplan.*; import club.joylink.rtss.vo.client.runplan.user.RunPlanRoutingVO; import club.joylink.rtss.vo.client.runplan.user.RunPlanRunlevelVO; -import club.joylink.rtss.vo.map.*; +import club.joylink.rtss.vo.map.MapVO; +import club.joylink.rtss.vo.map.RealLineConfigVO; import club.joylink.rtss.vo.map.graph.MapSectionNewVO; import club.joylink.rtss.vo.map.graph.MapStationNewVO; import club.joylink.rtss.vo.map.graph.MapStationStandNewVO; @@ -444,7 +445,9 @@ public class RunPlanDraftService implements IRunPlanDraftService { String max = planVO.getTripList().stream().map(RunPlanTripVO::getServiceNumber).max(Comparator.comparingInt(Integer::parseInt)).orElse("0"); // 当前已有最大服务号 int maxServiceNumber = Integer.parseInt(max); - inputData.setServiceNumber(String.format("%03d", ++maxServiceNumber)); + RealLineConfigVO configVO = mapVO.getConfigVO(); + String serviceFormat = String.format("%%0%sd", configVO.getFiguresOfServiceNumber()); + inputData.setServiceNumber(String.format(serviceFormat, ++maxServiceNumber)); Integer departureInterval = inputData.getDepartureInterval() < 60 ? 180 : inputData.getDepartureInterval(); inputData.setDepartureInterval(departureInterval); } diff --git a/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java b/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java index fe25f3f90..abffb76cd 100644 --- a/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java +++ b/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java @@ -33,8 +33,8 @@ public class RunPlanGenerator { private IRunPlanUserConfigService runPlanUserConfigService; public List generatorTrips(Long userId, RunPlanInputData inputData, MapVO mapVO) { - RealLineConfigVO configVO = mapVO.getConfigVO(); - String serviceFormat = String.format("%%0%sd", configVO.getFiguresOfServiceNumber()); + RealLineConfigVO mapConfigVO = mapVO.getConfigVO(); + String serviceFormat = String.format("%%0%sd", mapConfigVO.getFiguresOfServiceNumber()); //校验时间 checkInputTime(inputData); RunPlanRoutingVO running1Routing = runPlanRoutingService.queryUserRoutingById(userId, mapVO.getId(), inputData.getRunningRouting1()); @@ -83,6 +83,7 @@ public class RunPlanGenerator { inputData.setServiceNumber(String.format(serviceFormat, startServiceNumber + 2)); departEndTime1 = serviceTripList1.get(2).getTimeList().get(0).getArrivalTime(); generateServices(inputData, mapVO, running1Routing, running2Routing, inboundRoutings, outBoundRouting1, runLevelMap, parkTimeMap, reentryData, tripList, initBeginTime, departEndTime1); + rearrangeTripNumber(mapConfigVO, tripList); return tripList; } else if (Objects.nonNull(outBoundRouting2)) { tripList.removeAll(serviceTripList1); @@ -90,6 +91,7 @@ public class RunPlanGenerator { inputData.setServiceNumber(String.format(serviceFormat, startServiceNumber + 3)); departEndTime2 = serviceTripList2.get(2).getTimeList().get(0).getArrivalTime(); generateServices(inputData, mapVO, running2Routing, running1Routing, inboundRoutings, outBoundRouting2, runLevelMap, parkTimeMap, reentryData, tripList, initBeginTime, departEndTime2); + rearrangeTripNumber(mapConfigVO, tripList); return tripList; } } @@ -99,6 +101,7 @@ public class RunPlanGenerator { inputData.setServiceNumber(String.format(serviceFormat, startServiceNumber + 3)); generateServices(inputData, mapVO, running2Routing, running1Routing, inboundRoutings, outBoundRouting2, runLevelMap, parkTimeMap, reentryData, tripList, initBeginTime, departEndTime2); + rearrangeTripNumber(mapConfigVO, tripList); } else { Routing2BoundInfo outBoundRouting = null; @@ -126,6 +129,39 @@ public class RunPlanGenerator { return tripList; } + /** + * 根据线路配置,重排车次号 + */ + private void rearrangeTripNumber(RealLineConfigVO mapConfigVO, List tripList) { + //重排车次号 + if (mapConfigVO.isTripNumberIsUnique()) { + //上下行车次号 + int upTn = 1; + int downTn = 1; + //上下行方向编号 + String upDirection; + String downDirection; + String tripFormat; + if (mapConfigVO.getFiguresOfTripNumber() == 2) { + throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("两位车次号暂不支持车次号唯一"); +// upDirection = ""; +// downDirection = ""; +// tripFormat = "%02d"; + } else { + upDirection = "2"; + downDirection = "1"; + tripFormat = String.format("%%0%sd", mapConfigVO.getFiguresOfTripNumber() - 1); + } + for (RunPlanTripVO tripVO : tripList.stream().sorted(Comparator.comparing(RunPlanTripVO::getStartTime)).collect(Collectors.toList())) { + if (mapConfigVO.isUp(tripVO.getRight())) { + tripVO.setTripNumber(upDirection + String.format(tripFormat, upTn++)); + } else { + tripVO.setTripNumber(downDirection + String.format(tripFormat, downTn++)); + } + } + } + } + private void checkInputTime(RunPlanInputData inputData) { BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(inputData.getOverTime().isAfter(inputData.getBeginTime()), "输入参数错误:发车时间应早于结束时间"); LocalTime beginTimeOffset = inputData.getBeginTime().minusHours(OFFSET_TIME_HOURS); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/MapConfig.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/MapConfig.java index 0d2683715..a23a864d4 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/MapConfig.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/MapConfig.java @@ -219,6 +219,9 @@ public class MapConfig { /** 处理停车场/车辆段逻辑 */ private boolean handleDepot; + /** 运行图中车次号是否唯一 */ + private boolean tripNumberIsUnique; + private Set needConfirmConnectMembers = Stream.of(DISPATCHER, STATION_SUPERVISOR, MAINTAINER, ELECTRIC_DISPATCHER).collect(Collectors.toSet()); diff --git a/src/main/java/club/joylink/rtss/vo/map/RealLineConfigVO.java b/src/main/java/club/joylink/rtss/vo/map/RealLineConfigVO.java index d3ac26e3d..0da236445 100644 --- a/src/main/java/club/joylink/rtss/vo/map/RealLineConfigVO.java +++ b/src/main/java/club/joylink/rtss/vo/map/RealLineConfigVO.java @@ -206,6 +206,9 @@ public class RealLineConfigVO { /** 进路默认开启冲突检测 */ private boolean routeDefaultCheckConflict; + /** 运行图中车次号是否唯一 */ + private boolean tripNumberIsUnique; + public static RealLineConfigVO parseJsonStr(String configData) { if (StringUtils.hasText(configData)) { return JsonUtils.read(configData, RealLineConfigVO.class); From 6372892cdb6843a324cab64dfec4d6a766866956 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Wed, 8 Dec 2021 15:31:13 +0800 Subject: [PATCH 18/21] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=87=8D=E8=AE=BE?= =?UTF-8?q?=E8=BD=A6=E6=AC=A1=E5=8F=B7=E9=80=BB=E8=BE=91=E7=9A=84=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E4=BB=A5=E8=A6=86=E7=9B=96=E7=94=9F=E6=88=90=E5=8D=95?= =?UTF-8?q?=E6=9D=A1=E8=AE=A1=E5=88=92=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtss/services/RunPlanDraftService.java | 36 ++++++++++++++++++- .../services/runplan/RunPlanGenerator.java | 36 ------------------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/main/java/club/joylink/rtss/services/RunPlanDraftService.java b/src/main/java/club/joylink/rtss/services/RunPlanDraftService.java index 86c441540..c6e65a52f 100644 --- a/src/main/java/club/joylink/rtss/services/RunPlanDraftService.java +++ b/src/main/java/club/joylink/rtss/services/RunPlanDraftService.java @@ -441,17 +441,18 @@ public class RunPlanDraftService implements IRunPlanDraftService { public void generateRunPlanService(Long userId, Long planId, RunPlanInputData inputData) { RunPlanVO planVO = getRunPlanById(planId); MapVO mapVO = this.iMapService.getMapDetail(planVO.getMapId()); + RealLineConfigVO configVO = mapVO.getConfigVO(); if (Objects.nonNull(inputData.getDepartureInterval())) { String max = planVO.getTripList().stream().map(RunPlanTripVO::getServiceNumber).max(Comparator.comparingInt(Integer::parseInt)).orElse("0"); // 当前已有最大服务号 int maxServiceNumber = Integer.parseInt(max); - RealLineConfigVO configVO = mapVO.getConfigVO(); String serviceFormat = String.format("%%0%sd", configVO.getFiguresOfServiceNumber()); inputData.setServiceNumber(String.format(serviceFormat, ++maxServiceNumber)); Integer departureInterval = inputData.getDepartureInterval() < 60 ? 180 : inputData.getDepartureInterval(); inputData.setDepartureInterval(departureInterval); } List newTripList = runPlanGenerator.generatorTrips(userId, inputData, mapVO); + rearrangeTripNumber(configVO, newTripList); BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotTrue(CollectionUtils.isEmpty(newTripList), String.format("生成服务号%s运行图数据失败", inputData.getServiceNumber())); planVO.getTripList().addAll(newTripList); RunPlanDraft planDraft = planVO.convert2Draft(); @@ -460,6 +461,39 @@ public class RunPlanDraftService implements IRunPlanDraftService { runPlanDraftDAO.updateByPrimaryKeySelective(planDraft); } + /** + * 根据线路配置,重排车次号 + */ + private void rearrangeTripNumber(RealLineConfigVO mapConfigVO, List tripList) { + //重排车次号 + if (mapConfigVO.isTripNumberIsUnique()) { + //上下行车次号 + int upTn = 1; + int downTn = 1; + //上下行方向编号 + String upDirection; + String downDirection; + String tripFormat; + if (mapConfigVO.getFiguresOfTripNumber() == 2) { + throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("两位车次号暂不支持车次号唯一"); +// upDirection = ""; +// downDirection = ""; +// tripFormat = "%02d"; + } else { + upDirection = "2"; + downDirection = "1"; + tripFormat = String.format("%%0%sd", mapConfigVO.getFiguresOfTripNumber() - 1); + } + for (RunPlanTripVO tripVO : tripList.stream().sorted(Comparator.comparing(RunPlanTripVO::getStartTime)).collect(Collectors.toList())) { + if (mapConfigVO.isUp(tripVO.getRight())) { + tripVO.setTripNumber(upDirection + String.format(tripFormat, upTn++)); + } else { + tripVO.setTripNumber(downDirection + String.format(tripFormat, downTn++)); + } + } + } + } + @Override @Transactional public void updateRunPlanService(Long planId, String serviceNumber, RunPlanServiceConfigVO serviceConfig, AccountVO accountVO) { diff --git a/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java b/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java index abffb76cd..89c4e7e77 100644 --- a/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java +++ b/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java @@ -83,7 +83,6 @@ public class RunPlanGenerator { inputData.setServiceNumber(String.format(serviceFormat, startServiceNumber + 2)); departEndTime1 = serviceTripList1.get(2).getTimeList().get(0).getArrivalTime(); generateServices(inputData, mapVO, running1Routing, running2Routing, inboundRoutings, outBoundRouting1, runLevelMap, parkTimeMap, reentryData, tripList, initBeginTime, departEndTime1); - rearrangeTripNumber(mapConfigVO, tripList); return tripList; } else if (Objects.nonNull(outBoundRouting2)) { tripList.removeAll(serviceTripList1); @@ -91,7 +90,6 @@ public class RunPlanGenerator { inputData.setServiceNumber(String.format(serviceFormat, startServiceNumber + 3)); departEndTime2 = serviceTripList2.get(2).getTimeList().get(0).getArrivalTime(); generateServices(inputData, mapVO, running2Routing, running1Routing, inboundRoutings, outBoundRouting2, runLevelMap, parkTimeMap, reentryData, tripList, initBeginTime, departEndTime2); - rearrangeTripNumber(mapConfigVO, tripList); return tripList; } } @@ -101,7 +99,6 @@ public class RunPlanGenerator { inputData.setServiceNumber(String.format(serviceFormat, startServiceNumber + 3)); generateServices(inputData, mapVO, running2Routing, running1Routing, inboundRoutings, outBoundRouting2, runLevelMap, parkTimeMap, reentryData, tripList, initBeginTime, departEndTime2); - rearrangeTripNumber(mapConfigVO, tripList); } else { Routing2BoundInfo outBoundRouting = null; @@ -129,39 +126,6 @@ public class RunPlanGenerator { return tripList; } - /** - * 根据线路配置,重排车次号 - */ - private void rearrangeTripNumber(RealLineConfigVO mapConfigVO, List tripList) { - //重排车次号 - if (mapConfigVO.isTripNumberIsUnique()) { - //上下行车次号 - int upTn = 1; - int downTn = 1; - //上下行方向编号 - String upDirection; - String downDirection; - String tripFormat; - if (mapConfigVO.getFiguresOfTripNumber() == 2) { - throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("两位车次号暂不支持车次号唯一"); -// upDirection = ""; -// downDirection = ""; -// tripFormat = "%02d"; - } else { - upDirection = "2"; - downDirection = "1"; - tripFormat = String.format("%%0%sd", mapConfigVO.getFiguresOfTripNumber() - 1); - } - for (RunPlanTripVO tripVO : tripList.stream().sorted(Comparator.comparing(RunPlanTripVO::getStartTime)).collect(Collectors.toList())) { - if (mapConfigVO.isUp(tripVO.getRight())) { - tripVO.setTripNumber(upDirection + String.format(tripFormat, upTn++)); - } else { - tripVO.setTripNumber(downDirection + String.format(tripFormat, downTn++)); - } - } - } - } - private void checkInputTime(RunPlanInputData inputData) { BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(inputData.getOverTime().isAfter(inputData.getBeginTime()), "输入参数错误:发车时间应早于结束时间"); LocalTime beginTimeOffset = inputData.getBeginTime().minusHours(OFFSET_TIME_HOURS); From 1bf100f117d7cf142e1781230d491db14337e2fa Mon Sep 17 00:00:00 2001 From: Jade Date: Wed, 8 Dec 2021 15:46:03 +0800 Subject: [PATCH 19/21] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=AE=B5=20=E5=87=BA?= =?UTF-8?q?=E5=BA=93=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/ATS/service/AtsTrainLoadService.java | 2 +- .../stage/AtsManualTrainStageService.java | 2 +- .../simulation/cbtc/data/plan/TripPlan.java | 13 ++++- .../simulation/cbtc/data/vo/TrainInfo.java | 2 +- .../simulation/cbtc/depot/DepotService.java | 50 +++++++++++++------ 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java index 4c0dac1d1..880150e46 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java @@ -827,7 +827,7 @@ public class AtsTrainLoadService { List allTripPlanList = repository.getAllTripPlanList(); allTripPlanList.forEach(tripPlan -> { if (!systemTime.isBefore(tripPlan.getStartTime())) { - tripPlan.dispatch(); + tripPlan.departure(); tripPlan.finishStationPlanOf(systemTime); } }); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsManualTrainStageService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsManualTrainStageService.java index e7ffaf9ab..f6d4b7193 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsManualTrainStageService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsManualTrainStageService.java @@ -68,7 +68,7 @@ public class AtsManualTrainStageService implements AtsStageService { } if (systemTime.toLocalTime().plusMinutes(10).isAfter(tripPlan.getStartTime())) { this.planTrainStageService.updateTripPlan(simulation, trainInfo, tripPlan); - tripPlan.dispatch(); + tripPlan.departure(); this.realRunRecordService.recordTrainRealRun(simulation, trainInfo, parkSection.getStation(), parkSection, true); break; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/plan/TripPlan.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/plan/TripPlan.java index 99947c05e..7dfcbc5c7 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/plan/TripPlan.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/plan/TripPlan.java @@ -232,11 +232,20 @@ public class TripPlan { return false; } + /** + * 按计划发车 + */ + public void departure() { + this.departure = true; + if (this.isOutbound()) { + this.dispatched = true; + } + } + /** * 按计划派发 */ - public void dispatch() { - this.departure = true; + public void dispatched() { if (this.isOutbound()) { this.dispatched = true; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java index a902f7ea0..e564cd0e9 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java @@ -532,7 +532,7 @@ public class TrainInfo extends MapElement { } public synchronized void applyNewTripPlan(TripPlan tripPlan) { - tripPlan.dispatch(); + tripPlan.departure(); this.serviceNumber = tripPlan.getServiceNumber(); this.tripNumber = tripPlan.getTripNumber(); this.destinationCode = tripPlan.getDestinationCode(); 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 e502933f9..2df2a7c27 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 @@ -2,7 +2,10 @@ package club.joylink.rtss.simulation.cbtc.depot; import club.joylink.rtss.simulation.cbtc.ATS.tools.TrainOutboundLoadTool; import club.joylink.rtss.simulation.cbtc.CI.device.CiRouteService; +import club.joylink.rtss.simulation.cbtc.GroupSimulationService; import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.command.CommandBO; +import club.joylink.rtss.simulation.cbtc.command.CommandInitiateVO; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; import club.joylink.rtss.simulation.cbtc.data.map.Route; @@ -14,10 +17,12 @@ 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.data.vr.VirtualRealityTrain; +import club.joylink.rtss.simulation.cbtc.member.SimulationMember; 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; @@ -25,7 +30,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Queue; import java.util.stream.Collectors; @Component @@ -37,7 +41,10 @@ public class DepotService { @Autowired private TrainOutboundLoadTool trainOutboundLoadTool; - private Map> stationListMap = new HashMap<>(); + @Autowired + private GroupSimulationService groupSimulationService; + + private Map> sectionDispatchMap = new HashMap<>(); private List outboundPlanList = new LinkedList<>(); @@ -68,15 +75,15 @@ public class DepotService { simulation.getRepository().addTrainInfo(trainInfo); } }); - stationListMap.clear(); + sectionDispatchMap.clear(); outboundPlanList.clear(); inboundPlanList.clear(); simulation.getRepository().getSchedulingTrainPlanList().stream(). sorted(Comparator.comparing(schedulingTrainPlan -> schedulingTrainPlan.getOutDepotTrip().getStartTime().toSecondOfDay())) .forEach(schedulingTrainPlan -> { - Queue queue = stationListMap - .computeIfAbsent(schedulingTrainPlan.getOutDepotTrip().getStartSection(), key -> new LinkedList<>()); - queue.add(schedulingTrainPlan); + List planList = sectionDispatchMap + .computeIfAbsent(schedulingTrainPlan.getOutDepotTrip().getStartSection(), key -> new ArrayList<>()); + planList.add(schedulingTrainPlan); }); } @@ -94,7 +101,7 @@ public class DepotService { timeToDeparture(simulation); settingRouteAndMoving(simulation); arriveTransferTrack(simulation); - backToParking(simulation); +// backToParking(simulation); } } @@ -104,13 +111,16 @@ public class DepotService { */ private void timeToDeparture(Simulation simulation) { LocalDateTime systemTime = simulation.getSystemTime(); - stationListMap.forEach((section, list) -> { - SchedulingTrainPlan schedulingTrainPlan = list.peek(); - if (!schedulingTrainPlan.getOutDepotTrip().isDeparture() - && schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) { - if (!outboundPlanList.contains(schedulingTrainPlan)) { - outboundPlanList.add(schedulingTrainPlan); - list.add(list.poll()); + 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(); + } } } }); @@ -139,9 +149,17 @@ public class DepotService { String groupNumber = schedulingTrainPlan.getGroupNumber(); VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); if (train.getSpeed() == 0 - && train.getHeadPosition().getSection().equals(schedulingTrainPlan.getOutDepotTrip().getStartSection())) { + && 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(); ) { @@ -169,7 +187,7 @@ public class DepotService { if (!section.isTransferTrack()) { continue; } - for (SchedulingTrainPlan schedulingTrainPlan : stationListMap.get(section)) { + for (SchedulingTrainPlan schedulingTrainPlan : sectionDispatchMap.get(section)) { if (!schedulingTrainPlan.getInDepotTrip().getEndSection().equals(section)) { continue; } From ce26b80e6a1612513aed12af7689e5b21acd5d68 Mon Sep 17 00:00:00 2001 From: Jade Date: Wed, 8 Dec 2021 17:55:07 +0800 Subject: [PATCH 20/21] =?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); + } + } + } } From 0a52d4d0291225f1989cb78ca1097a5440593fa9 Mon Sep 17 00:00:00 2001 From: Jade Date: Thu, 9 Dec 2021 10:28:13 +0800 Subject: [PATCH 21/21] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=85=8D=E7=BD=AE-?= =?UTF-8?q?=E8=BD=A6=E6=AC=A1=E7=AA=97=E8=BD=A6=E5=A4=B4=E7=BF=BB=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/club/joylink/rtss/vo/map/display/AmendPoints.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/club/joylink/rtss/vo/map/display/AmendPoints.java b/src/main/java/club/joylink/rtss/vo/map/display/AmendPoints.java index 656d68515..5cff4c9f6 100644 --- a/src/main/java/club/joylink/rtss/vo/map/display/AmendPoints.java +++ b/src/main/java/club/joylink/rtss/vo/map/display/AmendPoints.java @@ -15,4 +15,5 @@ public class AmendPoints { private List points; private Point position; private Float rotate; + private Boolean reversal; }