车辆段逻辑
This commit is contained in:
parent
cae20aba53
commit
645bfee559
@ -37,7 +37,9 @@ public class DepotService {
|
||||
|
||||
private Map<Section, Queue<SchedulingTrainPlan>> stationListMap = new HashMap<>();
|
||||
|
||||
private List<SchedulingTrainPlan> schedulingTrainPlanList = new LinkedList<>();
|
||||
private List<SchedulingTrainPlan> outboundPlanList = new LinkedList<>();
|
||||
|
||||
private List<SchedulingTrainPlan> inboundPlanList = new LinkedList<>();
|
||||
|
||||
public void loadDepotTrain(Simulation simulation) {
|
||||
if (!simulation.getRepository().getConfig().isHandleDepot()) {
|
||||
@ -65,11 +67,12 @@ public class DepotService {
|
||||
}
|
||||
});
|
||||
stationListMap.clear();
|
||||
schedulingTrainPlanList.clear();
|
||||
outboundPlanList.clear();
|
||||
simulation.getRepository().getSchedulingTrainPlanList().stream().
|
||||
sorted(Comparator.comparing(schedulingTrainPlan -> schedulingTrainPlan.getOutDepotTrip().getStartTime().toSecondOfDay()))
|
||||
.forEach(schedulingTrainPlan -> {
|
||||
Queue<SchedulingTrainPlan> queue = stationListMap.computeIfAbsent(schedulingTrainPlan.getOutDepotTrip().getStartSection(), key -> new LinkedList<>());
|
||||
Queue<SchedulingTrainPlan> queue = stationListMap
|
||||
.computeIfAbsent(schedulingTrainPlan.getOutDepotTrip().getStartSection(), key -> new LinkedList<>());
|
||||
queue.add(schedulingTrainPlan);
|
||||
});
|
||||
}
|
||||
@ -88,6 +91,7 @@ public class DepotService {
|
||||
timeToDeparture(simulation);
|
||||
settingRouteAndMoving(simulation);
|
||||
arriveTransferTrack(simulation);
|
||||
backToParking(simulation);
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,8 +104,10 @@ public class DepotService {
|
||||
stationListMap.forEach((section, list) -> {
|
||||
SchedulingTrainPlan schedulingTrainPlan = list.peek();
|
||||
if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(20).isBefore(systemTime.toLocalTime())) {
|
||||
schedulingTrainPlanList.add(list.poll());
|
||||
list.add(schedulingTrainPlan);
|
||||
if (!outboundPlanList.contains(schedulingTrainPlan)) {
|
||||
outboundPlanList.add(schedulingTrainPlan);
|
||||
list.add(list.poll());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -111,25 +117,11 @@ public class DepotService {
|
||||
* @param simulation
|
||||
*/
|
||||
private void settingRouteAndMoving(Simulation simulation) {
|
||||
for (SchedulingTrainPlan schedulingTrainPlan : schedulingTrainPlanList) {
|
||||
String groupNumber = schedulingTrainPlan.getGroupNumber();
|
||||
VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class);
|
||||
List<RoutePath> routePaths = simulation.getRepository().queryRoutePathsByStart(train.getHeadPosition().getSection());
|
||||
if (routePaths.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
RoutePath routePath = routePaths.get(0);
|
||||
for (Route route : routePath.getRouteList()) {
|
||||
if (route.isSetting()) {
|
||||
continue;
|
||||
}
|
||||
if (route.isLock()) {
|
||||
continue;
|
||||
}
|
||||
ciRouteService.setRoute(simulation, route);
|
||||
}
|
||||
Section lastSection = routePath.getLastSection();
|
||||
train.setRobotTargetPosition(new SectionPosition(lastSection, lastSection.getStopPointByDirection(routePath.isRight())));
|
||||
for (SchedulingTrainPlan schedulingTrainPlan : outboundPlanList) {
|
||||
moving(simulation, schedulingTrainPlan.getGroupNumber(), schedulingTrainPlan.getOutDepotTrip().getStartSection());
|
||||
}
|
||||
for (SchedulingTrainPlan schedulingTrainPlan : inboundPlanList) {
|
||||
moving(simulation, schedulingTrainPlan.getGroupNumber(), schedulingTrainPlan.getInDepotTrip().getEndSection());
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,14 +130,75 @@ public class DepotService {
|
||||
* @param simulation
|
||||
*/
|
||||
private void arriveTransferTrack(Simulation simulation) {
|
||||
for (SchedulingTrainPlan schedulingTrainPlan : schedulingTrainPlanList) {
|
||||
for (SchedulingTrainPlan schedulingTrainPlan : outboundPlanList) {
|
||||
String groupNumber = schedulingTrainPlan.getGroupNumber();
|
||||
VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class);
|
||||
List<RoutePath> routePaths = simulation.getRepository().queryRoutePathsByStart(train.getHeadPosition().getSection());
|
||||
if (train.isParkingAt() && train.getHeadPosition().getSection().equals(routePaths.get(0).getLastSection())) {
|
||||
if (train.isParkingAt()
|
||||
&& train.getHeadPosition().getSection().equals(schedulingTrainPlan.getOutDepotTrip().getStartSection())) {
|
||||
// 到达
|
||||
schedulingTrainPlanList.remove(schedulingTrainPlan);
|
||||
outboundPlanList.remove(schedulingTrainPlan);
|
||||
train.setServiceNumber(schedulingTrainPlan.getOutDepotTrip().getServiceNumber());
|
||||
train.setTripNumber(schedulingTrainPlan.getOutDepotTrip().getTripNumber());
|
||||
train.setCommunication(true);
|
||||
}
|
||||
}
|
||||
for (SchedulingTrainPlan schedulingTrainPlan : inboundPlanList) {
|
||||
String groupNumber = schedulingTrainPlan.getGroupNumber();
|
||||
VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class);
|
||||
if (train.isParkingAt()
|
||||
&& train.getHeadPosition().getSection().equals(schedulingTrainPlan.getInDepotTrip().getEndSection())) {
|
||||
// 到达
|
||||
inboundPlanList.remove(schedulingTrainPlan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 筛选入库
|
||||
* @param simulation
|
||||
*/
|
||||
private void backToParking(Simulation simulation) {
|
||||
for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) {
|
||||
if (!train.isParkingAt()) {
|
||||
continue;
|
||||
}
|
||||
Section section = train.getHeadPosition().getSection();
|
||||
if (!section.isTransferTrack()) {
|
||||
continue;
|
||||
}
|
||||
for (SchedulingTrainPlan schedulingTrainPlan : stationListMap.get(section)) {
|
||||
if (!schedulingTrainPlan.getInDepotTrip().getEndSection().equals(section)) {
|
||||
continue;
|
||||
}
|
||||
if (!train.getGroupNumber().equals(schedulingTrainPlan.getGroupNumber())) {
|
||||
continue;
|
||||
}
|
||||
if (!inboundPlanList.contains(schedulingTrainPlan)) {
|
||||
train.initAsRM();
|
||||
inboundPlanList.add(schedulingTrainPlan);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void moving(Simulation simulation, String groupNumber, Section endSection) {
|
||||
VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class);
|
||||
Section startSection = train.getHeadPosition().getSection();
|
||||
List<RoutePath> routePaths = simulation.getRepository().queryRoutePaths(startSection, endSection);
|
||||
if (routePaths == null || routePaths.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
RoutePath routePath = routePaths.get(0);
|
||||
for (Route route : routePath.getRouteList()) {
|
||||
if (route.isSetting()) {
|
||||
continue;
|
||||
}
|
||||
if (route.isLock()) {
|
||||
continue;
|
||||
}
|
||||
ciRouteService.setRoute(simulation, route);
|
||||
}
|
||||
Section lastSection = routePath.getEnd();
|
||||
train.setRobotTargetPosition(new SectionPosition(lastSection, lastSection.getStopPointByDirection(routePath.isRight())));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user