From ed266efb662c5b8460ecc22e31a070a718f35f9c Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 31 三月 2026 16:08:59 +0800
Subject: [PATCH] #地图编辑路径联通性导致算法计算失败问题修复
---
src/main/java/com/zy/common/utils/NavigateSolution.java | 64 +++++++++++++++++++++++++++----
1 files changed, 55 insertions(+), 9 deletions(-)
diff --git a/src/main/java/com/zy/common/utils/NavigateSolution.java b/src/main/java/com/zy/common/utils/NavigateSolution.java
index 6dd6c57..adf527f 100644
--- a/src/main/java/com/zy/common/utils/NavigateSolution.java
+++ b/src/main/java/com/zy/common/utils/NavigateSolution.java
@@ -399,12 +399,16 @@
}
private Integer extractStationId(NavigateNode node) {
- if (node == null || !"devp".equals(node.getNodeType())) {
+ JSONObject valueObj = parseNodeValue(node == null ? null : node.getNodeValue());
+ return valueObj == null ? null : valueObj.getInteger("stationId");
+ }
+
+ private JSONObject parseNodeValue(String nodeValue) {
+ if (nodeValue == null || nodeValue.trim().isEmpty()) {
return null;
}
try {
- JSONObject valueObj = JSON.parseObject(node.getNodeValue());
- return valueObj == null ? null : valueObj.getInteger("stationId");
+ return JSON.parseObject(nodeValue);
} catch (Exception ignore) {
return null;
}
@@ -503,18 +507,60 @@
}
public NavigateNode findStationNavigateNode(List<List<NavigateNode>> map, int stationId) {
+ NavigateNode bestNode = null;
+ int bestExternalConnectionCount = -1;
+ int bestNeighborCount = -1;
for(int x = 0; x < map.size(); x++) {
for(int y = 0; y < map.get(0).size(); y++) {
NavigateNode node = map.get(x).get(y);
- if("devp".equals(node.getNodeType())) {
- JSONObject valueObj = JSON.parseObject(node.getNodeValue());
- if(valueObj.getInteger("stationId") == stationId) {
- return node;
- }
+ Integer currentStationId = extractStationId(node);
+ if (currentStationId == null || currentStationId != stationId) {
+ continue;
+ }
+ ArrayList<NavigateNode> neighbors = extend_current_node(map, node);
+ int externalConnectionCount = countExternalConnectionCount(stationId, neighbors);
+ int neighborCount = neighbors == null ? 0 : neighbors.size();
+ if (externalConnectionCount > bestExternalConnectionCount
+ || (externalConnectionCount == bestExternalConnectionCount && neighborCount > bestNeighborCount)) {
+ bestNode = node;
+ bestExternalConnectionCount = externalConnectionCount;
+ bestNeighborCount = neighborCount;
}
}
}
- return null;
+ return bestNode;
+ }
+
+ private int countExternalConnectionCount(Integer currentStationId, List<NavigateNode> neighbors) {
+ Set<Integer> connectedStationIdSet = new LinkedHashSet<>();
+ if (neighbors == null || neighbors.isEmpty()) {
+ return 0;
+ }
+ for (NavigateNode neighbor : neighbors) {
+ connectedStationIdSet.addAll(resolveAdjacentStationIds(currentStationId, neighbor));
+ }
+ return connectedStationIdSet.size();
+ }
+
+ private Set<Integer> resolveAdjacentStationIds(Integer currentStationId, NavigateNode node) {
+ Set<Integer> stationIdSet = new LinkedHashSet<>();
+ JSONObject valueObj = parseNodeValue(node == null ? null : node.getNodeValue());
+ if (valueObj == null) {
+ return stationIdSet;
+ }
+ Integer directStationId = valueObj.getInteger("stationId");
+ if (directStationId != null && !directStationId.equals(currentStationId)) {
+ stationIdSet.add(directStationId);
+ }
+ if (valueObj.getJSONArray("bridgeStationIds") == null) {
+ return stationIdSet;
+ }
+ for (Integer bridgeStationId : valueObj.getJSONArray("bridgeStationIds").toJavaList(Integer.class)) {
+ if (bridgeStationId != null && !bridgeStationId.equals(currentStationId)) {
+ stationIdSet.add(bridgeStationId);
+ }
+ }
+ return stationIdSet;
}
public NavigateNode findTrackSiteNoNavigateNode(List<List<NavigateNode>> map, int trackSiteNo) {
--
Gitblit v1.9.1