#
luxiaotao1123
2024-12-30 3209b7899f99fbc567c24be9709ba289f33ea73b
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java
@@ -57,10 +57,11 @@
        NavigateNode startNode = new NavigateNode(startMapIdx[0], startMapIdx[1], startCode.getData());
        NavigateNode endNode = new NavigateNode(endMapIdx[0], endMapIdx[1], endCode.getData());
        long startTime = System.currentTimeMillis();
        NavigateNode finishNode = aStarNavigateService.execute(agvNo, startNode, endNode, lock, blackList, segment);
//        System.out.println("AStart spend time: " + (System.currentTimeMillis() - startTime));
        if (null == finishNode) {
            log.warn("{} 号AGV检索[{}] ===>> [{}]路径失败......", agvNo, startCode.getData(), endCode.getData());
            return new ArrayList<>();
        }
@@ -204,18 +205,17 @@
            Integer serial = dynamicNode.getSerial();
            long time = dynamicNode.getTime();
            List<String> resetCodeList = new ArrayList<>();
            for (int i = 0; i < dynamicMatrix.length; i++) {
                for (int j = 0; j < dynamicMatrix[i].length; j++) {
                    if (i == codeMatrixIdx[0] && j == codeMatrixIdx[1]) { continue; }
//                    if (i == codeMatrixIdx[0] && j == codeMatrixIdx[1]) { continue; }
                    DynamicNode node = dynamicMatrix[i][j];
                    if (node.getVehicle().equals(agvNo)) {
                        if (node.getSerial() < serial || node.getTime() != time) {
                        if (node.getSerial() < serial) {
                            resetCodeList.add(codeMatrix[i][j]);
                        }
                    }
@@ -265,7 +265,7 @@
        NavigateNode originNode = new NavigateNode(codeMatrixIdx[0], codeMatrixIdx[1], code);
        List<NavigateNode> includeList = new ArrayList<>();
        List<NavigateNode> existNodes = new ArrayList<>();
        Set<NavigateNode> existNodes = new HashSet<>();
        includeList.add(originNode);
        existNodes.add(originNode);
@@ -277,7 +277,7 @@
    public void spreadWaveNode(NavigateNode originNode, NavigateNode currNode
            , String[][] codeMatrix, String[][] cdaMatrix, Double radiusLen
            , List<NavigateNode> includeList, List<NavigateNode> existNodes) {
            , List<NavigateNode> includeList, Set<NavigateNode> existNodes) {
        int x = currNode.getX();
        int y = currNode.getY();
@@ -289,7 +289,7 @@
    public void extendNeighborNodes(NavigateNode originNode, NavigateNode nextNode
            , String[][] codeMatrix, String[][] cdaMatrix, Double radiusLen
            , List<NavigateNode> includeList, List<NavigateNode> existNodes) {
            , List<NavigateNode> includeList, Set<NavigateNode> existNodes) {
        int x = nextNode.getX();
        int y = nextNode.getY();
@@ -299,48 +299,26 @@
            return;
        }
        if (this.isExist(nextNode, existNodes)) {
        if (existNodes.contains(nextNode)) {
            return;
        }
        existNodes.add(nextNode);
        String nextNodeCodeData = codeMatrix[x][y];
        if (nextNodeCodeData.equals(CodeNodeType.NONE.val)) {
        List<Double> o1Cda = MapDataUtils.parseCdaNode(cdaMatrix[originNode.getX()][originNode.getY()]);
        List<Double> o2Cda = MapDataUtils.parseCdaNode(cdaMatrix[x][y]);
        if (Math.pow(o1Cda.get(0) - o2Cda.get(0), 2) + Math.pow(o1Cda.get(1) - o2Cda.get(1), 2) <= Math.pow(radiusLen, 2)) {
            nextNode.setCodeData(codeMatrix[x][y]);
            if (!nextNode.getCodeData().equals(CodeNodeType.NONE.val)) {
                includeList.add(nextNode);
            }
            this.spreadWaveNode(originNode, nextNode, codeMatrix, cdaMatrix, radiusLen, includeList, existNodes);
        } else {
            List<Double> o1Cda = MapDataUtils.parseCdaNode(cdaMatrix[originNode.getX()][originNode.getY()]);
            List<Double> o2Cda = MapDataUtils.parseCdaNode(cdaMatrix[nextNode.getX()][nextNode.getY()]);
//            if (Math.pow(o1.getX() - o2.getX(), 2) + Math.pow(o1.getY() - o2.getY(), 2) <= Math.pow(radiusLen, 2)) {
            if (Math.pow(o1Cda.get(0) - o2Cda.get(0), 2) + Math.pow(o1Cda.get(1) - o2Cda.get(1), 2) <= Math.pow(radiusLen, 2)) {
                nextNode.setCodeData(nextNodeCodeData);
                includeList.add(nextNode);
                this.spreadWaveNode(originNode, nextNode, codeMatrix, cdaMatrix, radiusLen, includeList, existNodes);
            }
        }
    }
    private boolean isExist(NavigateNode node, List<NavigateNode> existNodes) {
        for (NavigateNode existNode : existNodes) {
            if (this.isSame(node, existNode)) {
                return true;
            }
        }
        return false;
    }
    private boolean isSame(NavigateNode o1, NavigateNode o2) {
        if (Cools.isEmpty(o1, o2)) {
            return false;
        }
        return o1.getX() == o2.getX() && o1.getY() == o2.getY();
    }
    // v2 BFS ------------------------------------------------------------------------------
@@ -392,7 +370,7 @@
        }
        // If the node has already been visited, skip it
        if (this.isExist0(nextNode, visited)) {
        if (visited.contains(nextNode)) {
            return;
        }
@@ -420,15 +398,6 @@
                queue.offer(nextNode);
            }
        }
    }
    private boolean isExist0(NavigateNode node, Set<NavigateNode> existNodes) {
        for (NavigateNode existNode : existNodes) {
            if (this.isSame(node, existNode)) {
                return true;
            }
        }
        return false;
    }