From 95a193eef12a217076be6ba280190b3104daf967 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 20 三月 2026 20:42:12 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/common/utils/NavigateUtils.java | 105 +++++++++++++++++++++++++++++++---------------------
1 files changed, 62 insertions(+), 43 deletions(-)
diff --git a/src/main/java/com/zy/common/utils/NavigateUtils.java b/src/main/java/com/zy/common/utils/NavigateUtils.java
index 11ec85c..7f91b77 100644
--- a/src/main/java/com/zy/common/utils/NavigateUtils.java
+++ b/src/main/java/com/zy/common/utils/NavigateUtils.java
@@ -73,10 +73,21 @@
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) {
+ return calcByStationId(startStationId, endStationId, currentTaskNo, false);
+ }
+
+ public synchronized List<NavigateNode> calcReachablePathByStationId(Integer startStationId, Integer endStationId) {
+ return calcByStationId(startStationId, endStationId, null, true);
+ }
+
+ private synchronized List<NavigateNode> calcByStationId(Integer startStationId,
+ Integer endStationId,
+ Integer currentTaskNo,
+ boolean reachabilityOnly) {
BasStation startStation = basStationService.getById(startStationId);
if (startStation == null) {
throw new CoolException("鏈壘鍒拌 璧风偣 瀵瑰簲鐨勭珯鐐规暟鎹�");
@@ -130,7 +141,9 @@
startTime = System.currentTimeMillis();
News.info("[WCS Debug] 绔欑偣璺緞鏉冮噸寮�濮嬪垎鏋�,startStationId={},endStationId={}", startStationId, endStationId);
- List<NavigateNode> list = findStationBestPathTwoStage(allList, resolvedPolicy, currentTaskNo);
+ List<NavigateNode> list = reachabilityOnly
+ ? findStationReachablePath(allList, resolvedPolicy, startStationId, endStationId)
+ : findStationBestPathTwoStage(allList, resolvedPolicy, currentTaskNo, startStationId, endStationId);
News.info("[WCS Debug] 绔欑偣璺緞鏉冮噸鍒嗘瀽瀹屾垚锛岃�楁椂锛歿}ms", System.currentTimeMillis() - startTime);
//鍘婚噸
@@ -288,9 +301,42 @@
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) {
if (allList == null || allList.isEmpty()) {
return new ArrayList<>();
}
@@ -353,12 +399,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<>();
}
@@ -670,6 +714,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) {
@@ -1196,42 +1250,7 @@
StationTrafficSnapshot trafficSnapshot,
LoopMergeGuardContext loopMergeGuardContext,
Set<LoopMergeEntry> mandatoryLoopMergeEntrySet) {
- if (path == null || path.size() < 2 || loopMergeGuardContext == null || loopMergeGuardContext.loopStationIdSet.isEmpty()) {
- return true;
- }
-
- List<Integer> stationIdList = extractStationIdList(path);
- if (stationIdList.size() < 2) {
- return true;
- }
-
- 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;
- }
-
- LoopMergeEntry currentEntry = new LoopMergeEntry(prevStationId, currentStationId);
- for (Integer trunkNeighborStationId : trunkNeighborSet) {
- if (isStationOccupiedForLoopMerge(trunkNeighborStationId, statusMap, trafficSnapshot)) {
- return false;
- }
- }
- boolean mandatoryEntry = mandatoryLoopMergeEntrySet != null && mandatoryLoopMergeEntrySet.contains(currentEntry);
- if (!mandatoryEntry && !isLoopTrunkVeryIdle(currentStationId, loopMergeGuardContext, statusMap, trafficSnapshot)) {
- return false;
- }
- }
+ // 鐜嚎骞跺叆淇濇姢宸插仠鐢細鍏佽鍊欓�夎矾寰勭洿鎺ュ弬涓庡悗缁瘎鍒嗐��
return true;
}
--
Gitblit v1.9.1