jianghaiyue
5 天以前 71f29001d7ec27a72b33143dc104abd34822268a
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秒