车辆段 逻辑完善

This commit is contained in:
Jade 2021-12-08 17:55:07 +08:00
parent e6f6421e50
commit ce26b80e6a
2 changed files with 88 additions and 80 deletions

View File

@ -227,6 +227,10 @@ 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<SchedulingTrainPlan> inboundPlanList = new ArrayList<>();
/** /**
* 间隔时间/s * 间隔时间/s
*/ */

View File

@ -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.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 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;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -44,11 +43,8 @@ public class DepotService {
@Autowired @Autowired
private GroupSimulationService groupSimulationService; private GroupSimulationService groupSimulationService;
private Map<Section, List<SchedulingTrainPlan>> sectionDispatchMap = new HashMap<>(); @Autowired
private ATPService atpService;
private List<SchedulingTrainPlan> outboundPlanList = new LinkedList<>();
private List<SchedulingTrainPlan> inboundPlanList = new LinkedList<>();
public void loadDepotTrain(Simulation simulation) { public void loadDepotTrain(Simulation simulation) {
if (!simulation.getRepository().getConfig().isHandleDepot()) { if (!simulation.getRepository().getConfig().isHandleDepot()) {
@ -75,16 +71,6 @@ public class DepotService {
simulation.getRepository().addTrainInfo(trainInfo); 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) { public void addJobs(Simulation simulation) {
@ -99,9 +85,9 @@ public class DepotService {
trainOutboundLoadTool.loadOutboundTrain(simulation); trainOutboundLoadTool.loadOutboundTrain(simulation);
} else { } else {
timeToDeparture(simulation); timeToDeparture(simulation);
backToParking(simulation);
settingRouteAndMoving(simulation); settingRouteAndMoving(simulation);
arriveTransferTrack(simulation); arriveDestination(simulation);
// backToParking(simulation);
} }
} }
@ -111,65 +97,15 @@ public class DepotService {
*/ */
private void timeToDeparture(Simulation simulation) { private void timeToDeparture(Simulation simulation) {
LocalDateTime systemTime = simulation.getSystemTime(); LocalDateTime systemTime = simulation.getSystemTime();
sectionDispatchMap.forEach((section, list) -> { for (SchedulingTrainPlan schedulingTrainPlan : simulation.getRepository().getSchedulingTrainPlanList()) {
for (SchedulingTrainPlan schedulingTrainPlan : list) { if (schedulingTrainPlan.getOutDepotTrip().isDispatched()) {
if (schedulingTrainPlan.getOutDepotTrip().isDispatched()) { continue;
continue;
}
if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) {
if (!outboundPlanList.contains(schedulingTrainPlan)) {
outboundPlanList.add(schedulingTrainPlan);
schedulingTrainPlan.getOutDepotTrip().dispatched();
}
}
} }
}); if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) {
} if (!simulation.getRepository().getOutboundPlanList().contains(schedulingTrainPlan)) {
simulation.getRepository().getOutboundPlanList().add(schedulingTrainPlan);
/** schedulingTrainPlan.getOutDepotTrip().dispatched();
* 列车排进路并运行 }
* @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();
} }
} }
} }
@ -187,22 +123,54 @@ public class DepotService {
if (!section.isTransferTrack()) { if (!section.isTransferTrack()) {
continue; continue;
} }
for (SchedulingTrainPlan schedulingTrainPlan : sectionDispatchMap.get(section)) { for (SchedulingTrainPlan schedulingTrainPlan : simulation.getRepository().getSchedulingTrainPlanList()) {
if (!schedulingTrainPlan.getInDepotTrip().getEndSection().equals(section)) { if (!schedulingTrainPlan.getInDepotTrip().getEndSection().equals(section)) {
continue; continue;
} }
if (!train.getGroupNumber().equals(schedulingTrainPlan.getGroupNumber())) { if (!train.getGroupNumber().equals(schedulingTrainPlan.getGroupNumber())) {
continue; continue;
} }
if (!inboundPlanList.contains(schedulingTrainPlan)) { if (!schedulingTrainPlan.getInDepotTrip().getEndTime().minusMinutes(10)
.isBefore(simulation.getSystemTime().toLocalTime())) {
continue;
}
if (!simulation.getRepository().getInboundPlanList().contains(schedulingTrainPlan)) {
train.initAsRM(); train.initAsRM();
inboundPlanList.add(schedulingTrainPlan); simulation.getRepository().getInboundPlanList().add(schedulingTrainPlan);
break; 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) { private void moving(Simulation simulation, String groupNumber, Section endSection) {
VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class);
Section startSection = train.getHeadPosition().getSection(); 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);
}
}
}
} }