From 45052042f06689096093fc86cae36560b2eeb1f0 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 02 四月 2026 15:38:48 +0800
Subject: [PATCH] #优化运行速度
---
src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java | 6 +-
src/main/java/com/zy/core/utils/station/StationOutboundDecisionSupport.java | 87 ++++++++++++++++++++++------
src/main/java/com/zy/common/utils/NavigateUtils.java | 34 +++++-----
3 files changed, 87 insertions(+), 40 deletions(-)
diff --git a/src/main/java/com/zy/common/utils/NavigateUtils.java b/src/main/java/com/zy/common/utils/NavigateUtils.java
index 74c70f6..eeb8ad0 100644
--- a/src/main/java/com/zy/common/utils/NavigateUtils.java
+++ b/src/main/java/com/zy/common/utils/NavigateUtils.java
@@ -75,21 +75,21 @@
@Autowired
private StationTaskTraceRegistry stationTaskTraceRegistry;
- public synchronized List<NavigateNode> calcOptimalPathByStationId(Integer startStationId,
- Integer endStationId,
- Integer currentTaskNo,
- Double pathLenFactor) {
+ public List<NavigateNode> calcOptimalPathByStationId(Integer startStationId,
+ Integer endStationId,
+ Integer currentTaskNo,
+ Double pathLenFactor) {
return calcPathByStationId(startStationId, endStationId, currentTaskNo, pathLenFactor, StationPathCalcMode.OPTIMAL);
}
- public synchronized List<NavigateNode> calcReachablePathByStationId(Integer startStationId, Integer endStationId) {
+ public List<NavigateNode> calcReachablePathByStationId(Integer startStationId, Integer endStationId) {
return calcPathByStationId(startStationId, endStationId, null, null, StationPathCalcMode.REACHABILITY);
}
- public synchronized List<List<NavigateNode>> calcCandidatePathByStationId(Integer startStationId,
- Integer endStationId,
- Integer currentTaskNo,
- Double pathLenFactor) {
+ public List<List<NavigateNode>> calcCandidatePathByStationId(Integer startStationId,
+ Integer endStationId,
+ Integer currentTaskNo,
+ Double pathLenFactor) {
StationPathResolvedPolicy resolvedPolicy = resolveStationPathPolicy(startStationId, endStationId);
StationPathSearchContext context = buildStationPathSearchContext(
startStationId,
@@ -112,7 +112,7 @@
return normalizeCandidatePaths(orderedPathList);
}
- public synchronized Map<Integer, Set<Integer>> loadUndirectedStationGraphSnapshot() {
+ public Map<Integer, Set<Integer>> loadUndirectedStationGraphSnapshot() {
Map<Integer, Set<Integer>> graph = loadUndirectedStationGraph();
Map<Integer, Set<Integer>> snapshot = new HashMap<>();
for (Map.Entry<Integer, Set<Integer>> entry : graph.entrySet()) {
@@ -125,11 +125,11 @@
return snapshot;
}
- private synchronized List<NavigateNode> calcPathByStationId(Integer startStationId,
- Integer endStationId,
- Integer currentTaskNo,
- Double pathLenFactor,
- StationPathCalcMode calcMode) {
+ private List<NavigateNode> calcPathByStationId(Integer startStationId,
+ Integer endStationId,
+ Integer currentTaskNo,
+ Double pathLenFactor,
+ StationPathCalcMode calcMode) {
StationPathResolvedPolicy resolvedPolicy = resolveStationPathPolicy(startStationId, endStationId);
if (calcMode != StationPathCalcMode.REROUTE) {
List<NavigateNode> directPath = findStationDirectPath(
@@ -160,7 +160,7 @@
return normalizeStationPath(list);
}
- public synchronized List<NavigateNode> calcByTrackSiteNo(int lev, Integer startTrackSiteNo, Integer endTrackSiteNo) {
+ public List<NavigateNode> calcByTrackSiteNo(int lev, Integer startTrackSiteNo, Integer endTrackSiteNo) {
NavigateSolution navigateSolution = new NavigateSolution();
List<List<NavigateNode>> rgvTrackMap = navigateSolution.getRgvTrackMap(lev);
@@ -230,7 +230,7 @@
return fitlerList;
}
- public synchronized List<NavigateNode> findLiftStationList(int lev) {
+ public List<NavigateNode> findLiftStationList(int lev) {
NavigateSolution navigateSolution = new NavigateSolution();
List<List<NavigateNode>> stationMap = navigateSolution.getStationMap(lev);
diff --git a/src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java b/src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java
index 5166a7b..0f8f76c 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java
@@ -177,7 +177,7 @@
}
@Override
- public synchronized StationCommand getRunBlockRerouteCommand(Integer taskNo,
+ public StationCommand getRunBlockRerouteCommand(Integer taskNo,
Integer stationId,
Integer targetStationId,
Integer palletSize) {
@@ -185,7 +185,7 @@
}
@Override
- public synchronized StationCommand getRunBlockRerouteCommand(Integer taskNo,
+ public StationCommand getRunBlockRerouteCommand(Integer taskNo,
Integer stationId,
Integer targetStationId,
Integer palletSize,
@@ -249,7 +249,7 @@
}
@Override
- public synchronized boolean clearPath(Integer taskNo) {
+ public boolean clearPath(Integer taskNo) {
if (taskNo == null || taskNo <= 0) {
return false;
}
diff --git a/src/main/java/com/zy/core/utils/station/StationOutboundDecisionSupport.java b/src/main/java/com/zy/core/utils/station/StationOutboundDecisionSupport.java
index 3a1450c..02018dd 100644
--- a/src/main/java/com/zy/core/utils/station/StationOutboundDecisionSupport.java
+++ b/src/main/java/com/zy/core/utils/station/StationOutboundDecisionSupport.java
@@ -116,6 +116,7 @@
if (wrkMast == null || wrkMast.getStaNo() == null) {
return null;
}
+ DecisionPathCache decisionPathCache = new DecisionPathCache();
if (!shouldApplyOutOrder(wrkMast, outOrderStationIds)) {
return OutOrderDispatchDecision.direct(wrkMast.getStaNo());
}
@@ -124,13 +125,14 @@
wrkMast.getSourceStaNo(),
wrkMast.getStaNo(),
outOrderStationIds,
- pathLenFactor
+ pathLenFactor,
+ decisionPathCache
);
if (dispatchStationId == null) {
return null;
}
- if (isCurrentOutOrderDispatchStation(currentStationId, wrkMast, outOrderStationIds, pathLenFactor)) {
- return resolveCurrentOutOrderDispatchDecision(currentStationId, wrkMast, outOrderStationIds, pathLenFactor);
+ if (isCurrentOutOrderDispatchStation(currentStationId, wrkMast, outOrderStationIds, pathLenFactor, decisionPathCache)) {
+ return resolveCurrentOutOrderDispatchDecision(currentStationId, wrkMast, outOrderStationIds, pathLenFactor, decisionPathCache);
}
if (!Objects.equals(dispatchStationId, wrkMast.getStaNo())
&& isCurrentOutOrderStation(currentStationId, outOrderStationIds)
@@ -197,12 +199,35 @@
Integer sourceStationId,
Integer targetStationId,
Double pathLenFactor) {
+ return calcOutboundNavigatePath(wrkMast, sourceStationId, targetStationId, pathLenFactor, null);
+ }
+
+ private List<NavigateNode> calcOutboundNavigatePath(WrkMast wrkMast,
+ Integer sourceStationId,
+ Integer targetStationId,
+ Double pathLenFactor,
+ DecisionPathCache decisionPathCache) {
Double normalizedFactor = normalizePathLenFactor(pathLenFactor);
Integer currentTaskNo = wrkMast == null ? null : wrkMast.getWrkNo();
- if (currentTaskNo == null) {
- return navigateUtils.calcOptimalPathByStationId(sourceStationId, targetStationId, null, normalizedFactor);
+ if (decisionPathCache == null) {
+ if (currentTaskNo == null) {
+ return navigateUtils.calcOptimalPathByStationId(sourceStationId, targetStationId, null, normalizedFactor);
+ }
+ return navigateUtils.calcOptimalPathByStationId(sourceStationId, targetStationId, currentTaskNo, normalizedFactor);
}
- return navigateUtils.calcOptimalPathByStationId(sourceStationId, targetStationId, currentTaskNo, normalizedFactor);
+ String cacheKey = buildPathCacheKey(currentTaskNo, sourceStationId, targetStationId, normalizedFactor);
+ List<NavigateNode> cachedPath = decisionPathCache.pathMap.get(cacheKey);
+ if (cachedPath != null) {
+ return cachedPath;
+ }
+ List<NavigateNode> path = currentTaskNo == null
+ ? navigateUtils.calcOptimalPathByStationId(sourceStationId, targetStationId, null, normalizedFactor)
+ : navigateUtils.calcOptimalPathByStationId(sourceStationId, targetStationId, currentTaskNo, normalizedFactor);
+ if (path == null) {
+ path = Collections.emptyList();
+ }
+ decisionPathCache.pathMap.put(cacheKey, path);
+ return path;
}
private boolean isBatchOutboundTaskWithSeq(WrkMast wrkMast) {
@@ -246,7 +271,8 @@
private boolean isCurrentOutOrderDispatchStation(Integer currentStationId,
WrkMast wrkMast,
List<Integer> outOrderStationIds,
- Double pathLenFactor) {
+ Double pathLenFactor,
+ DecisionPathCache decisionPathCache) {
if (!shouldApplyOutOrder(wrkMast, outOrderStationIds) || currentStationId == null) {
return false;
}
@@ -255,7 +281,8 @@
wrkMast.getSourceStaNo(),
wrkMast.getStaNo(),
outOrderStationIds,
- pathLenFactor
+ pathLenFactor,
+ decisionPathCache
);
return dispatchStationId != null
&& !Objects.equals(dispatchStationId, wrkMast.getStaNo())
@@ -272,8 +299,9 @@
private OutOrderDispatchDecision resolveCurrentOutOrderDispatchDecision(Integer currentStationId,
WrkMast wrkMast,
List<Integer> outOrderStationIds,
- Double pathLenFactor) {
- if (!isCurrentOutOrderDispatchStation(currentStationId, wrkMast, outOrderStationIds, pathLenFactor)) {
+ Double pathLenFactor,
+ DecisionPathCache decisionPathCache) {
+ if (!isCurrentOutOrderDispatchStation(currentStationId, wrkMast, outOrderStationIds, pathLenFactor, decisionPathCache)) {
return null;
}
@@ -299,7 +327,7 @@
List<NavigateNode> initPath;
try {
- initPath = calcOutboundNavigatePath(wrkMast, wrkMast.getSourceStaNo(), wrkMast.getStaNo(), pathLenFactor);
+ initPath = calcOutboundNavigatePath(wrkMast, wrkMast.getSourceStaNo(), wrkMast.getStaNo(), pathLenFactor, decisionPathCache);
} catch (Exception e) {
News.taskInfo(wrkMast.getWrkNo(), "鎵规:{} 璁$畻鎺掑簭璺緞澶辫触锛屽綋鍓嶇珯鐐�={}", wrkMast.getBatch(), currentStationId);
return null;
@@ -310,7 +338,7 @@
? currentBatchSeq.equals(wrkMast.getBatchSeq())
: Integer.valueOf(seq + 1).equals(wrkMast.getBatchSeq());
if (toTarget) {
- if (hasReachableOutReleaseSlot(wrkMast, currentStationId, wrkMast.getStaNo(), pathLenFactor)) {
+ if (hasReachableOutReleaseSlot(wrkMast, currentStationId, wrkMast.getStaNo(), pathLenFactor, decisionPathCache)) {
return OutOrderDispatchDecision.direct(wrkMast.getStaNo());
}
StationTaskLoopService.LoopEvaluation loopEvaluation = evaluateOutOrderLoop(
@@ -323,7 +351,8 @@
currentStationId,
outOrderStationIds,
loopEvaluation.getExpectedLoopIssueCount(),
- pathLenFactor
+ pathLenFactor,
+ decisionPathCache
);
if (circleTarget == null) {
News.taskInfo(wrkMast.getWrkNo(), "鐩爣绔欏綋鍓嶄笉鍙繘锛屼笖鏈壘鍒板彲鎵ц鐨勪笅涓�鎺掑簭妫�娴嬬偣锛屽綋鍓嶇珯鐐�={}", currentStationId);
@@ -342,7 +371,8 @@
currentStationId,
outOrderStationIds,
loopEvaluation.getExpectedLoopIssueCount(),
- pathLenFactor
+ pathLenFactor,
+ decisionPathCache
);
if (circleTarget == null) {
News.taskInfo(wrkMast.getWrkNo(), "鏈壘鍒板彲鎵ц鐨勪笅涓�鎺掑簭妫�娴嬬偣锛屽綋鍓嶇珯鐐�={}", currentStationId);
@@ -377,7 +407,8 @@
Integer sourceStationId,
Integer finalTargetStationId,
List<Integer> outOrderList,
- Double pathLenFactor) {
+ Double pathLenFactor,
+ DecisionPathCache decisionPathCache) {
if (finalTargetStationId == null) {
return null;
}
@@ -386,7 +417,7 @@
}
try {
- List<NavigateNode> nodes = calcOutboundNavigatePath(wrkMast, sourceStationId, finalTargetStationId, pathLenFactor);
+ List<NavigateNode> nodes = calcOutboundNavigatePath(wrkMast, sourceStationId, finalTargetStationId, pathLenFactor, decisionPathCache);
for (int i = nodes.size() - 1; i >= 0; i--) {
Integer stationId = getStationIdFromNode(nodes.get(i));
if (stationId == null) {
@@ -407,13 +438,14 @@
private boolean hasReachableOutReleaseSlot(WrkMast wrkMast,
Integer currentStationId,
Integer finalTargetStationId,
- Double pathLenFactor) {
+ Double pathLenFactor,
+ DecisionPathCache decisionPathCache) {
if (currentStationId == null || finalTargetStationId == null) {
return true;
}
try {
- List<NavigateNode> nodes = calcOutboundNavigatePath(wrkMast, currentStationId, finalTargetStationId, pathLenFactor);
+ List<NavigateNode> nodes = calcOutboundNavigatePath(wrkMast, currentStationId, finalTargetStationId, pathLenFactor, decisionPathCache);
if (nodes == null || nodes.isEmpty()) {
return true;
}
@@ -462,7 +494,8 @@
Integer currentStationId,
List<Integer> orderedOutStationList,
Integer expectedLoopIssueCount,
- Double pathLenFactor) {
+ Double pathLenFactor,
+ DecisionPathCache decisionPathCache) {
if (currentStationId == null || orderedOutStationList == null || orderedOutStationList.size() <= 1) {
return null;
}
@@ -477,7 +510,7 @@
continue;
}
try {
- List<NavigateNode> path = calcOutboundNavigatePath(wrkMast, currentStationId, candidateStationId, pathLenFactor);
+ List<NavigateNode> path = calcOutboundNavigatePath(wrkMast, currentStationId, candidateStationId, pathLenFactor, decisionPathCache);
if (path != null && !path.isEmpty()) {
candidateList.add(new CircleTargetCandidate(candidateStationId, path.size(), offset));
}
@@ -609,7 +642,21 @@
return pathLenFactor;
}
+ private String buildPathCacheKey(Integer currentTaskNo,
+ Integer sourceStationId,
+ Integer targetStationId,
+ Double normalizedFactor) {
+ return String.valueOf(currentTaskNo) + "->"
+ + String.valueOf(sourceStationId) + "->"
+ + String.valueOf(targetStationId) + "@"
+ + String.format(java.util.Locale.ROOT, "%.4f", normalizedFactor == null ? 0.0d : normalizedFactor);
+ }
+
private boolean isBlank(String value) {
return value == null || value.trim().isEmpty();
}
+
+ private static class DecisionPathCache {
+ private final Map<String, List<NavigateNode>> pathMap = new HashMap<>();
+ }
}
--
Gitblit v1.9.1