#
Junjie
18 小时以前 1116b5a1c3feb85959d9b0b03e1c14693271aa8a
src/main/java/com/zy/common/utils/NavigateUtils.java
@@ -11,17 +11,22 @@
import com.zy.asrs.domain.path.StationPathProfileConfig;
import com.zy.asrs.domain.path.StationPathResolvedPolicy;
import com.zy.asrs.domain.path.StationPathRuleConfig;
import com.zy.asrs.domain.vo.StationTaskTraceSegmentVo;
import com.zy.asrs.entity.BasStationOpt;
import com.zy.asrs.domain.vo.StationTaskTraceVo;
import com.zy.asrs.domain.vo.StationCycleCapacityVo;
import com.zy.asrs.domain.vo.StationCycleLoopVo;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.service.BasStationOptService;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.BasStationService;
import com.zy.asrs.service.StationCycleCapacityService;
import com.zy.asrs.service.StationPathPolicyService;
import com.zy.core.News;
import com.zy.core.model.StationObjModel;
import com.zy.core.model.command.StationCommand;
import com.zy.core.enums.StationCommandType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -39,6 +44,9 @@
import com.zy.core.thread.StationThread;
import com.zy.core.trace.StationTaskTraceRegistry;
import java.util.Date;
import java.util.LinkedHashMap;
@Component
public class NavigateUtils {
@@ -50,9 +58,12 @@
    private static final double WAIT_ISSUED_RESERVE_SECONDS = 8.0d;
    private static final double WAIT_PENDING_QUEUE_SECONDS = 5.0d;
    private static final double WAIT_RUN_BLOCK_SECONDS = 30.0d;
    private static final int DEADLOCK_PREFIX_LOOKAHEAD = 6;
    @Autowired
    private BasStationService basStationService;
    @Autowired
    private BasStationOptService basStationOptService;
    @Autowired
    private StationPathPolicyService stationPathPolicyService;
    @Autowired
@@ -61,6 +72,10 @@
    private StationTaskTraceRegistry stationTaskTraceRegistry;
    public synchronized List<NavigateNode> calcByStationId(Integer startStationId, Integer endStationId) {
        return calcByStationId(startStationId, endStationId, null);
    }
    public synchronized List<NavigateNode> calcByStationId(Integer startStationId, Integer endStationId, Integer currentTaskNo) {
        BasStation startStation = basStationService.getById(startStationId);
        if (startStation == null) {
            throw new CoolException("未找到该 起点 对应的站点数据");
@@ -114,7 +129,7 @@
        startTime = System.currentTimeMillis();
        News.info("[WCS Debug] 站点路径权重开始分析,startStationId={},endStationId={}", startStationId, endStationId);
        List<NavigateNode> list = findStationBestPathTwoStage(allList, resolvedPolicy);
        List<NavigateNode> list = findStationBestPathTwoStage(allList, resolvedPolicy, currentTaskNo);
        News.info("[WCS Debug] 站点路径权重分析完成,耗时:{}ms", System.currentTimeMillis() - startTime);
        //去重
@@ -272,7 +287,9 @@
        return new StationPathResolvedPolicy();
    }
    private List<NavigateNode> findStationBestPathTwoStage(List<List<NavigateNode>> allList, StationPathResolvedPolicy resolvedPolicy) {
    private List<NavigateNode> findStationBestPathTwoStage(List<List<NavigateNode>> allList,
                                                           StationPathResolvedPolicy resolvedPolicy,
                                                           Integer currentTaskNo) {
        if (allList == null || allList.isEmpty()) {
            return new ArrayList<>();
        }
@@ -310,7 +327,7 @@
        Map<Integer, StationProtocol> statusMap = loadStationStatusMap();
        Map<Integer, Double> stationLoopLoadMap = loadStationLoopLoadMap();
        StationTrafficSnapshot trafficSnapshot = loadStationTrafficSnapshot(statusMap);
        StationTrafficSnapshot trafficSnapshot = loadStationTrafficSnapshot(statusMap, currentTaskNo);
        Set<Integer> outStationIdSet = loadAllOutStationIdSet();
        List<PathCandidateMetrics> metricsList = new ArrayList<>();
        int skippedByOtherOutStation = 0;
@@ -592,6 +609,7 @@
        metrics.congestionScore = calcCongestionScore(stationIdList, trafficSnapshot);
        metrics.queueDepthScore = calcQueueDepthScore(stationIdList, trafficSnapshot);
        metrics.estimatedWaitSeconds = calcEstimatedWaitSeconds(stationIdList, trafficSnapshot);
        metrics.deadlockRiskScore = calcDeadlockRiskScore(stationIdList, trafficSnapshot);
        metrics.runBlockCount = countRunBlockCount(stationIdList, statusMap);
        metrics.loopPenalty = calcLoopPenalty(stationIdList, stationLoopLoadMap);
        metrics.passOtherOutStationCount = countPassOtherOutStations(path, outStationIdSet);
@@ -618,6 +636,7 @@
                safeDouble(profileConfig.getS2BusyWeight(), 2.0d) * congWeightFactor * metrics.congestionScore
                        + safeDouble(profileConfig.getS2QueueWeight(), 2.5d) * metrics.queueDepthScore
                        + safeDouble(profileConfig.getS2WaitWeight(), 1.5d) * (metrics.estimatedWaitSeconds / 60.0d)
                        + safeDouble(profileConfig.getS2DeadlockWeight(), 8.0d) * metrics.deadlockRiskScore
                        + safeDouble(profileConfig.getS2RunBlockWeight(), 10.0d) * metrics.runBlockCount
                        + safeDouble(profileConfig.getS2LoopLoadWeight(), 12.0d) * metrics.loopPenalty;
        return metrics;
@@ -693,6 +712,36 @@
            score += trafficSnapshot.estimatedWaitSecondsMap.getOrDefault(stationId, 0.0d);
        }
        return score;
    }
    private double calcDeadlockRiskScore(List<Integer> stationIdList, StationTrafficSnapshot trafficSnapshot) {
        if (trafficSnapshot == null || trafficSnapshot.traceRouteList.isEmpty() || stationIdList == null || stationIdList.size() <= 1) {
            return 0.0d;
        }
        List<Integer> candidateFutureStations = distinctPositiveStationIds(stationIdList.subList(1, stationIdList.size()));
        if (candidateFutureStations.isEmpty()) {
            return 0.0d;
        }
        double totalRisk = 0.0d;
        for (TraceRouteSnapshot routeSnapshot : trafficSnapshot.traceRouteList) {
            if (routeSnapshot == null) {
                continue;
            }
            OverlapMetrics pendingMetrics = calcOrderedOverlapMetrics(candidateFutureStations, routeSnapshot.pendingStationIds);
            OverlapMetrics issuedMetrics = calcOrderedOverlapMetrics(candidateFutureStations, routeSnapshot.issuedStationIds);
            totalRisk += pendingMetrics.sequentialRisk * 0.9d;
            totalRisk += issuedMetrics.sequentialRisk * 1.2d;
            totalRisk += pendingMetrics.sharedCount * 0.12d;
            totalRisk += issuedMetrics.sharedCount * 0.18d;
            int currentHitIndex = findFirstOverlapIndex(candidateFutureStations, routeSnapshot.currentStationId);
            if (currentHitIndex >= 0) {
                totalRisk += prefixRiskFactor(currentHitIndex) * 1.5d;
            }
        }
        return totalRisk;
    }
    private int countRunBlockCount(List<Integer> stationIdList, Map<Integer, StationProtocol> statusMap) {
@@ -887,7 +936,7 @@
        return stationLoopLoadMap;
    }
    private StationTrafficSnapshot loadStationTrafficSnapshot(Map<Integer, StationProtocol> statusMap) {
    private StationTrafficSnapshot loadStationTrafficSnapshot(Map<Integer, StationProtocol> statusMap, Integer currentTaskNo) {
        StationTrafficSnapshot snapshot = new StationTrafficSnapshot();
        Map<Integer, Integer> busyMap = new HashMap<>();
        Map<Integer, Integer> issuedReserveMap = new HashMap<>();
@@ -906,12 +955,18 @@
            }
        }
        for (StationTaskTraceVo traceVo : loadActiveTraceList()) {
        for (StationTaskTraceVo traceVo : loadActiveTraceList(currentTaskNo, statusMap)) {
            if (traceVo == null) {
                continue;
            }
            List<Integer> pendingStationIds = distinctPositiveStationIds(traceVo.getPendingStationIds());
            List<Integer> issuedStationIds = distinctPositiveStationIds(traceVo.getLatestIssuedSegmentPath());
            TraceRouteSnapshot routeSnapshot = new TraceRouteSnapshot();
            routeSnapshot.taskNo = traceVo.getTaskNo();
            routeSnapshot.currentStationId = traceVo.getCurrentStationId();
            routeSnapshot.pendingStationIds = pendingStationIds;
            routeSnapshot.issuedStationIds = issuedStationIds;
            snapshot.traceRouteList.add(routeSnapshot);
            Set<Integer> pendingSet = new HashSet<>(pendingStationIds);
            for (Integer stationId : issuedStationIds) {
                if (stationId == null || !pendingSet.contains(stationId)) {
@@ -972,28 +1027,32 @@
        return snapshot;
    }
    private List<StationTaskTraceVo> loadActiveTraceList() {
        if (stationTaskTraceRegistry == null) {
            return Collections.emptyList();
        }
        List<StationTaskTraceVo> traceList;
        try {
            traceList = stationTaskTraceRegistry.listLatestTraces();
        } catch (Exception ignore) {
            return Collections.emptyList();
        }
        if (traceList == null || traceList.isEmpty()) {
            return Collections.emptyList();
        }
        List<StationTaskTraceVo> result = new ArrayList<>();
        for (StationTaskTraceVo traceVo : traceList) {
            if (!isPlanningActiveTrace(traceVo)) {
                continue;
    private List<StationTaskTraceVo> loadActiveTraceList(Integer currentTaskNo, Map<Integer, StationProtocol> statusMap) {
        Map<Integer, StationTaskTraceVo> traceMap = new LinkedHashMap<>();
        if (stationTaskTraceRegistry != null) {
            try {
                List<StationTaskTraceVo> traceList = stationTaskTraceRegistry.listLatestTraces();
                if (traceList != null) {
                    for (StationTaskTraceVo traceVo : traceList) {
                        if (!isPlanningActiveTrace(traceVo)) {
                            continue;
                        }
                        if (currentTaskNo != null && currentTaskNo.equals(traceVo.getTaskNo())) {
                            continue;
                        }
                        if (traceVo.getTaskNo() != null) {
                            traceMap.put(traceVo.getTaskNo(), traceVo);
                        }
                    }
                }
            } catch (Exception ignore) {
            }
            result.add(traceVo);
        }
        return result;
        Map<Integer, StationTaskTraceVo> fallbackTraceMap = loadFallbackActiveTraceMap(currentTaskNo, statusMap, traceMap.keySet());
        if (!fallbackTraceMap.isEmpty()) {
            traceMap.putAll(fallbackTraceMap);
        }
        return new ArrayList<>(traceMap.values());
    }
    private boolean isPlanningActiveTrace(StationTaskTraceVo traceVo) {
@@ -1004,6 +1063,275 @@
        return StationTaskTraceRegistry.STATUS_WAITING.equals(status)
                || StationTaskTraceRegistry.STATUS_RUNNING.equals(status)
                || StationTaskTraceRegistry.STATUS_REROUTED.equals(status);
    }
    private Map<Integer, StationTaskTraceVo> loadFallbackActiveTraceMap(Integer currentTaskNo,
                                                                        Map<Integer, StationProtocol> statusMap,
                                                                        Set<Integer> existingTaskNoSet) {
        if (basStationOptService == null || statusMap == null || statusMap.isEmpty()) {
            return Collections.emptyMap();
        }
        Map<Integer, StationProtocol> activeTaskProtocolMap = new LinkedHashMap<>();
        for (StationProtocol protocol : statusMap.values()) {
            if (protocol == null || protocol.getTaskNo() == null || protocol.getTaskNo() <= 0) {
                continue;
            }
            if (!Boolean.TRUE.equals(protocol.isLoading())) {
                continue;
            }
            if (currentTaskNo != null && currentTaskNo.equals(protocol.getTaskNo())) {
                continue;
            }
            if (existingTaskNoSet != null && existingTaskNoSet.contains(protocol.getTaskNo())) {
                continue;
            }
            activeTaskProtocolMap.putIfAbsent(protocol.getTaskNo(), protocol);
        }
        if (activeTaskProtocolMap.isEmpty()) {
            return Collections.emptyMap();
        }
        List<Integer> taskNoList = new ArrayList<>(activeTaskProtocolMap.keySet());
        int limit = Math.max(50, taskNoList.size() * 8);
        List<BasStationOpt> optList;
        try {
            optList = basStationOptService.list(new QueryWrapper<BasStationOpt>()
                    .select("id", "task_no", "send_time", "command", "mode", "send", "target_station_id")
                    .in("task_no", taskNoList)
                    .eq("send", 1)
                    .orderByDesc("send_time")
                    .last("limit " + limit));
        } catch (Exception ignore) {
            return Collections.emptyMap();
        }
        if (optList == null || optList.isEmpty()) {
            return Collections.emptyMap();
        }
        Map<Integer, List<FallbackMoveCommand>> fallbackCommandMap = new LinkedHashMap<>();
        for (BasStationOpt opt : optList) {
            FallbackMoveCommand moveCommand = parseFallbackMoveCommand(opt);
            if (moveCommand == null || moveCommand.taskNo == null) {
                continue;
            }
            if (!activeTaskProtocolMap.containsKey(moveCommand.taskNo)) {
                continue;
            }
            fallbackCommandMap.computeIfAbsent(moveCommand.taskNo, key -> new ArrayList<>()).add(moveCommand);
        }
        Map<Integer, StationTaskTraceVo> result = new LinkedHashMap<>();
        for (Map.Entry<Integer, StationProtocol> entry : activeTaskProtocolMap.entrySet()) {
            Integer taskNo = entry.getKey();
            StationProtocol protocol = entry.getValue();
            StationTaskTraceVo fallbackTrace = buildFallbackTraceVo(taskNo, protocol, fallbackCommandMap.get(taskNo));
            if (fallbackTrace != null) {
                result.put(taskNo, fallbackTrace);
            }
        }
        return result;
    }
    private FallbackMoveCommand parseFallbackMoveCommand(BasStationOpt opt) {
        if (opt == null || opt.getTaskNo() == null || opt.getTaskNo() <= 0) {
            return null;
        }
        try {
            StationCommand command = JSON.parseObject(opt.getCommand(), StationCommand.class);
            if (command == null || command.getCommandType() != StationCommandType.MOVE) {
                return null;
            }
            List<Integer> navigatePath = distinctPositiveStationIds(command.getNavigatePath());
            if (navigatePath.isEmpty()) {
                return null;
            }
            FallbackMoveCommand item = new FallbackMoveCommand();
            item.taskNo = opt.getTaskNo();
            item.traceVersion = command.getTraceVersion();
            item.segmentNo = command.getSegmentNo();
            item.segmentCount = command.getSegmentCount();
            item.stationId = command.getStationId();
            item.targetStaNo = command.getTargetStaNo();
            item.navigatePath = navigatePath;
            item.sendTime = opt.getSendTime();
            return item;
        } catch (Exception ignore) {
            return null;
        }
    }
    private StationTaskTraceVo buildFallbackTraceVo(Integer taskNo,
                                                    StationProtocol protocol,
                                                    List<FallbackMoveCommand> commandList) {
        if (taskNo == null || protocol == null || commandList == null || commandList.isEmpty()) {
            return null;
        }
        Integer latestTraceVersion = null;
        long latestTimestamp = 0L;
        for (FallbackMoveCommand item : commandList) {
            if (item == null) {
                continue;
            }
            if (item.traceVersion != null && (latestTraceVersion == null || item.traceVersion > latestTraceVersion)) {
                latestTraceVersion = item.traceVersion;
            }
            long ts = item.sendTime == null ? 0L : item.sendTime.getTime();
            if (ts > latestTimestamp) {
                latestTimestamp = ts;
            }
        }
        List<FallbackMoveCommand> sameTraceCommandList = new ArrayList<>();
        for (FallbackMoveCommand item : commandList) {
            if (item == null) {
                continue;
            }
            if (latestTraceVersion == null || latestTraceVersion.equals(item.traceVersion)) {
                sameTraceCommandList.add(item);
            }
        }
        sameTraceCommandList.sort((a, b) -> {
            int av = a.segmentNo == null ? Integer.MAX_VALUE : a.segmentNo;
            int bv = b.segmentNo == null ? Integer.MAX_VALUE : b.segmentNo;
            if (av != bv) {
                return Integer.compare(av, bv);
            }
            long at = a.sendTime == null ? 0L : a.sendTime.getTime();
            long bt = b.sendTime == null ? 0L : b.sendTime.getTime();
            return Long.compare(at, bt);
        });
        List<Integer> issuedPath = new ArrayList<>();
        List<StationTaskTraceSegmentVo> segmentList = new ArrayList<>();
        FallbackMoveCommand latestCommand = null;
        for (FallbackMoveCommand item : sameTraceCommandList) {
            if (item == null || item.navigatePath == null || item.navigatePath.isEmpty()) {
                continue;
            }
            appendMergedPath(issuedPath, item.navigatePath);
            segmentList.add(toTraceSegment(item));
            if (latestCommand == null || compareFallbackCommand(item, latestCommand) > 0) {
                latestCommand = item;
            }
        }
        if (issuedPath.isEmpty()) {
            return null;
        }
        Integer currentStationId = protocol.getStationId();
        List<Integer> passedStationIds = new ArrayList<>();
        List<Integer> pendingStationIds = new ArrayList<>();
        if (currentStationId != null) {
            int currentIndex = issuedPath.indexOf(currentStationId);
            if (currentIndex >= 0) {
                passedStationIds = copyIntegerSubList(issuedPath, 0, currentIndex);
                pendingStationIds = copyIntegerSubList(issuedPath, currentIndex + 1, issuedPath.size());
            } else {
                pendingStationIds = new ArrayList<>(issuedPath);
            }
        } else {
            pendingStationIds = new ArrayList<>(issuedPath);
        }
        StationTaskTraceVo vo = new StationTaskTraceVo();
        vo.setTaskNo(taskNo);
        vo.setThreadImpl("DB_FALLBACK");
        vo.setStatus(StationTaskTraceRegistry.STATUS_RUNNING);
        vo.setTraceVersion(latestTraceVersion == null ? 1 : latestTraceVersion);
        vo.setStartStationId(issuedPath.isEmpty() ? null : issuedPath.get(0));
        vo.setCurrentStationId(currentStationId);
        vo.setFinalTargetStationId(protocol.getTargetStaNo() != null ? protocol.getTargetStaNo()
                : latestCommand == null ? null : latestCommand.targetStaNo);
        vo.setBlockedStationId(null);
        vo.setFullPathStationIds(new ArrayList<>(issuedPath));
        vo.setIssuedStationIds(new ArrayList<>(issuedPath));
        vo.setPassedStationIds(passedStationIds);
        vo.setPendingStationIds(pendingStationIds);
        vo.setLatestIssuedSegmentPath(latestCommand == null ? Collections.emptyList() : new ArrayList<>(latestCommand.navigatePath));
        vo.setSegmentList(segmentList);
        vo.setIssuedSegmentCount(segmentList.size());
        vo.setTotalSegmentCount(latestCommand == null || latestCommand.segmentCount == null
                ? segmentList.size()
                : latestCommand.segmentCount);
        vo.setUpdatedAt(latestTimestamp > 0L ? latestTimestamp : System.currentTimeMillis());
        vo.setEvents(Collections.emptyList());
        return vo;
    }
    private int compareFallbackCommand(FallbackMoveCommand a, FallbackMoveCommand b) {
        int av = a == null || a.segmentNo == null ? Integer.MIN_VALUE : a.segmentNo;
        int bv = b == null || b.segmentNo == null ? Integer.MIN_VALUE : b.segmentNo;
        if (av != bv) {
            return Integer.compare(av, bv);
        }
        long at = a == null || a.sendTime == null ? 0L : a.sendTime.getTime();
        long bt = b == null || b.sendTime == null ? 0L : b.sendTime.getTime();
        return Long.compare(at, bt);
    }
    private StationTaskTraceSegmentVo toTraceSegment(FallbackMoveCommand item) {
        StationTaskTraceSegmentVo segmentVo = new StationTaskTraceSegmentVo();
        if (item == null) {
            return segmentVo;
        }
        segmentVo.setSegmentNo(item.segmentNo);
        segmentVo.setSegmentCount(item.segmentCount);
        segmentVo.setStationId(item.stationId);
        segmentVo.setTargetStationId(item.targetStaNo);
        segmentVo.setSegmentPath(item.navigatePath == null ? Collections.emptyList() : new ArrayList<>(item.navigatePath));
        segmentVo.setIssued(Boolean.TRUE);
        return segmentVo;
    }
    private void appendMergedPath(List<Integer> target, List<Integer> source) {
        if (target == null || source == null || source.isEmpty()) {
            return;
        }
        if (target.isEmpty()) {
            target.addAll(source);
            return;
        }
        int overlap = 0;
        int maxOverlap = Math.min(target.size(), source.size());
        for (int size = maxOverlap; size >= 1; size--) {
            boolean matched = true;
            for (int i = 0; i < size; i++) {
                Integer left = target.get(target.size() - size + i);
                Integer right = source.get(i);
                if (left == null || !left.equals(right)) {
                    matched = false;
                    break;
                }
            }
            if (matched) {
                overlap = size;
                break;
            }
        }
        for (int i = overlap; i < source.size(); i++) {
            Integer stationId = source.get(i);
            if (stationId != null) {
                target.add(stationId);
            }
        }
    }
    private List<Integer> copyIntegerSubList(List<Integer> source, int fromIndex, int toIndex) {
        if (source == null || source.isEmpty()) {
            return new ArrayList<>();
        }
        int from = Math.max(0, fromIndex);
        int to = Math.min(source.size(), Math.max(from, toIndex));
        List<Integer> result = new ArrayList<>();
        for (int i = from; i < to; i++) {
            Integer value = source.get(i);
            if (value != null) {
                result.add(value);
            }
        }
        return result;
    }
    private List<Integer> distinctPositiveStationIds(List<Integer> stationIdList) {
@@ -1028,6 +1356,79 @@
            return;
        }
        target.put(stationId, target.getOrDefault(stationId, 0) + delta);
    }
    private OverlapMetrics calcOrderedOverlapMetrics(List<Integer> candidateStations, List<Integer> routeStations) {
        OverlapMetrics metrics = new OverlapMetrics();
        if (candidateStations == null || candidateStations.isEmpty() || routeStations == null || routeStations.isEmpty()) {
            return metrics;
        }
        Map<Integer, Integer> routeIndexMap = new HashMap<>();
        for (int i = 0; i < routeStations.size(); i++) {
            Integer stationId = routeStations.get(i);
            if (stationId != null && !routeIndexMap.containsKey(stationId)) {
                routeIndexMap.put(stationId, i);
            }
        }
        if (routeIndexMap.isEmpty()) {
            return metrics;
        }
        for (int i = 0; i < candidateStations.size(); i++) {
            Integer stationId = candidateStations.get(i);
            if (stationId != null && routeIndexMap.containsKey(stationId)) {
                metrics.sharedCount++;
            }
        }
        for (int candidateStart = 0; candidateStart < candidateStations.size(); candidateStart++) {
            Integer firstStation = candidateStations.get(candidateStart);
            Integer routeStart = routeIndexMap.get(firstStation);
            if (routeStart == null) {
                continue;
            }
            int length = 1;
            int prevRouteIndex = routeStart;
            for (int j = candidateStart + 1; j < candidateStations.size(); j++) {
                Integer nextRouteIndex = routeIndexMap.get(candidateStations.get(j));
                if (nextRouteIndex == null || nextRouteIndex.intValue() != prevRouteIndex + 1) {
                    break;
                }
                length++;
                prevRouteIndex = nextRouteIndex;
            }
            double risk = length * prefixRiskFactor(candidateStart);
            if (risk > metrics.sequentialRisk) {
                metrics.sequentialRisk = risk;
            }
        }
        return metrics;
    }
    private int findFirstOverlapIndex(List<Integer> stationIdList, Integer targetStationId) {
        if (stationIdList == null || stationIdList.isEmpty() || targetStationId == null) {
            return -1;
        }
        for (int i = 0; i < stationIdList.size(); i++) {
            Integer stationId = stationIdList.get(i);
            if (targetStationId.equals(stationId)) {
                return i;
            }
        }
        return -1;
    }
    private double prefixRiskFactor(int candidateIndex) {
        if (candidateIndex < 0) {
            return 0.0d;
        }
        if (candidateIndex >= DEADLOCK_PREFIX_LOOKAHEAD) {
            return 0.15d;
        }
        return (double) (DEADLOCK_PREFIX_LOOKAHEAD - candidateIndex) / (double) DEADLOCK_PREFIX_LOOKAHEAD;
    }
    private int compareDouble(double left, double right, int thenLeft1, int thenRight1, int thenLeft2, int thenRight2) {
@@ -1067,6 +1468,7 @@
        private double congestionScore;
        private double queueDepthScore;
        private double estimatedWaitSeconds;
        private double deadlockRiskScore;
        private int runBlockCount;
        private int softDeviationCount;
        private double loopPenalty;
@@ -1078,6 +1480,30 @@
        private final Map<Integer, Double> congestionScoreMap = new HashMap<>();
        private final Map<Integer, Integer> queueDepthMap = new HashMap<>();
        private final Map<Integer, Double> estimatedWaitSecondsMap = new HashMap<>();
        private final List<TraceRouteSnapshot> traceRouteList = new ArrayList<>();
    }
    private static class TraceRouteSnapshot {
        private Integer taskNo;
        private Integer currentStationId;
        private List<Integer> pendingStationIds = Collections.emptyList();
        private List<Integer> issuedStationIds = Collections.emptyList();
    }
    private static class OverlapMetrics {
        private int sharedCount;
        private double sequentialRisk;
    }
    private static class FallbackMoveCommand {
        private Integer taskNo;
        private Integer traceVersion;
        private Integer segmentNo;
        private Integer segmentCount;
        private Integer stationId;
        private Integer targetStaNo;
        private List<Integer> navigatePath = Collections.emptyList();
        private Date sendTime;
    }
    private static class PathGlobalPolicy {