#
luxiaotao1123
2024-10-25 beb476733eaff1f3a76ec1be772337655803cccb
zy-acs-manager/src/main/java/com/zy/acs/manager/core/DispatcherTestController.java
@@ -38,13 +38,13 @@
        Map<String, List<String>> adjacencyCodeMap = new HashMap<>();
        for (Code code : codeList) {
            List<Long> adjacencyNode = routeService.getAdjacencyNode(code.getId());
            adjacencyCodeMap.put(code.getData(), adjacencyNode.stream().map(node -> {
                return codeService.getById(node).getData();
            }).collect(Collectors.toList()));
            adjacencyCodeMap.put(code.getData(), adjacencyNode.stream().map(node -> (
                    codeService.getById(node).getData()
            )).collect(Collectors.toList()));
        }
        List<String> codeDataList = codeList.stream().map(Code::getData).collect(Collectors.toList());
        System.out.println(codeDataList.toString());
        System.out.println(adjacencyCodeMap.toString());
//        System.out.println(codeDataList.toString());
//        System.out.println(adjacencyCodeMap.toString());
        Set<String> visited = new HashSet<>();
@@ -74,6 +74,76 @@
            }
        }
        /**
         * 1.explore a dead end lane and checkout end point that is not dead point
         * 2.if this point has two near points and one of those points which not in current lane was also have two near points too
         * 3.then merge above two lane because they can connect each other
         */
        Iterator<Lane> iterator = lanes.iterator();
        while (iterator.hasNext()) {
            Lane lane = iterator.next();
            String[] endPoints = lane.queryEndPoints();
            if (null == endPoints) {
                continue;
            }
            String startPoint = endPoints[0];
            String endPoint = endPoints[1];
            boolean isDeadEndLane = false;
            String deadEndPoint = null;
            Integer anotherPointNearsCount = null;
            if (adjacencyCodeMap.get(startPoint).size() == 1) {
                isDeadEndLane = true;
                deadEndPoint = startPoint;
                anotherPointNearsCount = adjacencyCodeMap.get(endPoint).size();
            }
            if (adjacencyCodeMap.get(endPoint).size() == 1) {
                isDeadEndLane = true;
                deadEndPoint = endPoint;
                anotherPointNearsCount = adjacencyCodeMap.get(startPoint).size();
            }
            if (!isDeadEndLane) {
                continue;
            }
            if (anotherPointNearsCount == 2) {
                String anotherPoint = deadEndPoint.equals(startPoint) ? endPoint : startPoint;
                List<String> anotherPointNears = adjacencyCodeMap.get(anotherPoint);
                for (String anotherPointNear : anotherPointNears) {
                    if (!lane.getCodes().contains(anotherPointNear) && adjacencyCodeMap.get(anotherPointNear).size() == 2) {
                        for (Lane lane0 : lanes) {
                            if (lane0.getCodes().contains(anotherPointNear)) {
                                lane0.getCodes().addAll(lane.getCodes());
                                iterator.remove();
                                Collections.shuffle(lane0.getCodes());
                                System.out.println(lane0.getCodes().toString());
                                for (String code : lane0.getCodes()) {
                                    System.out.println("key: " + code + "; val" + adjacencyCodeMap.get(code).toString());
                                }
                                lane0.sortUsingDfs(adjacencyCodeMap);
                                System.out.println(lane0.getCodes().toString());
                            }
                        }
                    }
                }
            }
        }
        for (Lane lane : lanes) {
            lane.removeInteraction(adjacencyCodeMap);
        }
        lanes.removeIf(next -> next.getCodes().size() <= 2);
        System.out.println(GsonUtils.toJson(lanes));
        return R.ok().add(lanes);