列车图例显示位置调整

This commit is contained in:
tiger_zhou 2023-04-24 15:25:22 +08:00
parent 786a56b8d1
commit 7f003ec816
8 changed files with 479 additions and 139 deletions

View File

@ -1,7 +1,12 @@
package club.joylink.rtss.simulation.cbtc.ATS; 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.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.CTC.data.CtcStationRunPlanLog;
import club.joylink.rtss.simulation.cbtc.GroupSimulationCache;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; 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.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.FileReader; import java.io.FileReader;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
@ -39,41 +46,36 @@ public class ATSTrainMessageDiagram {
@Autowired @Autowired
private StompMessageService stompMessageService; private StompMessageService stompMessageService;
public void collect(Simulation simulation){ @Autowired
private ICacheService cacheService;
private final static List<CalculateDiagram> 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<StationDiagram> stationDiagramList = Lists.newArrayList(); List<StationDiagram> stationDiagramList = Lists.newArrayList();
for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) { for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) {
TrainInfo trainInfo = simulation.getRepository().findSupervisedTrainByGroup(train.getGroupNumber()); TrainInfo trainInfo = simulation.getRepository().findSupervisedTrainByGroup(train.getGroupNumber());
Section target = train.getTarget(); 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); StationDiagram sd = new StationDiagram(train,0F,false);
stationDiagramList.add(sd); stationDiagramList.add(sd);
continue; continue;
} }
if(Objects.nonNull(trainInfo) && trainInfo.isInbound()){ for (CalculateDiagram calculateDiagram : CALCULATE_DIAGRAM_LIST) {
StationDiagram sd = new StationDiagram(train,0F,false); Optional<StationDiagram> optional = calculateDiagram.calculate(simulation,trainInfo,train,diagramStation);
stationDiagramList.add(sd); if(optional.isPresent()){
continue; stationDiagramList.add(optional.get());
} break;
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<StationDiagram> optionalDiagram = this.calculateRuning2(simulation,train,trainInfo,kmStation);
optionalDiagram.ifPresent(stationDiagramList::add);
} }
} }
SocketMessageVO<List<StationDiagram>> messageVO = SocketMessageVO<List<StationDiagram>> messageVO =
@ -83,123 +85,19 @@ public class ATSTrainMessageDiagram {
} }
private synchronized SortDiagramStation findDiagramStation(Simulation simulation){
String k = String.format("%s,diagram",simulation.getId());
private Optional<StationDiagram> calculateRuning2(Simulation simulation,VirtualRealityTrain train,TrainInfo trainInfo,KmStation kmStation){ Object obj = this.cacheService.get(k);
if(Objects.isNull(obj)){
Section trainSection = train.getHeadPosition().getSection(); SortDiagramStation ds = new SortDiagramStation(simulation);
this.cacheService.putExpired(k,ds,10, TimeUnit.MINUTES);
Section arttiveSection = simulation.getRepository().getByCode(trainInfo.getEstimatedArriveStandTrack(),Section.class); return ds;
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);
}
} }
return (SortDiagramStation) obj;
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<Station> stationList;
public KmStation(Simulation simulation){
List<Station> 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){ public void addJobs(Simulation simulation){
simulation.addFixedRateJob(SimulationModule.TRAIN_DIAGRAM.name(), () -> collect(simulation), SimulationConstants.TRAIN_DIAGRAM_RATE); simulation.addFixedRateJob(SimulationModule.TRAIN_DIAGRAM.name(), () -> collect(simulation), SimulationConstants.TRAIN_DIAGRAM_RATE);

View File

@ -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<StationDiagram> 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<StationDiagram> optionalDiagram = this.calculateRuning2(simulation,train,trainInfo,kmStation);
optionalDiagram.ifPresent(stationDiagramList::add);
}
}
SocketMessageVO<List<StationDiagram>> messageVO =
SocketMessageFactory.buildAtsStationDiagram(simulation.getId(), stationDiagramList);
Set<String> sessions = simulation.getSimulationUserIds();
stompMessageService.sendToUser(sessions, messageVO);
}
private Optional<StationDiagram> 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<Station> stationList;
public KmStation(Simulation simulation){
List<Station> 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);
}
}
*/

View File

@ -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<Station> stationList;
public SortDiagramStation(Simulation simulation){
List<Station> 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);
}
}

View File

@ -1,12 +1,15 @@
package club.joylink.rtss.simulation.cbtc.ATS.service.diagram; 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.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.plan.TripPlan;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import java.util.Optional; import java.util.Optional;
public interface CalculateDiagram { public interface CalculateDiagram {
Optional<StationDiagram> calculate(VirtualRealityTrain train, TripPlan tripPlan); Optional<StationDiagram> calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation);
} }

View File

@ -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<StationDiagram> 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();
}
}

View File

@ -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<StationDiagram> 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();
}
}

View File

@ -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<StationDiagram> 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;
}
}
}

View File

@ -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<StationDiagram> 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();
}
}