运行线添加筛选进路列表逻辑

This commit is contained in:
joylink_zhangsai 2021-03-10 19:42:20 +08:00
parent d96b32d88a
commit a415ee4ad3
4 changed files with 101 additions and 19 deletions

View File

@ -602,15 +602,14 @@ public class InterlockBuilder2 {
runPath = new ArrayList<>();
routes = new ArrayList<>();
//从左端车站开始选择路径
startSection4RoutePath = screeningSection4DestinationCode(leftStation, leftFrontTurnBack, necessarySectionSet, true);
startSection4RoutePath = selectSection4DestinationCode(leftStation, leftFrontTurnBack, necessarySectionSet, true);
runPath.add(startSection4RoutePath);
endSection4RoutePath = screeningSection4DestinationCode(rightStation, rightFrontTurnBack, necessarySectionSet, false);
endSection4RoutePath = selectSection4DestinationCode(rightStation, rightFrontTurnBack, necessarySectionSet, false);
//查询并添加路径
RoutePath optimalPath = CalculateService.queryLeastSwitchRoutePath(startSection4RoutePath, endSection4RoutePath, necessarySectionSet, true);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(optimalPath,
String.format("从%s到%s的路径未找到", startSection4RoutePath.debugStr(), endSection4RoutePath.debugStr()));
runPath.addAll(optimalPath.getSectionList());
routes.addAll(optimalPath.getRouteList());
//寻找反向的路径
Section t = startSection4RoutePath;
startSection4RoutePath = endSection4RoutePath;
@ -620,7 +619,9 @@ public class InterlockBuilder2 {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(optimalPath2,
String.format("从%s到%s的路径未找到", startSection4RoutePath.debugStr(), endSection4RoutePath.debugStr()));
runPath.addAll(optimalPath2.getSectionList());
routes.addAll(optimalPath2.getRouteList());
//添加进路
routes.addAll(CalculateService.selectUniqueRoutes(optimalPath, true));
routes.addAll(CalculateService.selectUniqueRoutes(optimalPath2, true));
break;
}
case LAST_OPERATION:
@ -630,19 +631,37 @@ public class InterlockBuilder2 {
if (!StringUtils.hasText(description)) {
errMsgList.add(String.format("目的地码[%s]没有描述", code));
}
if (startSection == null || right == null) {
errMsgList.add(String.format("单向目的地码[%s]没有起始区段或方向", code));
continue;
}
if (section == null) {
errMsgList.add(String.format("单向目的地码[%s]没有目标区段", code));
continue;
}
RoutePath routePath = CalculateService.queryLeastSwitchRoutePath(startSection, section, necessarySections, right);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(routePath,
String.format("从%s到%s的路径未找到", startSection.debugStr(), section.debugStr()));
runPath = new ArrayList<>(routePath.getSectionList());
routes = new ArrayList<>(routePath.getRouteList());
if (startSection != null) {
List<Section> sectionPath = new ArrayList<>();
sectionPath.add(startSection);
sectionPath.addAll(necessarySections);
sectionPath.add(section);
runPath = new ArrayList<>();
routes = new ArrayList<>();
for (int i = 0; i < sectionPath.size() - 1; i++) {
Section start = sectionPath.get(i);
Section end = sectionPath.get(i + 1);
RoutePath routePath;
if (right == null) {
routePath = CalculateService.queryLeastSwitchRoutePath(start, end, null, true);
if (routePath == null) {
routePath = CalculateService.queryLeastSwitchRoutePath(start, end, null, false);
}
} else {
routePath = CalculateService.queryLeastSwitchRoutePath(start, end, null, right);
}
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(routePath,
String.format("从%s到%s的路径未找到", startSection.debugStr(), section.debugStr()));
runPath.add(start);
runPath.addAll(routePath.getSectionList());
routes.addAll(routePath.getRouteList());
}
runPath.add(section);
}
}
case OTHER:
if (section == null) {
@ -665,7 +684,7 @@ public class InterlockBuilder2 {
* @param preferredSections 优先区段
* @param right 站前折返时是否优先选择右向站台轨
*/
private static Section screeningSection4DestinationCode(Station station, Boolean ftb, Set<Section> preferredSections, boolean right) {
private static Section selectSection4DestinationCode(Station station, Boolean ftb, Set<Section> preferredSections, boolean right) {
Section section;
if (ftb) {
Optional<Section> selectedSectionOptional = preferredSections.stream()

View File

@ -691,7 +691,7 @@ public class CalculateService {
}
return optimalPath;
}
return routePaths.stream().min(Comparator.comparingDouble(RoutePath::getLength)).orElse(null);
return routePaths.stream().min(Comparator.comparingInt(RoutePath::getSwitchQuantity)).orElse(null);
}
}
@ -1157,6 +1157,46 @@ public class CalculateService {
return atoSpeed;
}
/**
* 筛选唯一进路
* 进路路径的sectionList中可能包含同一信号机下的多个进路本方法将筛选掉多余的进路
*
* @param routePath
* @param tb 是否要在进路路径的终点区段折返
* @return
*/
public static List<Route> selectUniqueRoutes(RoutePath routePath, boolean tb) {
List<Route> routes = new ArrayList<>();
List<Route> routeList = routePath.getRouteList();
List<Section> runPath = new ArrayList<>();
runPath.add(routePath.getStart());
runPath.addAll(routePath.getSectionList());
runPath.add(routePath.getEnd());
for (int i = 0; i < routeList.size(); i++) {
Route route = routeList.get(i);
Route last = i > 0 ? routeList.get(i - 1) : null;
if (last == null) {
routes.add(route);
} else {
if (last.getStart().equals(route.getStart())) {
if (last.getLastRouteSection().equals(routePath.getEnd())) { //进路到达目的地折返轨优先选择折返进路
if (!Objects.equals(tb, last.isTurnBack())) {
routes.set(routes.size() - 1, route);
}
} else { //优先选择非折返且无延续保护或延续保护在路径上的
if (last.isTurnBack() ||
(last.getOverlap() != null && !runPath.containsAll(last.getOverlap().getPathList().get(0).getSectionList()))) {
routes.set(routes.size() - 1, route);
}
}
} else {
routes.add(route);
}
}
}
return routes;
}
/**
* 计算加速段的时间
*/
@ -1195,4 +1235,5 @@ public class CalculateService {
return acceleratedDistance + varyingAcceleratedDistance;
}
}

View File

@ -1046,6 +1046,18 @@ public class Section extends MayOutOfOrderDevice {
section.setCtOccupied(true);
return true;
}
@Override
public void fix(MayOutOfOrderDevice device) {
if (this.equals(device.getFault())) {
Section section = (Section) device;
section.setCtOccupied(false);
section.setFault(null);
if (section.isSwitchTrack()) {
section.getRelSwitch().getAllSections().forEach(section1 -> section1.setCtOccupied(false));
}
}
}
}
}
}

View File

@ -48,6 +48,14 @@ public class MovementAuthority {
end.getEndPosition());
}
@Override
public String toString() {
return "MovementAuthority{" +
"end=" + end +
", protectSpeedCurve=" + protectSpeedCurve +
'}';
}
@Getter
public static class End {
MapNamedElement device;
@ -75,10 +83,12 @@ public class MovementAuthority {
@Override
public String toString() {
return String.format("End{" +
"device=[%s(%s)]" +
", type=[%s]" +
'}', this.device.getName(), this.device.getCode(), this.type);
return "End{" +
"device=" + device +
", type=" + type +
", baseSection=" + baseSection +
", endPosition=" + endPosition +
'}';
}
private SectionPosition computeEndPosition(boolean right) {