経路計画の計画ノードおよび接続ノード内の計画ノードのシリアル番号コード

バックグラウンド

経路計画機能があり、複数のノードを同時に計画し、検査には通常複数のノードが使用されます。接続ノードはノード間の経路計画アルゴリズムを通じて計算され、各計画ノードと接続ノードは計画経路に統合されます。ここで、(パス計画アルゴリズムを使用した後) 以前の計画ノードに従って計画ノードを並べ替えるだけで済みます。プランニング ノードの順序は異なり、同じパスに常にシリアル番号が蓄積される必要があります。同じプランニング ノードに複数のシリアル番号を持つことができますが、それらを繰り返すことはできません。それを書き上げるのに午後丸一日と夜の8時か9時かかったので、ここに記録します。

コード

			String lastPoint = "";
            StringBuilder sb = new StringBuilder();
            //未去重路线的巡检点位置,用于记录
            List<Integer> indexRecord = new ArrayList<>();
            //route为路径规划算法算出的所以有序节点,用逗号隔开,需要实现去重,两个连续节点重复的
            //此处只有多个节点的编号
            int i = 0;
            for (String point : route.split(",")) {
    
    
                if (lastPoint == "") {
    
    
                    lastPoint = point;
                    sb.append(point + ",");
                    i++;
                    indexRecord.add(i);

                } else {
    
    
                    String nextPointCodes[] = map.get(lastPoint).split(",");
                    //节点的相邻节点转换,逗号分隔转数组转List集合
                    Set<String> setPoint = new HashSet<>();
                    if (nextPointCodes != null && nextPointCodes.length > 0) {
    
    
                        for (String nextPointCode : nextPointCodes) {
    
    
                            setPoint.add(nextPointCode);
                        }
                    }
                    //如果两个巡检点直接相连,就不需要使用算法计算,否则使用算法计算
                    if (setPoint.contains(point)) {
    
    
                        lastPoint = point;
                        sb.append(point + ",");
                        i++;
                        indexRecord.add(i);
   

                    } else {
    
    
                        List<List<String>> list = new ArrayList<>();
                        int[] array = new int[]{
    
    0};
                        int index = 0;
						//路径规划算法
                        countRoute(lastPoint, point, map, list, index, array);
                        //从规划路径中找最优路径
                        String bestRoute = findBestRoute(lastPoint, point, list, locationMap);
                        sb.append(bestRoute + ",");
                        //记录规划节点的位置
                        i = i + bestRoute.split(",").length;
                        indexRecord.add(i);
                        //取前面路径中最后一个位置点作为起点
                        String num[] = bestRoute.split(",");
                        lastPoint = num[num.length - 1];
                    }
                }
            }
            //去粗重复数量
            int repeatTotalNum = 0;//中间有几个不是规划节点的个数
            //去重路线的巡检点位置
            List<Integer> repeatIndexRecord = new ArrayList<>();
            //去重
            String lastCode = "";
            i = 0; //去重后的巡检点下标累加,表示第几个巡检点
            String codes[] = sb.toString().split(",");
            StringBuilder sbb = new StringBuilder();
            for (int a = 1; a <= codes.length; a++) {
    
    
                String code = codes[a - 1];
                if(StringUtils.isBlank(code)){
    
    
                    continue;
                }
                if (StringUtils.isNotBlank(code) && lastCode == "") {
    
    
                    lastCode = code;
                    sbb.append(code + ",");
                    i++;
                    repeatIndexRecord.add(i);
                } else {
    
    
                    //去重,上一个点不等于当前点,就去掉
                    if (StringUtils.isNotBlank(code) && !lastCode.contains(code)) {
    
    
                        if (a >= indexRecord.get(i)) {
    
    
                            i++;
                            //有相差
                            if (repeatTotalNum != 0) {
    
    
                                logger.info("d=={}", (indexRecord.get(i-1) - repeatTotalNum));
                                repeatIndexRecord.add(indexRecord.get(i - 1) - repeatTotalNum);
                            } else if (repeatTotalNum == 0 && repeatTotalNum == 0) {
    
    
                                logger.info("b=={}", i);
                                repeatIndexRecord.add(i);
                            }

                        }
                        lastCode = code;
                        sbb.append(code + ",");
                    } else {
    
    
                    	//中间节点重复个数累计
                        repeatTotalNum++;
                    }
                }

            }
            logger.info("jsonObjects={}", sb.toString());
            logger.info("jsonObjectss={}", sbb.toString());
            Map<String, String> indexMap = new HashMap<>();
            //设置巡检区域序号,用于前端显示巡检顺序
            logger.info("indexRecord={}", indexRecord.toString());
            logger.info("repeatIndexRecord={}", repeatIndexRecord.toString());
            int idx = 1;
            //一个节点多个序号处理
            for (Integer o : repeatIndexRecord) {
    
    
                if (!indexMap.containsKey(jsonObjects.get(o - 1).getId() + "")) {
    
    
                    indexMap.put(jsonObjects.get(o - 1).getId() + "", idx + "");
                    idx++;
                } else {
    
    
                    indexMap.put(jsonObjects.get(o - 1).getId() + "", indexMap.get(jsonObjects.get(o - 1).getId() + "") + "," + idx);
                    idx++;
                }
            }
            
           

おすすめ

転載: blog.csdn.net/qq_40351360/article/details/128155825
おすすめ