From 7f003ec81685dfdb91416f9ce72535909d49d1ed Mon Sep 17 00:00:00 2001 From: tiger_zhou <123456> Date: Mon, 24 Apr 2023 15:25:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=BD=A6=E5=9B=BE=E4=BE=8B=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=BD=8D=E7=BD=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/ATS/ATSTrainMessageDiagram.java | 174 +++------------ .../cbtc/ATS/ATSTrainMessageDiagram2.java | 208 ++++++++++++++++++ .../cbtc/ATS/data/SortDiagramStation.java | 45 ++++ .../ATS/service/diagram/CalculateDiagram.java | 5 +- .../service/diagram/InOutBoundService.java | 43 ++++ .../ATS/service/diagram/PackingService.java | 42 ++++ .../ATS/service/diagram/RuningService.java | 69 ++++++ .../ATS/service/diagram/TurnBackService.java | 32 +++ 8 files changed, 479 insertions(+), 139 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram2.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/ATS/data/SortDiagramStation.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/InOutBoundService.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/PackingService.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/RuningService.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/TurnBackService.java diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram.java index b51c25a8d..75d9d214b 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram.java @@ -1,7 +1,12 @@ package club.joylink.rtss.simulation.cbtc.ATS; +import club.joylink.rtss.services.cache.ICacheService; +import club.joylink.rtss.simulation.SimulationManager; +import club.joylink.rtss.simulation.cbtc.ATS.data.SortDiagramStation; import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram; +import club.joylink.rtss.simulation.cbtc.ATS.service.diagram.*; import club.joylink.rtss.simulation.cbtc.CTC.data.CtcStationRunPlanLog; +import club.joylink.rtss.simulation.cbtc.GroupSimulationCache; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; @@ -22,11 +27,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import javax.annotation.PostConstruct; import java.io.BufferedReader; import java.io.FileReader; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -39,41 +46,36 @@ public class ATSTrainMessageDiagram { @Autowired private StompMessageService stompMessageService; - public void collect(Simulation simulation){ + @Autowired + private ICacheService cacheService; + + private final static List CALCULATE_DIAGRAM_LIST = Lists.newArrayList(); + + @PostConstruct + private void init(){ + CALCULATE_DIAGRAM_LIST.add(new InOutBoundService()); + CALCULATE_DIAGRAM_LIST.add(new TurnBackService()); + CALCULATE_DIAGRAM_LIST.add(new PackingService()); + CALCULATE_DIAGRAM_LIST.add(new RuningService()); + } + public void collect(Simulation simulation){ + SortDiagramStation diagramStation = this.findDiagramStation(simulation); - KmStation kmStation = new KmStation(simulation); List stationDiagramList = Lists.newArrayList(); for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) { - TrainInfo trainInfo = simulation.getRepository().findSupervisedTrainByGroup(train.getGroupNumber()); - Section target = train.getTarget(); - if(ObjectUtils.anyNull(target,train.getNextStation(),train.getTerminalStation())){ + if(ObjectUtils.anyNull(trainInfo,target,train.getNextStation(),train.getTerminalStation())){ StationDiagram sd = new StationDiagram(train,0F,false); stationDiagramList.add(sd); continue; } - if(Objects.nonNull(trainInfo) && trainInfo.isInbound()){ - StationDiagram sd = new StationDiagram(train,0F,false); - stationDiagramList.add(sd); - continue; - } - Station nextStation = train.getNextStation(); - SectionPosition tailPos = train.getTailPosition(); - - if(nextStation.isDepot() && !tailPos.getSection().isStandTrack()){ - //入库 - StationDiagram sd = new StationDiagram(train,0F,false); - stationDiagramList.add(sd); - }else if(trainInfo.isTurnBack()){ - //列车正在折返 - StationDiagram sd = new StationDiagram(train,0F,true); - sd.setStartStation(train.getNextStation()); - sd.setTurnBack(true); - stationDiagramList.add(sd); - }else{ - Optional optionalDiagram = this.calculateRuning2(simulation,train,trainInfo,kmStation); - optionalDiagram.ifPresent(stationDiagramList::add); + for (CalculateDiagram calculateDiagram : CALCULATE_DIAGRAM_LIST) { + Optional optional = calculateDiagram.calculate(simulation,trainInfo,train,diagramStation); + if(optional.isPresent()){ + stationDiagramList.add(optional.get()); + break; + } } } SocketMessageVO> messageVO = @@ -83,123 +85,19 @@ public class ATSTrainMessageDiagram { } - - - private Optional calculateRuning2(Simulation simulation,VirtualRealityTrain train,TrainInfo trainInfo,KmStation kmStation){ - - Section trainSection = train.getHeadPosition().getSection(); - - Section arttiveSection = simulation.getRepository().getByCode(trainInfo.getEstimatedArriveStandTrack(),Section.class); - - if(train.isParkingAt()){ - if(trainSection.isStandTrack() && Objects.equals(trainSection.getStation().getCode(),trainInfo.getStartStation())){ - //到达始发站 - StationDiagram sd = new StationDiagram(train,true,0F,false); - sd.setStartStation(trainSection.getStation()); - Station nextStation = kmStation.findNext(trainSection.getStation(),train.isRight()); - sd.setEndStation(nextStation); - return Optional.of(sd); - }else if(trainSection.isStandTrack() || (trainSection.isStandTrack() && Objects.equals(trainSection.getStation().getCode(),trainInfo.getEndStation()))){ - //列车停靠车站或到终点站 - StationDiagram sd = new StationDiagram(train,true,1F,true); - Station preStation = kmStation.findPre(trainSection.getStation(),train.isRight()); - sd.setStartStation(preStation); - sd.setEndStation(trainSection.getStation()); - - return Optional.of(sd); - } + private synchronized SortDiagramStation findDiagramStation(Simulation simulation){ + String k = String.format("%s,diagram",simulation.getId()); + Object obj = this.cacheService.get(k); + if(Objects.isNull(obj)){ + SortDiagramStation ds = new SortDiagramStation(simulation); + this.cacheService.putExpired(k,ds,10, TimeUnit.MINUTES); + return ds; } - - if(Objects.equals(train.getNextStation().getCode(),trainInfo.getStartStation())){ - StationDiagram sd = new StationDiagram(train,true,0F,false); - sd.setStartStation(train.getNextStation()); - Station nextStation = kmStation.findNext(train.getNextStation(),train.isRight()); - sd.setEndStation(nextStation); - return Optional.of(sd); - } - - String d = Objects.isNull(trainInfo.getEstimatedLeaveStandTrack()) ? trainInfo.getActualLeaveStandTrack() : trainInfo.getEstimatedLeaveStandTrack(); - Section leaveSeaction = simulation.getRepository().getByCode(d,Section.class); - Station endStation = simulation.getRepository().getByCode(trainInfo.getEndStation(),Station.class); - if(Objects.equals(leaveSeaction.getStation().getCode(),trainInfo.getEndStation())){ - StationDiagram sd = new StationDiagram(train,true,1F,true); - Station preStation = kmStation.findPre(leaveSeaction.getStation(),train.isRight()); - sd.setStartStation(preStation); - sd.setEndStation(endStation); - return Optional.of(sd); - }else{ - Station targetStation = kmStation.findNext(leaveSeaction.getStation(),train.isRight()); - Section targetStand = targetStation.getStandOf(train.isRight()).get(0).getSection(); - Float complateDis = this.calculateStationRatio(leaveSeaction,targetStand,train); - StationDiagram stationDiagram = new StationDiagram(train,true,complateDis,false); - stationDiagram.setStartStation(leaveSeaction.getStation()); - stationDiagram.setEndStation(targetStand.getStation()); - return Optional.of(stationDiagram); - } - - - + return (SortDiagramStation) obj; } - private Float calculateStationRatio(Section begin,Section end,VirtualRealityTrain train){ - float totalDis = CalculateService.calculateDistance(begin,end,train.isRight()); - if(totalDis == 0F){ - return 1F; - } - try{ - float runDis = totalDis - train.getTargetDistance(); - double t = 0D; - if(runDis > 0){ - t = runDis / totalDis;; - } - float d = new BigDecimal(t).setScale(3, RoundingMode.HALF_UP).floatValue(); - log.debug("车次[{}] 方向[{}] 车头区段[{}] 车尾区段[{}] 是否停靠[{}] 查找开始区段[{}] 结束区段[{}] 距离总长[{}] 剩余距离[{}] 行驶完成度[{}]" - ,train.getGroupNumber(),train.isRight(),train.getHeadPosition().getSection().getCode() - ,train.getTailPosition().getSection().getCode(),train.isParkingAt(),begin.getCode(),end.getCode() , totalDis ,train.getTargetDistance() ,d); - return Math.abs(d); - }catch (Exception e){ - log.error("计算失败 groupNum:{},isRight:{},begin:{},end:{},totalDis:{},targetDis:{}",train.getGroupNumber() ,train.isRight(),begin.getCode() ,end.getCode() ,totalDis , train.getTargetDistance()); - return null; - } - } - - public static class KmStation{ - private List stationList; - public KmStation(Simulation simulation){ - List list = simulation.getRepository().getListByType(MapElement.DeviceType.STATION,Station.class); - stationList = list.stream().sorted((o1, o2) -> Float.compare(o1.getKmPostVal(),o2.getKmPostVal())).filter(d->!d.isDepot()).collect(Collectors.toList()); - } - - public int findIndex(Station station){ - return IntStream.range(0,stationList.size()).filter(d->Objects.equals(stationList.get(d).getCode(),station.getCode())).findFirst().getAsInt(); - } - public Station findNext(Station station,boolean isRight){ - int index = this.findIndex(station); - if(isRight){ - return stationList.get(index + 1); - }else{ - - return stationList.get(index - 1); - } - - } - public Station findPre(Station station,boolean isRight){ - int index = this.findIndex(station); - if(isRight){ - return stationList.get(index - 1); - }else{ - return stationList.get(index + 1); - - } - } - public Station find(Station station){ - int index = this.findIndex(station); - return stationList.get(index); - } - - } public void addJobs(Simulation simulation){ simulation.addFixedRateJob(SimulationModule.TRAIN_DIAGRAM.name(), () -> collect(simulation), SimulationConstants.TRAIN_DIAGRAM_RATE); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram2.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram2.java new file mode 100644 index 000000000..a6e916b72 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSTrainMessageDiagram2.java @@ -0,0 +1,208 @@ +/* +package club.joylink.rtss.simulation.cbtc.ATS; + +import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram; +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; +import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; +import club.joylink.rtss.simulation.cbtc.data.CalculateService; +import club.joylink.rtss.simulation.cbtc.data.map.MapElement; +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 club.joylink.rtss.vo.client.SocketMessageVO; +import club.joylink.rtss.vo.client.factory.SocketMessageFactory; +import club.joylink.rtss.websocket.StompMessageService; +import com.google.common.collect.Lists; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +*/ +/** + * 收集列车相关信息 + *//* + +@Component +@Slf4j +public class ATSTrainMessageDiagram2 { + @Autowired + private StompMessageService stompMessageService; + + public void collect(Simulation simulation){ + + KmStation kmStation = new KmStation(simulation); + List stationDiagramList = Lists.newArrayList(); + for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) { + TrainInfo trainInfo = simulation.getRepository().findSupervisedTrainByGroup(train.getGroupNumber()); + Section target = train.getTarget(); + if(ObjectUtils.anyNull(trainInfo,target,train.getNextStation(),train.getTerminalStation())){ + StationDiagram sd = new StationDiagram(train,0F,false); + stationDiagramList.add(sd); + continue; + } + if(Objects.nonNull(trainInfo) && trainInfo.isInbound()){ + StationDiagram sd = new StationDiagram(train,0F,false); + stationDiagramList.add(sd); + continue; + } + Station nextStation = train.getNextStation(); + SectionPosition tailPos = train.getTailPosition(); + + if(nextStation.isDepot() && !tailPos.getSection().isStandTrack()){ + //入库 + StationDiagram sd = new StationDiagram(train,0F,false); + stationDiagramList.add(sd); + }else if(trainInfo.isTurnBack()){ + //列车正在折返 + StationDiagram sd = new StationDiagram(train,0F,true); + sd.setStartStation(train.getNextStation()); + sd.setTurnBack(true); + stationDiagramList.add(sd); + }else{ + Optional optionalDiagram = this.calculateRuning2(simulation,train,trainInfo,kmStation); + optionalDiagram.ifPresent(stationDiagramList::add); + } + } + SocketMessageVO> messageVO = + SocketMessageFactory.buildAtsStationDiagram(simulation.getId(), stationDiagramList); + Set sessions = simulation.getSimulationUserIds(); + stompMessageService.sendToUser(sessions, messageVO); + } + + + + + private Optional calculateRuning2(Simulation simulation,VirtualRealityTrain train,TrainInfo trainInfo,KmStation kmStation){ + + Section trainSection = train.getHeadPosition().getSection(); + + Section arttiveSection = simulation.getRepository().getByCode(trainInfo.getEstimatedArriveStandTrack(),Section.class); + + if(train.isParkingAt()){ + if(trainSection.isStandTrack() && Objects.equals(trainSection.getStation().getCode(),trainInfo.getStartStation())){ + //到达始发站 + StationDiagram sd = new StationDiagram(train,true,0F,false); + sd.setStartStation(trainSection.getStation()); + Station nextStation = kmStation.findNext(trainSection.getStation(),train.isRight()); + sd.setEndStation(nextStation); + return Optional.of(sd); + }else if(trainSection.isStandTrack() || (trainSection.isStandTrack() && Objects.equals(trainSection.getStation().getCode(),trainInfo.getEndStation()))){ + //列车停靠车站或到终点站 + StationDiagram sd = new StationDiagram(train,true,1F,true); + Station preStation = kmStation.findPre(trainSection.getStation(),train.isRight()); + sd.setStartStation(preStation); + sd.setEndStation(trainSection.getStation()); + + return Optional.of(sd); + } + } + + if(Objects.equals(train.getNextStation().getCode(),trainInfo.getStartStation())){ + StationDiagram sd = new StationDiagram(train,true,0F,false); + sd.setStartStation(train.getNextStation()); + Station nextStation = kmStation.findNext(train.getNextStation(),train.isRight()); + sd.setEndStation(nextStation); + return Optional.of(sd); + } + + String d = Objects.isNull(trainInfo.getEstimatedLeaveStandTrack()) ? trainInfo.getActualLeaveStandTrack() : trainInfo.getEstimatedLeaveStandTrack(); + Section leaveSeaction = simulation.getRepository().getByCode(d,Section.class); + Station endStation = simulation.getRepository().getByCode(trainInfo.getEndStation(),Station.class); + if(Objects.equals(leaveSeaction.getStation().getCode(),trainInfo.getEndStation())){ + StationDiagram sd = new StationDiagram(train,true,1F,true); + Station preStation = kmStation.findPre(leaveSeaction.getStation(),train.isRight()); + sd.setStartStation(preStation); + sd.setEndStation(endStation); + return Optional.of(sd); + }else{ + Station targetStation = kmStation.findNext(leaveSeaction.getStation(),train.isRight()); + Section targetStand = targetStation.getStandOf(train.isRight()).get(0).getSection(); + Float complateDis = this.calculateStationRatio(leaveSeaction,targetStand,train); + StationDiagram stationDiagram = new StationDiagram(train,true,complateDis,false); + stationDiagram.setStartStation(leaveSeaction.getStation()); + stationDiagram.setEndStation(targetStand.getStation()); + return Optional.of(stationDiagram); + } + + + + } + + + + private Float calculateStationRatio(Section begin,Section end,VirtualRealityTrain train){ + float totalDis = CalculateService.calculateDistance(begin,end,train.isRight()); + if(totalDis == 0F){ + return 1F; + } + try{ + float runDis = totalDis - train.getTargetDistance(); + double t = 0D; + if(runDis > 0){ + t = runDis / totalDis;; + } + float d = new BigDecimal(t).setScale(3, RoundingMode.HALF_UP).floatValue(); + log.debug("车次[{}] 方向[{}] 车头区段[{}] 车尾区段[{}] 是否停靠[{}] 查找开始区段[{}] 结束区段[{}] 距离总长[{}] 剩余距离[{}] 行驶完成度[{}]" + ,train.getGroupNumber(),train.isRight(),train.getHeadPosition().getSection().getCode() + ,train.getTailPosition().getSection().getCode(),train.isParkingAt(),begin.getCode(),end.getCode() , totalDis ,train.getTargetDistance() ,d); + return Math.abs(d); + }catch (Exception e){ + log.error("计算失败 groupNum:{},isRight:{},begin:{},end:{},totalDis:{},targetDis:{}",train.getGroupNumber() ,train.isRight(),begin.getCode() ,end.getCode() ,totalDis , train.getTargetDistance()); + return null; + } + } + + public static class KmStation{ + private List stationList; + public KmStation(Simulation simulation){ + List list = simulation.getRepository().getListByType(MapElement.DeviceType.STATION,Station.class); + stationList = list.stream().sorted((o1, o2) -> Float.compare(o1.getKmPostVal(),o2.getKmPostVal())).filter(d->!d.isDepot()).collect(Collectors.toList()); + } + + public int findIndex(Station station){ + return IntStream.range(0,stationList.size()).filter(d->Objects.equals(stationList.get(d).getCode(),station.getCode())).findFirst().getAsInt(); + } + public Station findNext(Station station,boolean isRight){ + int index = this.findIndex(station); + if(isRight){ + return stationList.get(index + 1); + }else{ + + return stationList.get(index - 1); + } + + } + public Station findPre(Station station,boolean isRight){ + int index = this.findIndex(station); + if(isRight){ + return stationList.get(index - 1); + }else{ + return stationList.get(index + 1); + + } + } + public Station find(Station station){ + int index = this.findIndex(station); + return stationList.get(index); + } + + } + + public void addJobs(Simulation simulation){ + simulation.addFixedRateJob(SimulationModule.TRAIN_DIAGRAM.name(), () -> collect(simulation), SimulationConstants.TRAIN_DIAGRAM_RATE); + } +} +*/ diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/data/SortDiagramStation.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/data/SortDiagramStation.java new file mode 100644 index 000000000..adcc21a9f --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/data/SortDiagramStation.java @@ -0,0 +1,45 @@ +package club.joylink.rtss.simulation.cbtc.ATS.data; + +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.data.map.MapElement; +import club.joylink.rtss.simulation.cbtc.data.map.Station; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class SortDiagramStation { + private List stationList; + public SortDiagramStation(Simulation simulation){ + List list = simulation.getRepository().getListByType(MapElement.DeviceType.STATION,Station.class); + stationList = list.stream().sorted((o1, o2) -> Float.compare(o1.getKmPostVal(),o2.getKmPostVal())).filter(d->!d.isDepot()).collect(Collectors.toList()); + } + + public int findIndex(Station station){ + return IntStream.range(0,stationList.size()).filter(d-> Objects.equals(stationList.get(d).getCode(),station.getCode())).findFirst().getAsInt(); + } + public Station findNext(Station station,boolean isRight){ + int index = this.findIndex(station); + if(isRight){ + return stationList.get(index + 1); + }else{ + + return stationList.get(index - 1); + } + + } + public Station findPre(Station station,boolean isRight){ + int index = this.findIndex(station); + if(isRight){ + return stationList.get(index - 1); + }else{ + return stationList.get(index + 1); + + } + } + public Station find(Station station){ + int index = this.findIndex(station); + return stationList.get(index); + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/CalculateDiagram.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/CalculateDiagram.java index 2b76041cb..c5d33342f 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/CalculateDiagram.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/CalculateDiagram.java @@ -1,12 +1,15 @@ package club.joylink.rtss.simulation.cbtc.ATS.service.diagram; +import club.joylink.rtss.simulation.cbtc.ATS.data.SortDiagramStation; import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram; +import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; +import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import java.util.Optional; public interface CalculateDiagram { - Optional calculate(VirtualRealityTrain train, TripPlan tripPlan); + Optional calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/InOutBoundService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/InOutBoundService.java new file mode 100644 index 000000000..a6f7418bb --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/InOutBoundService.java @@ -0,0 +1,43 @@ +package club.joylink.rtss.simulation.cbtc.ATS.service.diagram; + +import club.joylink.rtss.simulation.cbtc.ATS.data.SortDiagramStation; +import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram; +import club.joylink.rtss.simulation.cbtc.Simulation; +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 java.util.Objects; +import java.util.Optional; + +/** + * 车辆出入库 + */ +public class InOutBoundService implements CalculateDiagram{ + + @Override + public Optional calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation){ + if(trainInfo.isInbound()){ + StationDiagram sd = new StationDiagram(train,0F,false); + return Optional.of(sd); + } + Station nextStation = train.getNextStation(); + SectionPosition tailPos = train.getTailPosition(); + + if(nextStation.isDepot() && !tailPos.getSection().isStandTrack()) { + //入库 + StationDiagram sd = new StationDiagram(train, 0F, false); + return Optional.of(sd); + } + if(Objects.equals(nextStation.getCode(),trainInfo.getStartStation())){ + //出库 + StationDiagram sd = new StationDiagram(train,true,0F,false); + sd.setStartStation(train.getNextStation()); + Station nextStopStation = diagramStation.findNext(nextStation,train.isRight()); + sd.setEndStation(nextStopStation); + return Optional.of(sd); + } + return Optional.empty(); + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/PackingService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/PackingService.java new file mode 100644 index 000000000..3d9f11de2 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/PackingService.java @@ -0,0 +1,42 @@ +package club.joylink.rtss.simulation.cbtc.ATS.service.diagram; + +import club.joylink.rtss.simulation.cbtc.ATS.data.SortDiagramStation; +import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram; +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.vo.TrainInfo; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; + +import java.util.Objects; +import java.util.Optional; + +/** + * 车辆停靠站 + */ +public class PackingService implements CalculateDiagram{ + + @Override + public Optional calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation){ + Section trainSection = train.getHeadPosition().getSection(); + if(train.isParkingAt()){ + if(trainSection.isStandTrack() && Objects.equals(trainSection.getStation().getCode(),trainInfo.getStartStation())){ + //停留在始发站 + StationDiagram sd = new StationDiagram(train,true,0F,false); + sd.setStartStation(trainSection.getStation()); + Station nextStation = diagramStation.findNext(trainSection.getStation(),train.isRight()); + sd.setEndStation(nextStation); + return Optional.of(sd); + }else if(trainSection.isStandTrack() || (trainSection.isStandTrack() && Objects.equals(trainSection.getStation().getCode(),trainInfo.getEndStation()))){ + //列车停靠车站或到终点站 + StationDiagram sd = new StationDiagram(train,true,1F,true); + Station preStation = diagramStation.findPre(trainSection.getStation(),train.isRight()); + sd.setStartStation(preStation); + sd.setEndStation(trainSection.getStation()); + return Optional.of(sd); + } + //中途停靠站不处理 + } + return Optional.empty(); + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/RuningService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/RuningService.java new file mode 100644 index 000000000..0836382a7 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/RuningService.java @@ -0,0 +1,69 @@ +package club.joylink.rtss.simulation.cbtc.ATS.service.diagram; + +import club.joylink.rtss.simulation.cbtc.ATS.data.SortDiagramStation; +import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram; +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.data.CalculateService; +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.vo.TrainInfo; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; +import lombok.extern.slf4j.Slf4j; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Objects; +import java.util.Optional; + +/** + * 车辆运行中 + */ +@Slf4j +public class RuningService implements CalculateDiagram{ + + @Override + public Optional calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation){ + String d = Objects.isNull(trainInfo.getEstimatedLeaveStandTrack()) ? trainInfo.getActualLeaveStandTrack() : trainInfo.getEstimatedLeaveStandTrack(); + Section leaveSeaction = simulation.getRepository().getByCode(d,Section.class); + Station endStation = simulation.getRepository().getByCode(trainInfo.getEndStation(),Station.class); + if(Objects.equals(leaveSeaction.getStation().getCode(),trainInfo.getEndStation())){ + StationDiagram sd = new StationDiagram(train,true,1F,true); + Station preStation = diagramStation.findPre(leaveSeaction.getStation(),train.isRight()); + sd.setStartStation(preStation); + sd.setEndStation(endStation); + return Optional.of(sd); + }else{ + Station targetStation = diagramStation.findNext(leaveSeaction.getStation(),train.isRight()); + Section targetStand = targetStation.getStandOf(train.isRight()).get(0).getSection(); + Float complateDis = this.calculateStationRatio(leaveSeaction,targetStand,train); + StationDiagram stationDiagram = new StationDiagram(train,true,complateDis,false); + stationDiagram.setStartStation(leaveSeaction.getStation()); + stationDiagram.setEndStation(targetStand.getStation()); + return Optional.of(stationDiagram); + } + + } + + private Float calculateStationRatio(Section begin,Section end,VirtualRealityTrain train){ + float totalDis = CalculateService.calculateDistance(begin,end,train.isRight()); + if(totalDis == 0F){ + return 1F; + } + try{ + float runDis = totalDis - train.getTargetDistance(); + double t = 0D; + if(runDis > 0){ + t = runDis / totalDis;; + } + float d = new BigDecimal(t).setScale(3, RoundingMode.HALF_UP).floatValue(); + log.debug("车次[{}] 方向[{}] 车头区段[{}] 车尾区段[{}] 是否停靠[{}] 查找开始区段[{}] 结束区段[{}] 距离总长[{}] 剩余距离[{}] 行驶完成度[{}]" + ,train.getGroupNumber(),train.isRight(),train.getHeadPosition().getSection().getCode() + ,train.getTailPosition().getSection().getCode(),train.isParkingAt(),begin.getCode(),end.getCode() , totalDis ,train.getTargetDistance() ,d); + return Math.abs(d); + }catch (Exception e){ + log.error("计算失败 groupNum:{},isRight:{},begin:{},end:{},totalDis:{},targetDis:{}",train.getGroupNumber() ,train.isRight(),begin.getCode() ,end.getCode() ,totalDis , train.getTargetDistance()); + return null; + } + } + +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/TurnBackService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/TurnBackService.java new file mode 100644 index 000000000..76dc2a4e7 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/diagram/TurnBackService.java @@ -0,0 +1,32 @@ +package club.joylink.rtss.simulation.cbtc.ATS.service.diagram; + +import club.joylink.rtss.simulation.cbtc.ATS.data.SortDiagramStation; +import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram; +import club.joylink.rtss.simulation.cbtc.Simulation; +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 java.util.Objects; +import java.util.Optional; + +/** + * 车辆折返 + */ +public class TurnBackService implements CalculateDiagram{ + + @Override + public Optional calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation){ + if(trainInfo.isTurnBack()){ + //列车正在折返 + StationDiagram sd = new StationDiagram(train,0F,true); + sd.setStartStation(train.getNextStation()); + Station nextStopStation = diagramStation.findNext(train.getNextStation(),train.isRight()); + sd.setEndStation(nextStopStation); + sd.setTurnBack(true); + Optional.of(sd); + } + return Optional.empty(); + } +}