From 1c6d2b037844239b907adfe3882d2cc41a99a3d3 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 06 五月 2026 17:18:16 +0800
Subject: [PATCH] #dfs
---
src/main/java/com/zy/core/thread/impl/v5/StationV5RunBlockReroutePlanner.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/impl/v5/StationV5RunBlockReroutePlanner.java b/src/main/java/com/zy/core/thread/impl/v5/StationV5RunBlockReroutePlanner.java
index 5c1d3c3..7ce54c6 100644
--- a/src/main/java/com/zy/core/thread/impl/v5/StationV5RunBlockReroutePlanner.java
+++ b/src/main/java/com/zy/core/thread/impl/v5/StationV5RunBlockReroutePlanner.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.core.common.Cools;
import com.zy.common.utils.RedisUtil;
+import com.zy.core.News;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.model.command.StationCommand;
import com.zy.core.service.StationTaskLoopService;
@@ -19,6 +20,7 @@
private static final int RUN_BLOCK_REROUTE_STATE_EXPIRE_SECONDS = 60 * 60 * 24;
private static final int SHORT_PATH_REPEAT_AVOID_THRESHOLD = 2;
+ private static final int PLANNER_RESET_PLAN_COUNT_THRESHOLD = 20;
private final RedisUtil redisUtil;
@@ -34,11 +36,34 @@
rerouteState.setTaskNo(taskNo);
rerouteState.setBlockStationId(blockStationId);
rerouteState.setPlanCount((rerouteState.getPlanCount() == null ? 0 : rerouteState.getPlanCount()) + 1);
+ int currentPlanCount = rerouteState.getPlanCount() == null ? 0 : rerouteState.getPlanCount();
+ boolean resetForPlanCountLimit = rerouteState.getPlanCount() > PLANNER_RESET_PLAN_COUNT_THRESHOLD;
+ if (resetForPlanCountLimit) {
+ rerouteState.resetPlanner();
+ rerouteState.setTaskNo(taskNo);
+ rerouteState.setBlockStationId(blockStationId);
+ rerouteState.setPlanCount(1);
+ News.info("杈撻�佺嚎鍫靛閲嶈鍒抪lanner绱瓒呰繃闃堝�硷紝宸叉竻绌鸿矾绾胯蹇嗗苟浠庢渶鐭矾绾块噸鏂伴�夋嫨锛宼askNo={}锛宐lockStationId={}锛宲lanCount={}锛宼hreshold={}",
+ taskNo,
+ blockStationId,
+ currentPlanCount,
+ PLANNER_RESET_PLAN_COUNT_THRESHOLD);
+ }
- StationCommand rerouteCommand = selectAvailableRerouteCommand(rerouteState, loopEvaluation, candidateCommands);
+ StationCommand rerouteCommand = selectAvailableRerouteCommand(
+ rerouteState,
+ loopEvaluation,
+ candidateCommands,
+ resetForPlanCountLimit
+ );
if (rerouteCommand == null && candidateCommands != null && !candidateCommands.isEmpty()) {
rerouteState.resetIssuedRoutes();
- rerouteCommand = selectAvailableRerouteCommand(rerouteState, loopEvaluation, candidateCommands);
+ rerouteCommand = selectAvailableRerouteCommand(
+ rerouteState,
+ loopEvaluation,
+ candidateCommands,
+ resetForPlanCountLimit
+ );
}
saveRunBlockRerouteState(rerouteState);
@@ -51,7 +76,8 @@
private StationCommand selectAvailableRerouteCommand(RunBlockRerouteState rerouteState,
StationTaskLoopService.LoopEvaluation loopEvaluation,
- List<StationCommand> candidateCommands) {
+ List<StationCommand> candidateCommands,
+ boolean preferShortestPath) {
if (rerouteState == null || candidateCommands == null || candidateCommands.isEmpty()) {
return null;
}
@@ -90,7 +116,9 @@
return null;
}
- List<RerouteCandidateCommand> orderedCandidateCommandList = reorderCandidateCommandsForLoopRelease(candidateCommandList);
+ List<RerouteCandidateCommand> orderedCandidateCommandList = preferShortestPath
+ ? reorderCandidateCommandsByShortestPath(candidateCommandList)
+ : reorderCandidateCommandsForLoopRelease(candidateCommandList);
for (RerouteCandidateCommand candidateCommand : orderedCandidateCommandList) {
if (candidateCommand == null || candidateCommand.getCommand() == null) {
continue;
@@ -110,6 +138,19 @@
return rerouteCommand;
}
return null;
+ }
+
+ private List<RerouteCandidateCommand> reorderCandidateCommandsByShortestPath(List<RerouteCandidateCommand> candidateCommandList) {
+ if (candidateCommandList == null || candidateCommandList.isEmpty()) {
+ return new ArrayList<>();
+ }
+ List<RerouteCandidateCommand> reorderedList = new ArrayList<>(candidateCommandList);
+ reorderedList.sort((left, right) -> {
+ int leftPathLength = left == null || left.getPathLength() == null ? Integer.MAX_VALUE : left.getPathLength();
+ int rightPathLength = right == null || right.getPathLength() == null ? Integer.MAX_VALUE : right.getPathLength();
+ return Integer.compare(leftPathLength, rightPathLength);
+ });
+ return reorderedList;
}
private List<RerouteCandidateCommand> reorderCandidateCommandsForLoopRelease(List<RerouteCandidateCommand> candidateCommandList) {
@@ -344,6 +385,11 @@
this.issuedRouteSignatureSet = new LinkedHashSet<>();
}
+ private void resetPlanner() {
+ resetIssuedRoutes();
+ this.routeIssueCountMap = new HashMap<>();
+ }
+
private static String buildPathSignatureText(List<Integer> routePath) {
if (routePath == null || routePath.isEmpty()) {
return "";
--
Gitblit v1.9.1