车辆段 逻辑完善
This commit is contained in:
parent
e6f6421e50
commit
ce26b80e6a
@ -227,6 +227,10 @@ public class SimulationDataRepository {
|
||||
*/
|
||||
private Map<Station, List<Section>> parkingTracksMap = new HashMap<>();
|
||||
|
||||
private List<SchedulingTrainPlan> outboundPlanList = new ArrayList<>();
|
||||
|
||||
private List<SchedulingTrainPlan> inboundPlanList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 间隔时间/s
|
||||
*/
|
||||
|
@ -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<Section, List<SchedulingTrainPlan>> sectionDispatchMap = new HashMap<>();
|
||||
|
||||
private List<SchedulingTrainPlan> outboundPlanList = new LinkedList<>();
|
||||
|
||||
private List<SchedulingTrainPlan> 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<SchedulingTrainPlan> 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<SchedulingTrainPlan> 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<String, Object> 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<SchedulingTrainPlan> 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<SchedulingTrainPlan> 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<String, Object> 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<SchedulingTrainPlan> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user