车辆段逻辑

This commit is contained in:
Jade 2021-12-13 11:02:48 +08:00
parent 690acdba5f
commit 6b7a36aeed
2 changed files with 74 additions and 42 deletions

View File

@ -17,6 +17,7 @@ import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vo.TdtStatusVO; import club.joylink.rtss.simulation.cbtc.data.vo.TdtStatusVO;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.simulation.cbtc.data.vr.*; import club.joylink.rtss.simulation.cbtc.data.vr.*;
import club.joylink.rtss.simulation.cbtc.depot.DepotService;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.util.StrUtils; import club.joylink.rtss.util.StrUtils;
@ -227,9 +228,9 @@ public class SimulationDataRepository {
*/ */
private Map<Station, List<Section>> parkingTracksMap = new HashMap<>(); private Map<Station, List<Section>> parkingTracksMap = new HashMap<>();
private List<SchedulingTrainPlan> outboundPlanList = new ArrayList<>(); private List<DepotService.DepotInfo> outboundInfoList = new ArrayList<>();
private List<VirtualRealityTrain> inboundTrainList = new ArrayList<>(); private List<DepotService.DepotInfo> inboundInfoList = new ArrayList<>();
/** /**
* 间隔时间/s * 间隔时间/s

View File

@ -19,10 +19,12 @@ import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService; import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -102,10 +104,15 @@ public class DepotService {
continue; continue;
} }
if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) { if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) {
if (!simulation.getRepository().getOutboundPlanList().contains(schedulingTrainPlan)) { schedulingTrainPlan.getOutDepotTrip().dispatched();
simulation.getRepository().getOutboundPlanList().add(schedulingTrainPlan); // 保存信息
schedulingTrainPlan.getOutDepotTrip().dispatched(); VirtualRealityTrain train = simulation.getRepository().getVRByCode(schedulingTrainPlan.getGroupNumber(), VirtualRealityTrain.class);
} Section startSection = train.getHeadPosition().getSection();
Section endSection = schedulingTrainPlan.getOutDepotTrip().getStartSection();
List<RoutePath> routePaths = simulation.getRepository().queryRoutePaths(startSection, endSection);
RoutePath routePath = routePaths.get(0);
DepotInfo depotInfo = new DepotInfo(endSection, train, routePath);
simulation.getRepository().getOutboundInfoList().add(depotInfo);
} }
} }
} }
@ -116,10 +123,15 @@ public class DepotService {
*/ */
private void backToParking(Simulation simulation) { private void backToParking(Simulation simulation) {
for (TrainInfo trainInfo : simulation.getRepository().getTrainInfoMap().values()) { for (TrainInfo trainInfo : simulation.getRepository().getTrainInfoMap().values()) {
next:
if (trainInfo.isInbound() && trainInfo.isParking()) { if (trainInfo.isInbound() && trainInfo.isParking()) {
VirtualRealityTrain train = simulation.getRepository().getVRByCode(trainInfo.getGroupNumber(), VirtualRealityTrain.class); VirtualRealityTrain train = simulation.getRepository().getVRByCode(trainInfo.getGroupNumber(), VirtualRealityTrain.class);
if (train.getHeadPosition().getSection().isTransferTrack() && train.getTailPosition().getSection().isTransferTrack()) { if (train.getHeadPosition().getSection().isTransferTrack() && train.getTailPosition().getSection().isTransferTrack()) {
simulation.getRepository().getInboundTrainList().add(train); for (DepotInfo depotInfo : simulation.getRepository().getInboundInfoList()) {
if (depotInfo.getTrain().equals(train)) {
break next;
}
}
train.initAsRM(); train.initAsRM();
Section startSection = train.getHeadPosition().getSection(); Section startSection = train.getHeadPosition().getSection();
Section endSection = null; Section endSection = null;
@ -139,6 +151,13 @@ public class DepotService {
break; break;
} }
train.setTarget(endSection); train.setTarget(endSection);
List<RoutePath> routePaths = simulation.getRepository().queryRoutePaths(startSection, endSection);
if (routePaths == null || routePaths.isEmpty()) {
return;
}
RoutePath routePath = routePaths.get(0);
DepotInfo depotInfo = new DepotInfo(endSection, train, routePath);
simulation.getRepository().getInboundInfoList().add(depotInfo);
break; break;
} }
} }
@ -150,36 +169,24 @@ public class DepotService {
* @param simulation * @param simulation
*/ */
private void settingRouteAndMoving(Simulation simulation) { private void settingRouteAndMoving(Simulation simulation) {
for (SchedulingTrainPlan schedulingTrainPlan : simulation.getRepository().getOutboundPlanList()) { for (DepotInfo depotInfo : simulation.getRepository().getOutboundInfoList()) {
VirtualRealityTrain train = simulation.getRepository().getVRByCode(schedulingTrainPlan.getGroupNumber(), VirtualRealityTrain.class); moving(simulation, depotInfo);
moving(simulation, train, schedulingTrainPlan.getOutDepotTrip().getStartSection());
} }
for (VirtualRealityTrain train : simulation.getRepository().getInboundTrainList()) { for (DepotInfo depotInfo : simulation.getRepository().getInboundInfoList()) {
moving(simulation, train, train.getTarget()); moving(simulation, depotInfo);
} }
} }
private void moving(Simulation simulation, VirtualRealityTrain train, Section endSection) { private void moving(Simulation simulation, DepotInfo depotInfo) {
Section startSection = train.getHeadPosition().getSection(); SectionPosition position = new SectionPosition(depotInfo.endSection, depotInfo.endSection.getStopPointByDirection(depotInfo.getRight()));
List<RoutePath> routePaths = simulation.getRepository().queryRoutePaths(startSection, endSection); depotInfo.getTrain().setRobotTargetPosition(position);
if (routePaths == null || routePaths.isEmpty()) { if (!depotInfo.getRouteList().isEmpty()) {
return; Route route = depotInfo.getRouteList().get(0);
} if (route.isLock()) {
RoutePath routePath = routePaths.get(0); depotInfo.getRouteList().remove(0);
Section pathEnd = routePath.getEnd(); }
train.setRobotTargetPosition(new SectionPosition(pathEnd, pathEnd.getStopPointByDirection(routePath.isRight()))); if (!route.isSetting()) {
for (Signal signal : routePath.getSignalList()) { ciRouteService.setRoute(simulation, route);
for (Route route : signal.getRouteList()) {
if (routePath.getRouteList().contains(route)) {
if (route.isSetting()) {
return;
}
if (route.isLock()) {
break;
}
ciRouteService.setRoute(simulation, route);
return;
}
} }
} }
} }
@ -189,13 +196,11 @@ public class DepotService {
* @param simulation * @param simulation
*/ */
private void arriveDestination(Simulation simulation) { private void arriveDestination(Simulation simulation) {
for (Iterator<SchedulingTrainPlan> iterator = simulation.getRepository().getOutboundPlanList().iterator(); iterator.hasNext(); ) { for (Iterator<DepotInfo> iterator = simulation.getRepository().getOutboundInfoList().iterator(); iterator.hasNext(); ) {
SchedulingTrainPlan schedulingTrainPlan = iterator.next(); DepotInfo depotInfo = iterator.next();
String groupNumber = schedulingTrainPlan.getGroupNumber(); VirtualRealityTrain train = depotInfo.getTrain();
VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); if (train.getSpeed() == 0 && train.getHeadPosition().getSection().equals(depotInfo.getEndSection())
if (train.getSpeed() == 0 && train.getTailPosition().getSection().equals(depotInfo.getEndSection())) {
&& train.getHeadPosition().getSection().equals(schedulingTrainPlan.getOutDepotTrip().getStartSection())
&& train.getTailPosition().getSection().equals(schedulingTrainPlan.getOutDepotTrip().getStartSection())) {
// 到达 // 到达
iterator.remove(); iterator.remove();
// 升级 // 升级
@ -207,8 +212,9 @@ public class DepotService {
groupSimulationService.command(simulation, commandInitiateVO, member); groupSimulationService.command(simulation, commandInitiateVO, member);
} }
} }
for (Iterator<VirtualRealityTrain> iterator = simulation.getRepository().getInboundTrainList().iterator(); iterator.hasNext(); ) { for (Iterator<DepotInfo> iterator = simulation.getRepository().getInboundInfoList().iterator(); iterator.hasNext(); ) {
VirtualRealityTrain train = iterator.next(); DepotInfo depotInfo = iterator.next();
VirtualRealityTrain train = depotInfo.getTrain();
if (train.getSpeed() == 0 && train.getHeadPosition().getSection().isParkingTrack() if (train.getSpeed() == 0 && train.getHeadPosition().getSection().isParkingTrack()
&& train.getTailPosition().getSection().isParkingTrack()) { && train.getTailPosition().getSection().isParkingTrack()) {
// 到达 // 到达
@ -217,4 +223,29 @@ public class DepotService {
} }
} }
} }
@Getter
public static class DepotInfo {
private final List<Route> routeList = new ArrayList<>();
private final Section endSection;
private final VirtualRealityTrain train;
private final Boolean right;
public DepotInfo(Section endSection, VirtualRealityTrain train, RoutePath routePath) {
this.endSection = endSection;
this.train = train;
for (Signal signal : routePath.getSignalList()) {
for (Route route : signal.getRouteList()) {
if (routePath.getRouteList().contains(route)) {
routeList.add(route);
}
}
}
this.right = routePath.isRight();
}
}
} }