jianghaiyue
6 天以前 1d520bffcd63cb8389c9cdf719c3cf7e7c4af567
algo-zkd/src/main/java/com/algo/service/RemainingPathProcessor.java
@@ -34,6 +34,7 @@
    /**
     * 处理所有CTU的剩余路径,构建时空占用表
     * 🔧 修复:同时处理有剩余路径的AGV和静止AGV的当前位置占用
     *
     * @param agvStatusList CTU状态列表
     * @return 时空占用表,key为"x,y,timeSlot",value为CTU编号
@@ -43,11 +44,50 @@
        for (AGVStatus agv : agvStatusList) {
            if (agv.hasRemainingPath()) {
                // 处理有剩余路径的AGV
                processRemainingPathOccupancy(agv, occupancyMap);
            } else if (agv.getPosition() != null && !agv.getPosition().isEmpty()) {
                // 处理静止AGV的当前位置占用
                processStaticAgvOccupancy(agv, occupancyMap);
            }
        }
        return occupancyMap;
    }
    /**
     * 处理静止AGV的位置占用
     *
     * @param agv          CTU状态
     * @param occupancyMap 时空占用表
     */
    private void processStaticAgvOccupancy(AGVStatus agv, Map<String, String> occupancyMap) {
        String position = agv.getPosition();
        if (position == null || position.isEmpty()) {
            return;
        }
        // 获取位置坐标
        int[] coord = JsonUtils.getCoordinate(position, pathMapping);
        if (coord == null) {
            return;
        }
        CTUPhysicalConfig config = agv.getPhysicalConfig();
        long currentTime = System.currentTimeMillis() / 1000; // 转换为秒
        // 静止AGV占用当前位置的长时间段(假设300秒)
        long occupancyDuration = 300; // 300秒的占用时间
        for (long timeSlot = currentTime; timeSlot < currentTime + occupancyDuration; timeSlot++) {
            String spaceTimeKey = coord[0] + "," + coord[1] + "," + timeSlot;
            occupancyMap.put(spaceTimeKey, agv.getAgvId());
            occupyAdjacentSpaces(coord, timeSlot, agv.getAgvId(), occupancyMap, config);
        }
        System.out.println("  静止AGV " + agv.getAgvId() + " 占用位置 " + position +
                         " (坐标: " + coord[0] + "," + coord[1] + ") " );
    }
    /**
@@ -153,8 +193,16 @@
            String currentDirection = currentCode.getDirection();
            String nextDirection = nextCode.getDirection();
            if (!currentDirection.equals(nextDirection)) {
                stayTime += config.getTurnTime(currentDirection, nextDirection);
            if (currentDirection != null && nextDirection != null) {
                if (!currentDirection.equals(nextDirection)) {
                    stayTime += config.getTurnTime(currentDirection, nextDirection);
                }
            } else {
                if (pathIndex == agv.getCurrentPathIndex()) {
                    System.out.println("AGV " + agv.getAgvId() +
                                     " 的剩余路径中direction字段为null");
                }
                stayTime += 0.5;
            }
        }
@@ -168,7 +216,7 @@
                    stayTime += 2.0; // 放货需要2秒
                    break;
                case "3": // 充电
                    stayTime += 10.0; // 充电停靠需要10秒
                    stayTime += 100.0; // 充电停靠
                    break;
                default:
                    stayTime += 1.0; // 其他动作需要1秒
@@ -362,11 +410,26 @@
        connectedPath.setAgvId(agv.getAgvId());
        connectedPath.setCodeList(remainingCodes);
        // 生成新的段落ID
        String segId = agv.getAgvId() + "_CONNECTED_" + System.currentTimeMillis();
        if (newPath != null && newPath.getSegId() != null) {
            segId = newPath.getSegId() + "_EXTENDED";
        // 使用剩余路径的原始segId
        String segId = remainingPath.getSegId();
        if (segId != null && !segId.trim().isEmpty()) {
            // 如果有新路径连接,在原segId基础上添加扩展标记
            if (newPath != null && newPath.getCodeList() != null && !newPath.getCodeList().isEmpty()) {
                // 检查是否已经有扩展标记,避免重复添加
                if (!segId.endsWith("_EXTENDED")) {
                    segId = segId + "_EXTENDED";
                }
            }
        } else {
            // 如果原始路径没有segId,根据情况生成
            if (newPath != null && newPath.getSegId() != null && !newPath.getSegId().trim().isEmpty()) {
                segId = newPath.getSegId() + "_EXTENDED";
            } else {
                segId = agv.getAgvId() + "_CONNECTED_" + System.currentTimeMillis();
            }
        }
        connectedPath.setSegId(segId);
        return connectedPath;