From 46bc958dc5bac3fd9861284020af5b8883d8e045 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期六, 21 三月 2026 16:06:01 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/common/utils/NavigateUtils.java | 536 +++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 406 insertions(+), 130 deletions(-)
diff --git a/src/main/java/com/zy/common/utils/NavigateUtils.java b/src/main/java/com/zy/common/utils/NavigateUtils.java
index b3b87dc..6219dbc 100644
--- a/src/main/java/com/zy/common/utils/NavigateUtils.java
+++ b/src/main/java/com/zy/common/utils/NavigateUtils.java
@@ -73,108 +73,47 @@
private StationTaskTraceRegistry stationTaskTraceRegistry;
public synchronized List<NavigateNode> calcByStationId(Integer startStationId, Integer endStationId) {
- return calcByStationId(startStationId, endStationId, null);
+ return calcByStationId(startStationId, endStationId, null, false);
}
public synchronized List<NavigateNode> calcByStationId(Integer startStationId, Integer endStationId, Integer currentTaskNo) {
- BasStation startStation = basStationService.getById(startStationId);
- if (startStation == null) {
- throw new CoolException("鏈壘鍒拌 璧风偣 瀵瑰簲鐨勭珯鐐规暟鎹�");
- }
- Integer lev = startStation.getStationLev();
+ return calcByStationId(startStationId, endStationId, currentTaskNo, false);
+ }
- NavigateSolution navigateSolution = new NavigateSolution();
- List<List<NavigateNode>> stationMap = navigateSolution.getStationMap(lev);
+ public synchronized List<NavigateNode> calcReachablePathByStationId(Integer startStationId, Integer endStationId) {
+ return calcByStationId(startStationId, endStationId, null, true);
+ }
- NavigateNode startNode = navigateSolution.findStationNavigateNode(stationMap, startStationId);
- if (startNode == null) {
- throw new CoolException("鏈壘鍒拌 璧风偣 瀵瑰簲鐨勮妭鐐�");
+ public synchronized List<List<NavigateNode>> calcCandidatePathByStationId(Integer startStationId,
+ Integer endStationId,
+ Integer currentTaskNo) {
+ StationPathSearchContext context = buildStationPathSearchContext(startStationId, endStationId);
+ if (context.allList.isEmpty()) {
+ return new ArrayList<>();
}
- NavigateNode endNode = navigateSolution.findStationNavigateNode(stationMap, endStationId);
- if (endNode == null) {
- throw new CoolException("鏈壘鍒拌 缁堢偣 瀵瑰簲鐨勮妭鐐�");
- }
-
- StationPathResolvedPolicy resolvedPolicy = resolveStationPathPolicy(startStationId, endStationId);
- StationPathProfileConfig profileConfig = resolvedPolicy.getProfileConfig() == null
- ? StationPathProfileConfig.defaultConfig()
- : resolvedPolicy.getProfileConfig();
-
- long startTime = System.currentTimeMillis();
- News.info("[WCS Debug] 绔欑偣璺緞寮�濮嬭绠�,startStationId={},endStationId={}", startStationId, endStationId);
- int calcMaxDepth = safeInt(profileConfig.getCalcMaxDepth(), 120);
- int calcMaxPaths = safeInt(profileConfig.getCalcMaxPaths(), 500);
- int calcMaxCost = safeInt(profileConfig.getCalcMaxCost(), 300);
- List<Integer> guideStationSequence = buildGuideStationSequence(startStationId, endStationId, resolvedPolicy.getRuleConfig());
- List<List<NavigateNode>> allList = navigateSolution.allSimplePaths(
- stationMap,
- startNode,
- endNode,
- calcMaxDepth,
- calcMaxPaths,
- calcMaxCost,
- guideStationSequence
+ List<List<NavigateNode>> orderedPathList = orderStationPathCandidates(
+ context.allList,
+ context.resolvedPolicy,
+ currentTaskNo,
+ startStationId,
+ endStationId
);
- if (allList.isEmpty()) {
-// throw new CoolException("鏈壘鍒拌璺緞");
+ return normalizeCandidatePaths(orderedPathList);
+ }
+
+ private synchronized List<NavigateNode> calcByStationId(Integer startStationId,
+ Integer endStationId,
+ Integer currentTaskNo,
+ boolean reachabilityOnly) {
+ StationPathSearchContext context = buildStationPathSearchContext(startStationId, endStationId);
+ if (context.allList.isEmpty()) {
return new ArrayList<>();
}
- Map<Integer, StationProtocol> statusMap = loadStationStatusMap();
- allList = filterNonAutoStationPaths(allList, statusMap);
- if (allList.isEmpty()) {
- News.info("[WCS Debug] 绔欑偣璺緞鍊欓�夊叏閮ㄨ杩囨护锛屽瓨鍦ㄩ潪鑷姩绔欑偣,startStationId={},endStationId={}", startStationId, endStationId);
- return new ArrayList<>();
- }
- News.info("[WCS Debug] 绔欑偣璺緞璁$畻瀹屾垚锛岃�楁椂锛歿}ms", System.currentTimeMillis() - startTime);
-
- startTime = System.currentTimeMillis();
- News.info("[WCS Debug] 绔欑偣璺緞鏉冮噸寮�濮嬪垎鏋�,startStationId={},endStationId={}", startStationId, endStationId);
- List<NavigateNode> list = findStationBestPathTwoStage(allList, resolvedPolicy, currentTaskNo);
- News.info("[WCS Debug] 绔欑偣璺緞鏉冮噸鍒嗘瀽瀹屾垚锛岃�楁椂锛歿}ms", System.currentTimeMillis() - startTime);
-
- //鍘婚噸
- HashSet<Integer> set = new HashSet<>();
- List<NavigateNode> fitlerList = new ArrayList<>();
- for (NavigateNode navigateNode : list) {
- JSONObject valuObject = JSON.parseObject(navigateNode.getNodeValue());
- if (valuObject.containsKey("rgvCalcFlag")) {
- continue;
- }
- if (set.add(valuObject.getInteger("stationId"))) {
- fitlerList.add(navigateNode);
- }
- }
-
- for (int i = 0; i < fitlerList.size(); i++) {
- NavigateNode currentNode = fitlerList.get(i);
- currentNode.setIsInflectionPoint(false);
- currentNode.setIsLiftTransferPoint(false);
-
- try {
- JSONObject valueObject = JSON.parseObject(currentNode.getNodeValue());
- if (valueObject != null) {
- Object isLiftTransfer = valueObject.get("isLiftTransfer");
- if (isLiftTransfer != null) {
- String isLiftTransferStr = isLiftTransfer.toString();
- if ("1".equals(isLiftTransferStr) || "true".equalsIgnoreCase(isLiftTransferStr)) {
- currentNode.setIsLiftTransferPoint(true);
- }
- }
- }
- } catch (Exception ignore) {}
-
- NavigateNode nextNode = (i + 1 < fitlerList.size()) ? fitlerList.get(i + 1) : null;
- NavigateNode prevNode = (i - 1 >= 0) ? fitlerList.get(i - 1) : null;
-
- HashMap<String, Object> result = searchInflectionPoint(currentNode, nextNode, prevNode);
- if (Boolean.parseBoolean(result.get("result").toString())) {
- currentNode.setIsInflectionPoint(true);
- currentNode.setDirection(result.get("direction").toString());
- }
- }
-
- return fitlerList;
+ List<NavigateNode> list = reachabilityOnly
+ ? findStationReachablePath(context.allList, context.resolvedPolicy, startStationId, endStationId)
+ : findStationBestPathTwoStage(context.allList, context.resolvedPolicy, currentTaskNo, startStationId, endStationId);
+ return normalizeStationPath(list);
}
public synchronized List<NavigateNode> calcByTrackSiteNo(int lev, Integer startTrackSiteNo, Integer endTrackSiteNo) {
@@ -288,9 +227,54 @@
return new StationPathResolvedPolicy();
}
+ private List<NavigateNode> findStationReachablePath(List<List<NavigateNode>> allList,
+ StationPathResolvedPolicy resolvedPolicy,
+ Integer startStationId,
+ Integer endStationId) {
+ if (allList == null || allList.isEmpty()) {
+ return new ArrayList<>();
+ }
+
+ StationPathRuleConfig ruleConfig = resolvedPolicy.getRuleConfig() == null
+ ? new StationPathRuleConfig()
+ : resolvedPolicy.getRuleConfig();
+
+ List<List<NavigateNode>> filteredCandidates = applyRuleFilters(allList, ruleConfig, true);
+ if (filteredCandidates.isEmpty() && hasWaypoint(ruleConfig) && !strictWaypoint(ruleConfig)) {
+ filteredCandidates = applyRuleFilters(allList, ruleConfig, false);
+ News.info("[WCS Debug] 绔欑偣璺緞鍙揪鎬ц鍒欏凡闄嶇骇锛屽拷鐣ュ叧閿�旂粡鐐圭害鏉熷悗閲嶈瘯");
+ }
+ if (filteredCandidates.isEmpty()) {
+ if (resolvedPolicy.matchedRule()) {
+ News.warn("绔欑偣璺緞瑙勫垯鍛戒腑浣嗘棤鍙揪璺緞锛宺uleCode={},startStationId={},endStationId={}",
+ resolvedPolicy.getRuleEntity() == null ? "" : resolvedPolicy.getRuleEntity().getRuleCode(),
+ startStationId, endStationId);
+ return new ArrayList<>();
+ }
+ filteredCandidates = allList;
+ }
+
+ filteredCandidates.sort((left, right) -> compareReachabilityPath(left, right));
+ return filteredCandidates.isEmpty() ? new ArrayList<>() : filteredCandidates.get(0);
+ }
+
private List<NavigateNode> findStationBestPathTwoStage(List<List<NavigateNode>> allList,
StationPathResolvedPolicy resolvedPolicy,
- Integer currentTaskNo) {
+ Integer currentTaskNo,
+ Integer startStationId,
+ Integer endStationId) {
+ List<List<NavigateNode>> orderedPathList = orderStationPathCandidates(allList, resolvedPolicy, currentTaskNo, startStationId, endStationId);
+ if (orderedPathList.isEmpty()) {
+ return new ArrayList<>();
+ }
+ return orderedPathList.get(0);
+ }
+
+ private List<List<NavigateNode>> orderStationPathCandidates(List<List<NavigateNode>> allList,
+ StationPathResolvedPolicy resolvedPolicy,
+ Integer currentTaskNo,
+ Integer startStationId,
+ Integer endStationId) {
if (allList == null || allList.isEmpty()) {
return new ArrayList<>();
}
@@ -330,6 +314,7 @@
Map<Integer, Double> stationLoopLoadMap = loadStationLoopLoadMap();
StationTrafficSnapshot trafficSnapshot = loadStationTrafficSnapshot(statusMap, currentTaskNo);
LoopMergeGuardContext loopMergeGuardContext = loadLoopMergeGuardContext();
+ Set<LoopMergeEntry> mandatoryLoopMergeEntrySet = resolveMandatoryLoopMergeEntrySet(filteredCandidates, loopMergeGuardContext);
Set<Integer> outStationIdSet = loadAllOutStationIdSet();
List<PathCandidateMetrics> metricsList = new ArrayList<>();
int skippedByOtherOutStation = 0;
@@ -338,7 +323,7 @@
if (path == null || path.isEmpty()) {
continue;
}
- if (!isLoopMergePathAllowed(path, statusMap, trafficSnapshot, loopMergeGuardContext)) {
+ if (!isLoopMergePathAllowed(path, statusMap, trafficSnapshot, loopMergeGuardContext, mandatoryLoopMergeEntrySet)) {
skippedByLoopMergeGuard++;
continue;
}
@@ -352,12 +337,10 @@
if (metricsList.isEmpty()) {
if (globalPolicy.forceSkipPassOtherOutStation && skippedByOtherOutStation > 0) {
News.warn("[WCS Debug] 绔欑偣璺緞鍊欓�夊叏閮ㄨ杩囨护锛屽洜缁忚繃鍏朵粬鍑哄簱绔欑偣,startStationId={},endStationId={}",
- resolvedPolicy.getRuleEntity() == null ? null : resolvedPolicy.getRuleEntity().getStartStationId(),
- resolvedPolicy.getRuleEntity() == null ? null : resolvedPolicy.getRuleEntity().getEndStationId());
+ startStationId, endStationId);
} else if (skippedByLoopMergeGuard > 0) {
News.warn("[WCS Debug] 绔欑偣璺緞鍊欓�夊叏閮ㄨ杩囨护锛屽洜鍒嗗弶鍙f彃鍏ョ幆绾夸富骞蹭細褰卞搷涓诲共閬�,startStationId={},endStationId={}",
- resolvedPolicy.getRuleEntity() == null ? null : resolvedPolicy.getRuleEntity().getStartStationId(),
- resolvedPolicy.getRuleEntity() == null ? null : resolvedPolicy.getRuleEntity().getEndStationId());
+ startStationId, endStationId);
}
return new ArrayList<>();
}
@@ -378,12 +361,41 @@
}
int topK = safeInt(profileConfig.getS1TopK(), 5);
- if (topK > 0 && stage1Selected.size() > topK) {
- stage1Selected = new ArrayList<>(stage1Selected.subList(0, topK));
+ List<PathCandidateMetrics> primaryMetrics = new ArrayList<>(stage1Selected);
+ List<PathCandidateMetrics> secondaryMetrics = new ArrayList<>();
+ if (topK > 0 && primaryMetrics.size() > topK) {
+ secondaryMetrics.addAll(primaryMetrics.subList(topK, primaryMetrics.size()));
+ primaryMetrics = new ArrayList<>(primaryMetrics.subList(0, topK));
}
- stage1Selected.sort((a, b) -> compareDouble(a.dynamicCost, b.dynamicCost, a.pathLen, b.pathLen, a.turnCount, b.turnCount));
- return stage1Selected.get(0).path;
+ primaryMetrics.sort((a, b) -> compareDouble(a.dynamicCost, b.dynamicCost, a.pathLen, b.pathLen, a.turnCount, b.turnCount));
+ secondaryMetrics.sort((a, b) -> compareDouble(a.dynamicCost, b.dynamicCost, a.pathLen, b.pathLen, a.turnCount, b.turnCount));
+
+ List<PathCandidateMetrics> remainingMetrics = new ArrayList<>();
+ for (PathCandidateMetrics metrics : metricsList) {
+ if (!stage1Selected.contains(metrics)) {
+ remainingMetrics.add(metrics);
+ }
+ }
+ remainingMetrics.sort((a, b) -> compareDouble(a.dynamicCost, b.dynamicCost, a.pathLen, b.pathLen, a.turnCount, b.turnCount));
+
+ List<List<NavigateNode>> orderedPathList = new ArrayList<>();
+ appendCandidatePathList(orderedPathList, primaryMetrics);
+ appendCandidatePathList(orderedPathList, secondaryMetrics);
+ appendCandidatePathList(orderedPathList, remainingMetrics);
+ return orderedPathList;
+ }
+
+ private void appendCandidatePathList(List<List<NavigateNode>> orderedPathList,
+ List<PathCandidateMetrics> metricsList) {
+ if (orderedPathList == null || metricsList == null) {
+ return;
+ }
+ for (PathCandidateMetrics metrics : metricsList) {
+ if (metrics != null && metrics.path != null && !metrics.path.isEmpty()) {
+ orderedPathList.add(metrics.path);
+ }
+ }
}
private List<List<NavigateNode>> applyRuleFilters(List<List<NavigateNode>> allList,
@@ -669,6 +681,16 @@
}
}
return count;
+ }
+
+ private int compareReachabilityPath(List<NavigateNode> left, List<NavigateNode> right) {
+ int leftLen = left == null ? Integer.MAX_VALUE : left.size();
+ int rightLen = right == null ? Integer.MAX_VALUE : right.size();
+ int leftTurnCount = countTurnCount(left);
+ int rightTurnCount = countTurnCount(right);
+ int leftLiftCount = countLiftTransferCount(left);
+ int rightLiftCount = countLiftTransferCount(right);
+ return compareDouble(leftLen, rightLen, leftTurnCount, rightTurnCount, leftLiftCount, rightLiftCount);
}
private int countLiftTransferCount(List<NavigateNode> path) {
@@ -989,6 +1011,51 @@
return context;
}
+ private Set<LoopMergeEntry> resolveMandatoryLoopMergeEntrySet(List<List<NavigateNode>> candidatePathList,
+ LoopMergeGuardContext loopMergeGuardContext) {
+ if (candidatePathList == null || candidatePathList.isEmpty()
+ || loopMergeGuardContext == null || loopMergeGuardContext.loopStationIdSet.isEmpty()) {
+ return Collections.emptySet();
+ }
+
+ Set<LoopMergeEntry> intersectionSet = null;
+ for (List<NavigateNode> path : candidatePathList) {
+ Set<LoopMergeEntry> entrySet = extractLoopMergeEntrySet(path, loopMergeGuardContext);
+ if (intersectionSet == null) {
+ intersectionSet = new HashSet<>(entrySet);
+ } else {
+ intersectionSet.retainAll(entrySet);
+ }
+ if (intersectionSet.isEmpty()) {
+ return Collections.emptySet();
+ }
+ }
+ return intersectionSet == null ? Collections.emptySet() : intersectionSet;
+ }
+
+ private Set<LoopMergeEntry> extractLoopMergeEntrySet(List<NavigateNode> path,
+ LoopMergeGuardContext loopMergeGuardContext) {
+ Set<LoopMergeEntry> result = new HashSet<>();
+ if (path == null || path.size() < 2 || loopMergeGuardContext == null || loopMergeGuardContext.loopStationIdSet.isEmpty()) {
+ return result;
+ }
+
+ List<Integer> stationIdList = extractStationIdList(path);
+ for (int i = 1; i < stationIdList.size(); i++) {
+ Integer prevStationId = stationIdList.get(i - 1);
+ Integer currentStationId = stationIdList.get(i);
+ if (prevStationId == null || currentStationId == null) {
+ continue;
+ }
+ if (loopMergeGuardContext.loopStationIdSet.contains(prevStationId)
+ || !loopMergeGuardContext.loopStationIdSet.contains(currentStationId)) {
+ continue;
+ }
+ result.add(new LoopMergeEntry(prevStationId, currentStationId));
+ }
+ return result;
+ }
+
private Map<Integer, Set<Integer>> loadUndirectedStationGraph() {
Map<Integer, Set<Integer>> graph = new HashMap<>();
List<Integer> levList = loadStationLevList();
@@ -1148,39 +1215,57 @@
private boolean isLoopMergePathAllowed(List<NavigateNode> path,
Map<Integer, StationProtocol> statusMap,
StationTrafficSnapshot trafficSnapshot,
- LoopMergeGuardContext loopMergeGuardContext) {
- if (path == null || path.size() < 2 || loopMergeGuardContext == null || loopMergeGuardContext.loopStationIdSet.isEmpty()) {
- return true;
+ LoopMergeGuardContext loopMergeGuardContext,
+ Set<LoopMergeEntry> mandatoryLoopMergeEntrySet) {
+ // 鐜嚎骞跺叆淇濇姢宸插仠鐢細鍏佽鍊欓�夎矾寰勭洿鎺ュ弬涓庡悗缁瘎鍒嗐��
+ return true;
+ }
+
+ private boolean isLoopTrunkVeryIdle(Integer mergeStationId,
+ LoopMergeGuardContext loopMergeGuardContext,
+ Map<Integer, StationProtocol> statusMap,
+ StationTrafficSnapshot trafficSnapshot) {
+ if (mergeStationId == null || loopMergeGuardContext == null) {
+ return false;
}
-
- List<Integer> stationIdList = extractStationIdList(path);
- if (stationIdList.size() < 2) {
- return true;
+ Set<Integer> guardStationIdSet = collectLoopNeighborWindow(mergeStationId, loopMergeGuardContext, 2);
+ if (guardStationIdSet.isEmpty()) {
+ return false;
}
-
- for (int i = 1; i < stationIdList.size(); i++) {
- Integer prevStationId = stationIdList.get(i - 1);
- Integer currentStationId = stationIdList.get(i);
- if (prevStationId == null || currentStationId == null) {
- continue;
- }
- if (loopMergeGuardContext.loopStationIdSet.contains(prevStationId)
- || !loopMergeGuardContext.loopStationIdSet.contains(currentStationId)) {
- continue;
- }
-
- Set<Integer> trunkNeighborSet = loopMergeGuardContext.loopNeighborMap.getOrDefault(currentStationId, Collections.emptySet());
- if (trunkNeighborSet.size() < 2) {
- continue;
- }
-
- for (Integer trunkNeighborStationId : trunkNeighborSet) {
- if (isStationOccupiedForLoopMerge(trunkNeighborStationId, statusMap, trafficSnapshot)) {
- return false;
- }
+ for (Integer stationId : guardStationIdSet) {
+ if (isStationOccupiedForLoopMerge(stationId, statusMap, trafficSnapshot)) {
+ return false;
}
}
return true;
+ }
+
+ private Set<Integer> collectLoopNeighborWindow(Integer centerStationId,
+ LoopMergeGuardContext loopMergeGuardContext,
+ int depth) {
+ Set<Integer> visited = new LinkedHashSet<>();
+ if (centerStationId == null || depth < 0 || loopMergeGuardContext == null) {
+ return visited;
+ }
+
+ Set<Integer> frontier = new LinkedHashSet<>();
+ frontier.add(centerStationId);
+ visited.add(centerStationId);
+ for (int step = 0; step < depth; step++) {
+ Set<Integer> nextFrontier = new LinkedHashSet<>();
+ for (Integer stationId : frontier) {
+ for (Integer neighborStationId : loopMergeGuardContext.loopNeighborMap.getOrDefault(stationId, Collections.emptySet())) {
+ if (neighborStationId != null && visited.add(neighborStationId)) {
+ nextFrontier.add(neighborStationId);
+ }
+ }
+ }
+ if (nextFrontier.isEmpty()) {
+ break;
+ }
+ frontier = nextFrontier;
+ }
+ return visited;
}
private boolean isStationOccupiedForLoopMerge(Integer stationId,
@@ -1659,8 +1744,169 @@
return text != null && !text.trim().isEmpty();
}
+ private StationPathSearchContext buildStationPathSearchContext(Integer startStationId, Integer endStationId) {
+ BasStation startStation = basStationService.getById(startStationId);
+ if (startStation == null) {
+ throw new CoolException("鏈壘鍒拌 璧风偣 瀵瑰簲鐨勭珯鐐规暟鎹�");
+ }
+ Integer lev = startStation.getStationLev();
+
+ NavigateSolution navigateSolution = new NavigateSolution();
+ List<List<NavigateNode>> stationMap = navigateSolution.getStationMap(lev);
+
+ NavigateNode startNode = navigateSolution.findStationNavigateNode(stationMap, startStationId);
+ if (startNode == null) {
+ throw new CoolException("鏈壘鍒拌 璧风偣 瀵瑰簲鐨勮妭鐐�");
+ }
+
+ NavigateNode endNode = navigateSolution.findStationNavigateNode(stationMap, endStationId);
+ if (endNode == null) {
+ throw new CoolException("鏈壘鍒拌 缁堢偣 瀵瑰簲鐨勮妭鐐�");
+ }
+
+ StationPathResolvedPolicy resolvedPolicy = resolveStationPathPolicy(startStationId, endStationId);
+ StationPathProfileConfig profileConfig = resolvedPolicy.getProfileConfig() == null
+ ? StationPathProfileConfig.defaultConfig()
+ : resolvedPolicy.getProfileConfig();
+
+ long startTime = System.currentTimeMillis();
+ News.info("[WCS Debug] 绔欑偣璺緞寮�濮嬭绠�,startStationId={},endStationId={}", startStationId, endStationId);
+ int calcMaxDepth = safeInt(profileConfig.getCalcMaxDepth(), 120);
+ int calcMaxPaths = safeInt(profileConfig.getCalcMaxPaths(), 500);
+ int calcMaxCost = safeInt(profileConfig.getCalcMaxCost(), 300);
+ List<Integer> guideStationSequence = buildGuideStationSequence(startStationId, endStationId, resolvedPolicy.getRuleConfig());
+ List<List<NavigateNode>> allList = navigateSolution.allSimplePaths(
+ stationMap,
+ startNode,
+ endNode,
+ calcMaxDepth,
+ calcMaxPaths,
+ calcMaxCost,
+ guideStationSequence
+ );
+ if (allList.isEmpty()) {
+ return StationPathSearchContext.empty(resolvedPolicy);
+ }
+ Map<Integer, StationProtocol> statusMap = loadStationStatusMap();
+ allList = filterNonAutoStationPaths(allList, statusMap);
+ if (allList.isEmpty()) {
+ News.info("[WCS Debug] 绔欑偣璺緞鍊欓�夊叏閮ㄨ杩囨护锛屽瓨鍦ㄩ潪鑷姩绔欑偣,startStationId={},endStationId={}", startStationId, endStationId);
+ return StationPathSearchContext.empty(resolvedPolicy);
+ }
+ News.info("[WCS Debug] 绔欑偣璺緞璁$畻瀹屾垚锛岃�楁椂锛歿}ms", System.currentTimeMillis() - startTime);
+ return new StationPathSearchContext(allList, resolvedPolicy);
+ }
+
+ private List<List<NavigateNode>> normalizeCandidatePaths(List<List<NavigateNode>> orderedPathList) {
+ List<List<NavigateNode>> result = new ArrayList<>();
+ if (orderedPathList == null || orderedPathList.isEmpty()) {
+ return result;
+ }
+ Set<String> seenPathSignatures = new LinkedHashSet<>();
+ for (List<NavigateNode> path : orderedPathList) {
+ List<NavigateNode> normalizedPath = normalizeStationPath(path);
+ String pathSignature = buildPathSignature(normalizedPath);
+ if (pathSignature.isEmpty() || !seenPathSignatures.add(pathSignature)) {
+ continue;
+ }
+ result.add(normalizedPath);
+ }
+ return result;
+ }
+
+ private List<NavigateNode> normalizeStationPath(List<NavigateNode> path) {
+ HashSet<Integer> stationIdSet = new HashSet<>();
+ List<NavigateNode> filterList = new ArrayList<>();
+ for (NavigateNode navigateNode : safeList(path)) {
+ if (navigateNode == null) {
+ continue;
+ }
+ JSONObject valueObject;
+ try {
+ valueObject = JSON.parseObject(navigateNode.getNodeValue());
+ } catch (Exception ignore) {
+ continue;
+ }
+ if (valueObject == null || valueObject.containsKey("rgvCalcFlag")) {
+ continue;
+ }
+ Integer stationId = valueObject.getInteger("stationId");
+ if (stationId == null || !stationIdSet.add(stationId)) {
+ continue;
+ }
+ NavigateNode clonedNode = navigateNode.clone();
+ if (clonedNode == null) {
+ continue;
+ }
+ filterList.add(clonedNode);
+ }
+
+ for (int i = 0; i < filterList.size(); i++) {
+ NavigateNode currentNode = filterList.get(i);
+ currentNode.setIsInflectionPoint(false);
+ currentNode.setIsLiftTransferPoint(false);
+
+ try {
+ JSONObject valueObject = JSON.parseObject(currentNode.getNodeValue());
+ if (valueObject != null) {
+ Object isLiftTransfer = valueObject.get("isLiftTransfer");
+ if (isLiftTransfer != null) {
+ String isLiftTransferStr = isLiftTransfer.toString();
+ if ("1".equals(isLiftTransferStr) || "true".equalsIgnoreCase(isLiftTransferStr)) {
+ currentNode.setIsLiftTransferPoint(true);
+ }
+ }
+ }
+ } catch (Exception ignore) {
+ }
+
+ NavigateNode nextNode = (i + 1 < filterList.size()) ? filterList.get(i + 1) : null;
+ NavigateNode prevNode = (i - 1 >= 0) ? filterList.get(i - 1) : null;
+
+ HashMap<String, Object> searchResult = searchInflectionPoint(currentNode, nextNode, prevNode);
+ if (Boolean.parseBoolean(searchResult.get("result").toString())) {
+ currentNode.setIsInflectionPoint(true);
+ currentNode.setDirection(searchResult.get("direction").toString());
+ }
+ }
+ return filterList;
+ }
+
+ private String buildPathSignature(List<NavigateNode> path) {
+ List<Integer> stationIdList = extractStationIdList(path);
+ if (stationIdList.isEmpty()) {
+ return "";
+ }
+ StringBuilder builder = new StringBuilder();
+ for (Integer stationId : stationIdList) {
+ if (stationId == null) {
+ continue;
+ }
+ if (builder.length() > 0) {
+ builder.append("->");
+ }
+ builder.append(stationId);
+ }
+ return builder.toString();
+ }
+
private <T> List<T> safeList(List<T> list) {
return list == null ? Collections.emptyList() : list;
+ }
+
+ private static class StationPathSearchContext {
+ private final List<List<NavigateNode>> allList;
+ private final StationPathResolvedPolicy resolvedPolicy;
+
+ private StationPathSearchContext(List<List<NavigateNode>> allList,
+ StationPathResolvedPolicy resolvedPolicy) {
+ this.allList = allList == null ? new ArrayList<>() : allList;
+ this.resolvedPolicy = resolvedPolicy == null ? new StationPathResolvedPolicy() : resolvedPolicy;
+ }
+
+ private static StationPathSearchContext empty(StationPathResolvedPolicy resolvedPolicy) {
+ return new StationPathSearchContext(new ArrayList<>(), resolvedPolicy);
+ }
}
private static class PathCandidateMetrics {
@@ -1715,6 +1961,36 @@
private final Map<Integer, Set<Integer>> loopNeighborMap = new HashMap<>();
}
+ private static class LoopMergeEntry {
+ private final Integer fromStationId;
+ private final Integer toStationId;
+
+ private LoopMergeEntry(Integer fromStationId, Integer toStationId) {
+ this.fromStationId = fromStationId;
+ this.toStationId = toStationId;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof LoopMergeEntry)) {
+ return false;
+ }
+ LoopMergeEntry other = (LoopMergeEntry) obj;
+ return (fromStationId == null ? other.fromStationId == null : fromStationId.equals(other.fromStationId))
+ && (toStationId == null ? other.toStationId == null : toStationId.equals(other.toStationId));
+ }
+
+ @Override
+ public int hashCode() {
+ int result = fromStationId == null ? 0 : fromStationId.hashCode();
+ result = 31 * result + (toStationId == null ? 0 : toStationId.hashCode());
+ return result;
+ }
+ }
+
private static class PathGlobalPolicy {
private double lenWeightFactor = 1.0d;
private double congWeightFactor = 1.0d;
--
Gitblit v1.9.1